Datasets:
VinayHajare
commited on
Commit
·
d148b96
1
Parent(s):
5ab1cc0
Update fruits30.py
Browse files- fruits30.py +32 -2
fruits30.py
CHANGED
@@ -1,6 +1,36 @@
|
|
1 |
import os
|
2 |
-
|
3 |
import datasets
|
4 |
from datasets.tasks import ImageClassification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
from .clasess import FRUITS30
|
|
|
1 |
import os
|
|
|
2 |
import datasets
|
3 |
from datasets.tasks import ImageClassification
|
4 |
+
from .classes import FRUITS30_CLASSES
|
5 |
+
|
6 |
+
class fruits30(datasets.GeneratorBasedBuilder):
|
7 |
+
|
8 |
+
def _info(self):
|
9 |
+
assert len(FRUITS30_CLASSES) == 30
|
10 |
+
return datasets.DatasetInfo(
|
11 |
+
description = " The fruits-30 is a image dataset for fruit image classification task." +
|
12 |
+
" It contains high-quality images of 30 types of fruit with annotation using segmentation.",
|
13 |
+
features = datasets.Features(
|
14 |
+
{
|
15 |
+
"image": datasets.Image(),
|
16 |
+
"label": datasets.ClassLabel(names = list(FRUITS30_CLASSES.values())),
|
17 |
+
}
|
18 |
+
),
|
19 |
+
homepage = "https://github.com/VinayHajare/Fruit-Image-Dataset",
|
20 |
+
task_templates = [ImageClassification(image_column = "image", label_column = "label")],
|
21 |
+
)
|
22 |
+
|
23 |
+
def _generate_examples(self, archives, split):
|
24 |
+
"""Yields examples."""
|
25 |
+
idx = 0
|
26 |
+
for archive in archives:
|
27 |
+
for path, file in archive:
|
28 |
+
if path.endswith(".JPG"):
|
29 |
+
# image filepath format: <IMAGE_FILENAME>_<SYNSET_ID>.JPEG
|
30 |
+
root, _ = os.path.splitext(path)
|
31 |
+
_, synset_id = os.path.basename(root).rsplit("_", 1)
|
32 |
+
label = FRUITS30_CLASSES[synset_id]
|
33 |
+
ex = {"image": {"path": path, "bytes": file.read()}, "label": label}
|
34 |
+
yield idx, ex
|
35 |
+
idx += 1
|
36 |
|
|