import datasets from datasets import ImageClassification _DESCRIPTION = """ A small rocket images dataset. """ _HOMEPAGE = "https://huggingface.co./datasets/MilkCool/rockets" _CITATION = "" _LICENSE = "MIT" _IMAGES_DIR = "train" _NAMES = "Rockets" #TODO class Rockets(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "image": datasets.Image(), "label": datasets.ClassLabel(names=_NAMES), } ), supervised_keys=("image", "label"), homepage=_HOMEPAGE, citation=_CITATION, license=_LICENSE, task_templates=[ImageClassification(image_column="image", label_column="label")], ) def _split_generators(self, dl_manager): #TODO return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir, "train.jsonl"), "split": "train", }, ) ] def _generate_examples(self, images, metadata_path): with open(metadata_path, encoding="utf-8") as f: files_to_keep = set(f.read().split("\n")) for file_path, file_obj in images: if file_path.startswith(_IMAGES_DIR): if file_path[len(_IMAGES_DIR) : -len(".jpg")] in files_to_keep: label = file_path.split("/")[2] yield file_path, { "image": {"path": file_path, "bytes": file_obj.read()}, "label": label, }