Update imagefolder.py
Browse files- imagefolder.py +10 -0
imagefolder.py
CHANGED
@@ -5,6 +5,7 @@ from typing import Optional
|
|
5 |
import pyarrow as pa
|
6 |
|
7 |
import datasets
|
|
|
8 |
|
9 |
|
10 |
logger = datasets.utils.logging.get_logger(__name__)
|
@@ -26,10 +27,19 @@ class ImageFolder(datasets.GeneratorBasedBuilder):
|
|
26 |
BUILDER_CONFIG_CLASS = ImageFolderConfig
|
27 |
|
28 |
def _info(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
return datasets.DatasetInfo(
|
30 |
features=datasets.Features(
|
31 |
{"image_file_path": datasets.Value("string"), "labels": datasets.Value("string")}
|
32 |
),
|
|
|
33 |
)
|
34 |
|
35 |
def _split_generators(self, dl_manager):
|
|
|
5 |
import pyarrow as pa
|
6 |
|
7 |
import datasets
|
8 |
+
from datasets.tasks import ImageClassification
|
9 |
|
10 |
|
11 |
logger = datasets.utils.logging.get_logger(__name__)
|
|
|
27 |
BUILDER_CONFIG_CLASS = ImageFolderConfig
|
28 |
|
29 |
def _info(self):
|
30 |
+
folder=None
|
31 |
+
if isinstance(self.config.data_files, str):
|
32 |
+
folder = self.config.data_files
|
33 |
+
elif isinstance(self.config.data_files, dict):
|
34 |
+
folder = self.config.data_files.get('train', None)
|
35 |
+
if folder is None:
|
36 |
+
raise RuntimeError()
|
37 |
+
classes = sorted([x.name.lower() for x in Path(folder).glob('*/**')])
|
38 |
return datasets.DatasetInfo(
|
39 |
features=datasets.Features(
|
40 |
{"image_file_path": datasets.Value("string"), "labels": datasets.Value("string")}
|
41 |
),
|
42 |
+
task_templates=[datasets.tasks.ImageClassification(image_file_path_column="image_file_path", label_column="labels", labels=classes)]
|
43 |
)
|
44 |
|
45 |
def _split_generators(self, dl_manager):
|