from pathlib import Path import datasets _VERSION = "0.1.0" _CITATION = "" _DESCRIPTION = "" _HOMEPAGE = "" _LICENSE = "" _FEATURES = datasets.Features( { "image": datasets.Image(mode="RGB"), "label": datasets.ClassLabel( names=[ "Basophil", "Eosinophil", "Lymphocyte", "Monocyte", "Neutrophil", ] ), } ) Cropped = datasets.Split("cropped") Augmented = datasets.Split("augmented") Original = datasets.Split("original") class WartyPig(datasets.GeneratorBasedBuilder): DEFAULT_WRITER_BATCH_SIZE = 1000 def _info(self): return datasets.DatasetInfo( features=_FEATURES, supervised_keys=None, description=_DESCRIPTION, homepage=_HOMEPAGE, license=_LICENSE, version=_VERSION, citation=_CITATION, ) def _split_generators(self, dl_manager: datasets.DownloadManager): original_images = sorted(list(Path("Original").rglob("*.jpg"))) augmented_images = sorted(list(Path("Augmented images").rglob("*.jpg"))) cropped_images = sorted(list(Path("Cropped Classified").rglob("*.jpg"))) return [ datasets.SplitGenerator( name=Original, gen_kwargs={"images": original_images, "no_label": True}, ), datasets.SplitGenerator( name=Cropped, gen_kwargs={"images": cropped_images}, ), datasets.SplitGenerator( name=Augmented, gen_kwargs={"images": augmented_images}, ), ] def _generate_examples(self, images: list[Path], no_label=False): for i, image in enumerate(images): if no_label: yield ( i, { "image": str(image), }, ) else: yield ( i, { "image": str(image), "label": image.parent.name, }, )