Update imagenette.py
Browse files- imagenette.py +11 -6
imagenette.py
CHANGED
@@ -49,6 +49,7 @@ Full size download;
|
|
49 |
"""
|
50 |
|
51 |
_URL_PREFIX = "https://s3.amazonaws.com/fast-ai-imageclas/"
|
|
|
52 |
|
53 |
_LABELS = {
|
54 |
"imagenette": [
|
@@ -100,9 +101,6 @@ class ImagenetteConfig(datasets.BuilderConfig):
|
|
100 |
self.labels = _LABELS[self.dataset]
|
101 |
self.name = name
|
102 |
|
103 |
-
with open("imagenet_refs.json", "r") as f:
|
104 |
-
self.imagenet_refs = json.load(f)
|
105 |
-
self.ref_to_labels = {}
|
106 |
|
107 |
|
108 |
def _make_builder_configs():
|
@@ -141,10 +139,17 @@ class Imagenette(datasets.GeneratorBasedBuilder):
|
|
141 |
"""Returns SplitGenerators."""
|
142 |
print(self.__dict__.keys())
|
143 |
print(self.config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
name = self.config.name
|
145 |
dirname = _NAME_TO_DIR[name]
|
146 |
url = _URL_PREFIX + "{}.tgz".format(dirname)
|
147 |
-
path = dl_manager.download_and_extract(url)
|
148 |
train_path = os.path.join(path, dirname, "train")
|
149 |
val_path = os.path.join(path, dirname, "val")
|
150 |
assert os.path.exists(train_path)
|
@@ -165,12 +170,12 @@ class Imagenette(datasets.GeneratorBasedBuilder):
|
|
165 |
|
166 |
def _generate_examples(self, datapath):
|
167 |
"""Yields examples."""
|
168 |
-
|
169 |
for path in Path(datapath).glob("**/*.JPEG"):
|
170 |
record = {
|
171 |
# In Imagenette, the parent folder of the file is
|
172 |
# the imagenet reference to the label name.
|
173 |
"image": str(path),
|
174 |
-
"labels":
|
175 |
}
|
176 |
yield path.name, record
|
|
|
49 |
"""
|
50 |
|
51 |
_URL_PREFIX = "https://s3.amazonaws.com/fast-ai-imageclas/"
|
52 |
+
_URL_IMAGENET_REFS = 'https://huggingface.co/datasets/jerpint/imagenette/raw/main/imagenet_refs.json'
|
53 |
|
54 |
_LABELS = {
|
55 |
"imagenette": [
|
|
|
101 |
self.labels = _LABELS[self.dataset]
|
102 |
self.name = name
|
103 |
|
|
|
|
|
|
|
104 |
|
105 |
|
106 |
def _make_builder_configs():
|
|
|
139 |
"""Returns SplitGenerators."""
|
140 |
print(self.__dict__.keys())
|
141 |
print(self.config)
|
142 |
+
|
143 |
+
# Download the ref:label map for imagenet
|
144 |
+
path = dl_manager.download_and_extract(url)
|
145 |
+
refs_path = dl_manager.download(_URL_IMAGENET_REFS)
|
146 |
+
with open(refs_path) as f:
|
147 |
+
self.ref_to_label = json.load(f)
|
148 |
+
|
149 |
+
|
150 |
name = self.config.name
|
151 |
dirname = _NAME_TO_DIR[name]
|
152 |
url = _URL_PREFIX + "{}.tgz".format(dirname)
|
|
|
153 |
train_path = os.path.join(path, dirname, "train")
|
154 |
val_path = os.path.join(path, dirname, "val")
|
155 |
assert os.path.exists(train_path)
|
|
|
170 |
|
171 |
def _generate_examples(self, datapath):
|
172 |
"""Yields examples."""
|
173 |
+
|
174 |
for path in Path(datapath).glob("**/*.JPEG"):
|
175 |
record = {
|
176 |
# In Imagenette, the parent folder of the file is
|
177 |
# the imagenet reference to the label name.
|
178 |
"image": str(path),
|
179 |
+
"labels": self.ref_to_label[path.parent.name],
|
180 |
}
|
181 |
yield path.name, record
|