MithatGuner commited on
Commit
f687740
·
verified ·
1 Parent(s): 660ab64

Create resistor.py

Browse files
Files changed (1) hide show
  1. resistor.py +101 -0
resistor.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import datasets
4
+ from datasets.tasks import ImageClassification
5
+
6
+
7
+ _HOMEPAGE = "https://huggingface.co/datasets/MithatGuner/resistor/"
8
+ _LICENSE = "Public Domain"
9
+ _CITATION = """\
10
+ """
11
+ _CATEGORIES = ['converse', 'adidas', 'nike']
12
+
13
+
14
+ class RESISTORConfig(datasets.BuilderConfig):
15
+ """Builder Config for resistor"""
16
+
17
+ def __init__(self, data_urls, **kwargs):
18
+ """
19
+ BuilderConfig for resistor.
20
+ Args:
21
+ data_urls: `dict`, name to url to download the zip file from.
22
+ **kwargs: keyword arguments forwarded to super.
23
+ """
24
+ super(RESISTORConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
25
+ self.data_urls = data_urls
26
+
27
+
28
+ class SHOECLASSIFICATION(datasets.GeneratorBasedBuilder):
29
+ """resistor image classification dataset"""
30
+
31
+ VERSION = datasets.Version("1.0.0")
32
+ BUILDER_CONFIGS = [
33
+ RESISTORConfig(
34
+ name="full",
35
+ description="Full version of resistor dataset.",
36
+ data_urls={
37
+ "train": "https://huggingface.co/datasets/MithatGuner/resistor/resolve/main/data/train.zip",
38
+ "validation": "https://huggingface.co/datasets/MithatGuner/resistor/resolve/main/data/valid.zip",
39
+ "test": "https://huggingface.co/datasets/MithatGuner/resistor/resolve/main/data/test.zip",
40
+ }
41
+ ,
42
+ ),
43
+ RESISTORConfig(
44
+ name="mini",
45
+ description="Mini version of resistor dataset.",
46
+ data_urls={
47
+ "train": "https://huggingface.co/datasets/MithatGuner/resistor/resolve/main/data/valid-mini.zip",
48
+ "validation": "https://huggingface.co/datasets/MithatGuner/resistor/resolve/main/data/valid-mini.zip",
49
+ "test": "https://huggingface.co/datasets/MithatGuner/resistor/resolve/main/data/valid-mini.zip",
50
+ },
51
+ )
52
+ ]
53
+
54
+ def _info(self):
55
+ return datasets.DatasetInfo(
56
+ features=datasets.Features(
57
+ {
58
+ "image_file_path": datasets.Value("string"),
59
+ "image": datasets.Image(),
60
+ "labels": datasets.features.ClassLabel(names=_CATEGORIES),
61
+ }
62
+ ),
63
+ supervised_keys=("image", "labels"),
64
+ homepage=_HOMEPAGE,
65
+ citation=_CITATION,
66
+ license=_LICENSE,
67
+ task_templates=[ImageClassification(image_column="image", label_column="labels")],
68
+ )
69
+
70
+ def _split_generators(self, dl_manager):
71
+ data_files = dl_manager.download_and_extract(self.config.data_urls)
72
+ return [
73
+ datasets.SplitGenerator(
74
+ name=datasets.Split.TRAIN,
75
+ gen_kwargs={
76
+ "files": dl_manager.iter_files([data_files["train"]]),
77
+ },
78
+ ),
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.VALIDATION,
81
+ gen_kwargs={
82
+ "files": dl_manager.iter_files([data_files["validation"]]),
83
+ },
84
+ ),
85
+ datasets.SplitGenerator(
86
+ name=datasets.Split.TEST,
87
+ gen_kwargs={
88
+ "files": dl_manager.iter_files([data_files["test"]]),
89
+ },
90
+ ),
91
+ ]
92
+
93
+ def _generate_examples(self, files):
94
+ for i, path in enumerate(files):
95
+ file_name = os.path.basename(path)
96
+ if file_name.endswith((".jpg", ".png", ".jpeg", ".bmp", ".tif", ".tiff")):
97
+ yield i, {
98
+ "image_file_path": path,
99
+ "image": path,
100
+ "labels": os.path.basename(os.path.dirname(path)),
101
+ }