import datasets from datasets.tasks import ImageClassification _CITATION = """\ @data{t5s2-4j73-22, doi = {10.21227/t5s2-4j73}, url = {https://dx.doi.org/10.21227/t5s2-4j73}, author = {Dimauro, Giovanni and Maglietta, Rosalia and Bai, Thulasi and Kasiviswanathan, Sivachandar}, publisher = {IEEE Dataport}, title = {Eyes-defy-anemia}, year = {2022} } """ _DESCRIPTION = """\ The dataset Eyes-defy-anemia contains 218 images of eyes, in particular conjunctivas, which can be used for research on the diagnosis/estimation of anemia based on the pallor of conjunctiva. """ _URLS = { "train": "https://huggingface.co/datasets/Yahaira/anemia-eyes/blob/main/data/train.zip", "validation": "https://huggingface.co/datasets/Yahaira/anemia-eyes/blob/main/data/validation.zip", "test": "https://huggingface.co/datasets/Yahaira/anemia-eyes/blob/main/data/test.zip", } _NAMES = ["NoAnemia, Anemia"] class Anemia(datasets.GeneratorBasedBuilder): """Beans plant leaf images dataset.""" def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "image_file_path": datasets.Value("string"), "image": datasets.Image(), "labels": datasets.features.ClassLabel(names=_NAMES), } ), supervised_keys=("image", "labels"), citation=_CITATION, task_templates=[ImageClassification(image_column="image", label_column="labels")], ) def _split_generators(self, dl_manager): data_files = dl_manager.download_and_extract(_URLS) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "files": dl_manager.iter_files([data_files["train"]]), }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "files": dl_manager.iter_files([data_files["validation"]]), }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "files": dl_manager.iter_files([data_files["test"]]), }, ), ] def _generate_examples(self, files): for i, path in enumerate(files): file_name = os.path.basename(path) if file_name.endswith(".jpg"): yield i, { "image_file_path": path, "image": path, "labels": os.path.basename(os.path.dirname(path)).lower(), }