RossVermouth commited on
Commit
40912a7
·
1 Parent(s): 78d95ef

Create cs_test_dataset.py

Browse files
Files changed (1) hide show
  1. cs_test_dataset.py +86 -0
cs_test_dataset.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """chensu test animal classification dataset with images of cats and dogs"""
16
+
17
+ import os
18
+
19
+ import datasets
20
+ from datasets.tasks import ImageClassification
21
+
22
+ _HOMEPAGE = "https://oss.console.aliyun.com/bucket/oss-cn-beijing/340788/object"
23
+
24
+ _CITATION = """\
25
+ @ONLINE {
26
+ author="chensu"
27
+ }
28
+ """
29
+
30
+ _DESCRIPTION = """\
31
+ This is a test dataset used to demonstrate the process of creating a hugging face dataset
32
+ """
33
+
34
+ _URLS = {
35
+ "train": "https://340788.oss-cn-beijing.aliyuncs.com/train.zip",
36
+ "test": "https://340788.oss-cn-beijing.aliyuncs.com/test.zip",
37
+ }
38
+
39
+ _NAMES = ["cat", "dog"]
40
+
41
+
42
+ class CsTestDataset(datasets.GeneratorBasedBuilder):
43
+ """Test classification dataset."""
44
+
45
+ def _info(self):
46
+ return datasets.DatasetInfo(
47
+ description=_DESCRIPTION,
48
+ features=datasets.Features(
49
+ {
50
+ "image_file_path": datasets.Value("string"),
51
+ "image": datasets.Image(),
52
+ "labels": datasets.features.ClassLabel(names=_NAMES),
53
+ }
54
+ ),
55
+ supervised_keys=("image", "labels"),
56
+ homepage=_HOMEPAGE,
57
+ citation=_CITATION,
58
+ task_templates=[ImageClassification(image_column="image", label_column="labels")],
59
+ )
60
+
61
+ def _split_generators(self, dl_manager):
62
+ data_files = dl_manager.download_and_extract(_URLS)
63
+ return [
64
+ datasets.SplitGenerator(
65
+ name=datasets.Split.TRAIN,
66
+ gen_kwargs={
67
+ "files": dl_manager.iter_files([data_files["train"]]),
68
+ },
69
+ ),
70
+ datasets.SplitGenerator(
71
+ name=datasets.Split.TEST,
72
+ gen_kwargs={
73
+ "files": dl_manager.iter_files([data_files["test"]]),
74
+ },
75
+ ),
76
+ ]
77
+
78
+ def _generate_examples(self, files):
79
+ for i, path in enumerate(files):
80
+ file_name = os.path.basename(path)
81
+ if file_name.endswith(".jpeg"):
82
+ yield i, {
83
+ "image_file_path": path,
84
+ "image": path,
85
+ "labels": os.path.basename(os.path.dirname(path)).lower(),
86
+ }