|
|
|
import os |
|
from dataclasses import dataclass |
|
|
|
import datasets |
|
from datasets.tasks import ImageClassification |
|
|
|
_HOMEPAGE = "TODO" |
|
|
|
_CITATION = """\ |
|
TODO |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
TODO |
|
""" |
|
|
|
_URL = "https://huggingface.co/datasets/HugsVision/Skin-Disease/resolve/main/skin-disease-datasaet.zip" |
|
|
|
@dataclass |
|
class CustomConfig(datasets.BuilderConfig): |
|
name: str = None |
|
version: datasets.Version = None |
|
description: str = None |
|
schema: str = None |
|
subset_id: str = None |
|
|
|
class SkinDisease(datasets.GeneratorBasedBuilder): |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
CustomConfig( |
|
name="default", |
|
version=VERSION, |
|
description="Skin Disease datasets.", |
|
schema="default", |
|
subset_id="default", |
|
), |
|
] |
|
|
|
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=["BA-cellulitis","BA-impetigo","FU-athlete-foot","FU-nail-fungus","FU-ringworm","PA-cutaneous-larva-migrans","VI-chickenpox","VI-shingles"]), |
|
} |
|
), |
|
supervised_keys=("image", "labels"), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
task_templates=[ImageClassification(image_column="image", label_column="labels")], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
data_dir = dl_manager.download_and_extract(_URL) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"data_dir": os.path.join(data_dir, "train_set"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"data_dir": os.path.join(data_dir, "validation_set"), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"data_dir": os.path.join(data_dir, "test_set"), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_dir): |
|
|
|
idx = 0 |
|
|
|
for class_name in os.listdir(data_dir): |
|
|
|
class_name_path = os.path.join(data_dir, class_name) |
|
|
|
for file_name in os.listdir(class_name_path): |
|
|
|
file_path = os.path.join(class_name_path, file_name) |
|
|
|
idx += 1 |
|
|
|
yield idx, { |
|
"image_file_path": file_path, |
|
"image": file_path, |
|
"labels": class_name, |
|
} |
|
|