1aurent commited on
Commit
29fe721
1 Parent(s): 2faf5f2

Create gen_script.py

Browse files
Files changed (1) hide show
  1. gen_script.py +85 -0
gen_script.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import datasets
4
+
5
+ _VERSION = "0.1.0"
6
+
7
+ _CITATION = ""
8
+
9
+ _DESCRIPTION = ""
10
+
11
+ _HOMEPAGE = ""
12
+
13
+ _LICENSE = ""
14
+
15
+ _FEATURES = datasets.Features(
16
+ {
17
+ "image": datasets.Image(mode="RGB"),
18
+ "label": datasets.ClassLabel(
19
+ names=[
20
+ "Basophil",
21
+ "Eosinophil",
22
+ "Lymphocyte",
23
+ "Monocyte",
24
+ "Neutrophil",
25
+ ]
26
+ ),
27
+ }
28
+ )
29
+
30
+ Cropped = datasets.Split("cropped")
31
+ Augmented = datasets.Split("augmented")
32
+ Original = datasets.Split("original")
33
+
34
+
35
+ class WartyPig(datasets.GeneratorBasedBuilder):
36
+ DEFAULT_WRITER_BATCH_SIZE = 1000
37
+
38
+ def _info(self):
39
+ return datasets.DatasetInfo(
40
+ features=_FEATURES,
41
+ supervised_keys=None,
42
+ description=_DESCRIPTION,
43
+ homepage=_HOMEPAGE,
44
+ license=_LICENSE,
45
+ version=_VERSION,
46
+ citation=_CITATION,
47
+ )
48
+
49
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
50
+ original_images = sorted(list(Path("Original").rglob("*.jpg")))
51
+ augmented_images = sorted(list(Path("Augmented images").rglob("*.jpg")))
52
+ cropped_images = sorted(list(Path("Cropped Classified").rglob("*.jpg")))
53
+
54
+ return [
55
+ datasets.SplitGenerator(
56
+ name=Original,
57
+ gen_kwargs={"images": original_images, "no_label": True},
58
+ ),
59
+ datasets.SplitGenerator(
60
+ name=Cropped,
61
+ gen_kwargs={"images": cropped_images},
62
+ ),
63
+ datasets.SplitGenerator(
64
+ name=Augmented,
65
+ gen_kwargs={"images": augmented_images},
66
+ ),
67
+ ]
68
+
69
+ def _generate_examples(self, images: list[Path], no_label=False):
70
+ for i, image in enumerate(images):
71
+ if no_label:
72
+ yield (
73
+ i,
74
+ {
75
+ "image": str(image),
76
+ },
77
+ )
78
+ else:
79
+ yield (
80
+ i,
81
+ {
82
+ "image": str(image),
83
+ "label": image.parent.name,
84
+ },
85
+ )