Create SkinDisease.py
Browse files- SkinDisease.py +101 -0
SkinDisease.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
import os
|
3 |
+
from dataclasses import dataclass
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
from datasets.tasks import ImageClassification
|
7 |
+
|
8 |
+
_HOMEPAGE = "TODO"
|
9 |
+
|
10 |
+
_CITATION = """\
|
11 |
+
TODO
|
12 |
+
"""
|
13 |
+
|
14 |
+
_DESCRIPTION = """\
|
15 |
+
TODO
|
16 |
+
"""
|
17 |
+
|
18 |
+
_URL = "https://huggingface.co/datasets/HugsVision/Skin-Disease/resolve/main/skin-disease-datasaet.zip"
|
19 |
+
|
20 |
+
@dataclass
|
21 |
+
class CustomConfig(datasets.BuilderConfig):
|
22 |
+
name: str = None
|
23 |
+
version: datasets.Version = None
|
24 |
+
description: str = None
|
25 |
+
schema: str = None
|
26 |
+
subset_id: str = None
|
27 |
+
|
28 |
+
class SkinDisease(datasets.GeneratorBasedBuilder):
|
29 |
+
|
30 |
+
VERSION = datasets.Version("1.0.0")
|
31 |
+
|
32 |
+
BUILDER_CONFIGS = [
|
33 |
+
CustomConfig(
|
34 |
+
name="default",
|
35 |
+
version=VERSION,
|
36 |
+
description="Skin Disease datasets.",
|
37 |
+
schema="default",
|
38 |
+
subset_id="default",
|
39 |
+
),
|
40 |
+
]
|
41 |
+
|
42 |
+
def _info(self):
|
43 |
+
return datasets.DatasetInfo(
|
44 |
+
description=_DESCRIPTION,
|
45 |
+
features=datasets.Features(
|
46 |
+
{
|
47 |
+
"image_file_path": datasets.Value("string"),
|
48 |
+
"image": datasets.Image(),
|
49 |
+
"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"]),
|
50 |
+
}
|
51 |
+
),
|
52 |
+
supervised_keys=("image", "labels"),
|
53 |
+
homepage=_HOMEPAGE,
|
54 |
+
citation=_CITATION,
|
55 |
+
task_templates=[ImageClassification(image_column="image", label_column="labels")],
|
56 |
+
)
|
57 |
+
|
58 |
+
def _split_generators(self, dl_manager):
|
59 |
+
|
60 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
61 |
+
|
62 |
+
return [
|
63 |
+
datasets.SplitGenerator(
|
64 |
+
name=datasets.Split.TRAIN,
|
65 |
+
gen_kwargs={
|
66 |
+
"data_dir": os.path.join(data_dir, "train"),
|
67 |
+
},
|
68 |
+
),
|
69 |
+
datasets.SplitGenerator(
|
70 |
+
name=datasets.Split.VALIDATION,
|
71 |
+
gen_kwargs={
|
72 |
+
"data_dir": os.path.join(data_dir, "validation"),
|
73 |
+
},
|
74 |
+
),
|
75 |
+
datasets.SplitGenerator(
|
76 |
+
name=datasets.Split.TEST,
|
77 |
+
gen_kwargs={
|
78 |
+
"data_dir": os.path.join(data_dir, "test"),
|
79 |
+
},
|
80 |
+
),
|
81 |
+
]
|
82 |
+
|
83 |
+
def _generate_examples(self, data_dir):
|
84 |
+
|
85 |
+
idx = 0
|
86 |
+
|
87 |
+
for class_name in os.listdir(data_dir):
|
88 |
+
|
89 |
+
class_name_path = os.path.join(data_dir, class_name)
|
90 |
+
|
91 |
+
for file_name in os.listdir(class_name_path):
|
92 |
+
|
93 |
+
file_path = os.path.join(class_name_path, file_name)
|
94 |
+
|
95 |
+
idx += 1
|
96 |
+
|
97 |
+
yield idx, {
|
98 |
+
"image_file_path": file_path,
|
99 |
+
"image": file_path,
|
100 |
+
"labels": class_name,
|
101 |
+
}
|