File size: 2,887 Bytes
1343513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9983dd6
1343513
 
 
 
 
 
 
 
 
 
 
db8a932
1343513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abca71d
1343513
 
 
 
 
abca71d
1343513
 
 
 
 
abca71d
1343513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# coding=utf-8
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/SkinDisease/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.1")

    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,
                }