Datasets:
Tasks:
Image Classification
Modalities:
Image
Formats:
imagefolder
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
1K - 10K
License:
| import os | |
| from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split, Features, ClassLabel, Image | |
| class SparkPlugAnomaly(GeneratorBasedBuilder): | |
| def _info(self): | |
| return DatasetInfo( | |
| description="Spark Plug Visual Anomaly Detection Dataset for Edge Impulse FOMO-AD", | |
| features=Features({ | |
| "image": Image(), | |
| "label": ClassLabel(names=["normal", "anomaly"]) | |
| }), | |
| supervised_keys=("image", "label"), | |
| ) | |
| def _split_generators(self, dl_manager): | |
| data_dir = os.path.join(dl_manager.manual_dir, "data") | |
| return [ | |
| SplitGenerator(name=Split.TRAIN, gen_kwargs={"data_dir": data_dir}), | |
| ] | |
| def _generate_examples(self, data_dir): | |
| idx = 0 | |
| for label in sorted(os.listdir(data_dir)): | |
| label_path = os.path.join(data_dir, label) | |
| if not os.path.isdir(label_path): | |
| continue | |
| for fname in os.listdir(label_path): | |
| if fname.lower().endswith((".jpg", ".jpeg", ".png")): | |
| yield idx, { | |
| "image": os.path.join(label_path, fname), | |
| "label": label | |
| } | |
| idx += 1 | |