Update imagenette.py
Browse files- imagenette.py +17 -3
imagenette.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import datasets
|
| 2 |
from pathlib import Path
|
|
|
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
class Imagenette(datasets.GeneratorBasedBuilder):
|
|
@@ -40,12 +42,24 @@ class Imagenette(datasets.GeneratorBasedBuilder):
|
|
| 40 |
gen_kwargs={"files": test_path.rglob("*.JPEG")},
|
| 41 |
),
|
| 42 |
]
|
| 43 |
-
|
| 44 |
def _generate_examples(self, files):
|
|
|
|
|
|
|
|
|
|
| 45 |
for key, file in enumerate(files):
|
| 46 |
-
image = str(file)
|
| 47 |
label = file.parent.name
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
@staticmethod
|
| 51 |
def _class_names():
|
|
|
|
| 1 |
import datasets
|
| 2 |
from pathlib import Path
|
| 3 |
+
import io
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
|
| 7 |
class Imagenette(datasets.GeneratorBasedBuilder):
|
|
|
|
| 42 |
gen_kwargs={"files": test_path.rglob("*.JPEG")},
|
| 43 |
),
|
| 44 |
]
|
| 45 |
+
|
| 46 |
def _generate_examples(self, files):
|
| 47 |
+
import io
|
| 48 |
+
from PIL import Image
|
| 49 |
+
|
| 50 |
for key, file in enumerate(files):
|
|
|
|
| 51 |
label = file.parent.name
|
| 52 |
+
|
| 53 |
+
# Open and ensure RGB
|
| 54 |
+
with open(file, "rb") as f:
|
| 55 |
+
img = Image.open(io.BytesIO(f.read()))
|
| 56 |
+
if img.mode != "RGB":
|
| 57 |
+
img = img.convert("RGB")
|
| 58 |
+
|
| 59 |
+
yield key, {
|
| 60 |
+
"image": img,
|
| 61 |
+
"label": label
|
| 62 |
+
}
|
| 63 |
|
| 64 |
@staticmethod
|
| 65 |
def _class_names():
|