rshrott commited on
Commit
065072f
1 Parent(s): 954b20f

Create renovation.py

Browse files
Files changed (1) hide show
  1. renovation.py +109 -0
renovation.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import random
4
+
5
+ import datasets
6
+ from datasets.tasks import ImageClassification
7
+
8
+ _HOMEPAGE = "https://github.com/your-github/renovation"
9
+
10
+ _CITATION = """\
11
+ @ONLINE {renovationdata,
12
+ author="Your Name",
13
+ title="Renovation dataset",
14
+ month="January",
15
+ year="2023",
16
+ url="https://github.com/your-github/renovation"
17
+ }
18
+ """
19
+
20
+ _DESCRIPTION = """\
21
+ Renovations is a dataset of images of houses taken in the field using smartphone
22
+ cameras. It consists of 3 classes: cheap, average, and expensive renovations.
23
+ Data was collected by the your research lab.
24
+ """
25
+
26
+ _URLS = {
27
+ 'Not Applicable': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Not Applicable.zip",
28
+ 'Very Poor': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Very Poor.zip",
29
+ 'Poor': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Poor.zip",
30
+ 'Fair': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Fair.zip",
31
+ 'Good': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Good.zip",
32
+ 'Excellent': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Excellent.zip",
33
+ 'Exceptional': "https://huggingface.co/datasets/rshrott/photos/resolve/main/Exceptional.zip"
34
+ }
35
+
36
+
37
+ _NAMES = ['Not Applicable', 'Very Poor', 'Poor', 'Fair', 'Good', 'Excellent', 'Exceptional']
38
+
39
+ class Renovations(datasets.GeneratorBasedBuilder):
40
+ """Renovations house images dataset."""
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=_NAMES),
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
+ data_files = dl_manager.download_and_extract(_URLS)
60
+ return [
61
+ datasets.SplitGenerator(
62
+ name=datasets.Split.TRAIN,
63
+ gen_kwargs={
64
+ "data_files": data_files,
65
+ "split": "train",
66
+ },
67
+ ),
68
+ datasets.SplitGenerator(
69
+ name=datasets.Split.VALIDATION,
70
+ gen_kwargs={
71
+ "data_files": data_files,
72
+ "split": "val",
73
+ },
74
+ ),
75
+ datasets.SplitGenerator(
76
+ name=datasets.Split.TEST,
77
+ gen_kwargs={
78
+ "data_files": data_files,
79
+ "split": "test",
80
+ },
81
+ ),
82
+ ]
83
+ def _generate_examples(self, data_files, split):
84
+ all_files_and_labels = []
85
+ for label, path in data_files.items():
86
+ files = glob.glob(path + '/*.jpeg', recursive=True)
87
+ all_files_and_labels.extend((file, label) for file in files)
88
+
89
+ random.seed(43) # ensure reproducibility
90
+ random.shuffle(all_files_and_labels)
91
+
92
+ num_files = len(all_files_and_labels)
93
+ train_data = all_files_and_labels[:int(num_files*0.9)]
94
+ val_test_data = all_files_and_labels[int(num_files*0.9):] # This will be used for both val and test
95
+
96
+ if split == "train":
97
+ data_to_use = train_data
98
+ else: # "val" or "test" split
99
+ data_to_use = val_test_data
100
+
101
+ for idx, (file, label) in enumerate(data_to_use):
102
+ yield idx, {
103
+ "image_file_path": file,
104
+ "image": file,
105
+ "labels": label,
106
+ }
107
+
108
+
109
+