Update renovation.py
Browse files- renovation.py +28 -58
renovation.py
CHANGED
@@ -1,44 +1,37 @@
|
|
1 |
-
import csv
|
2 |
-
import random
|
3 |
-
import datasets
|
4 |
-
import requests
|
5 |
import os
|
6 |
-
import py7zr
|
7 |
-
import numpy as np
|
8 |
-
from pathlib import Path
|
9 |
|
10 |
-
|
11 |
-
from io import BytesIO
|
12 |
from datasets.tasks import ImageClassification
|
13 |
|
14 |
-
_HOMEPAGE = "https://
|
15 |
|
16 |
_CITATION = """\
|
17 |
-
@ONLINE {
|
18 |
author="Your Name",
|
19 |
-
title="Renovation
|
20 |
-
month="
|
21 |
-
year="
|
22 |
-
url="https://
|
23 |
}
|
24 |
"""
|
25 |
|
26 |
_DESCRIPTION = """\
|
27 |
-
|
|
|
|
|
28 |
"""
|
29 |
|
30 |
_URLS = {
|
31 |
-
"cheap": "https://huggingface.co/datasets/
|
32 |
-
"average": "https://huggingface.co/datasets/
|
33 |
-
"expensive": "https://huggingface.co/datasets/
|
34 |
}
|
35 |
|
36 |
_NAMES = ["cheap", "average", "expensive"]
|
37 |
|
38 |
-
class RenovationQualityDataset(datasets.GeneratorBasedBuilder):
|
39 |
-
"""Renovation Quality Dataset."""
|
40 |
|
41 |
-
|
|
|
42 |
|
43 |
def _info(self):
|
44 |
return datasets.DatasetInfo(
|
@@ -57,57 +50,34 @@ class RenovationQualityDataset(datasets.GeneratorBasedBuilder):
|
|
57 |
)
|
58 |
|
59 |
def _split_generators(self, dl_manager):
|
60 |
-
|
61 |
-
image_paths = []
|
62 |
-
for label, url in _URLS.items():
|
63 |
-
extract_path = dl_manager.download_and_extract(url)
|
64 |
-
print(f"Extracted files for label {label} to path: {extract_path}")
|
65 |
-
|
66 |
-
# Get image paths
|
67 |
-
for image_file_path in Path(extract_path).rglob("*"):
|
68 |
-
if image_file_path.suffix in [".jpg", ".jpeg", ".png"]: # add or remove image file types as needed
|
69 |
-
image_paths.append((str(image_file_path), label))
|
70 |
-
|
71 |
-
print(f"Collected a total of {len(image_paths)} image paths.")
|
72 |
-
|
73 |
-
|
74 |
-
# Shuffle image paths
|
75 |
-
random.shuffle(image_paths)
|
76 |
-
|
77 |
-
# 80% for training, 10% for validation, 10% for testing
|
78 |
-
train_end = int(0.8 * len(image_paths))
|
79 |
-
val_end = int(0.9 * len(image_paths))
|
80 |
-
|
81 |
return [
|
82 |
datasets.SplitGenerator(
|
83 |
name=datasets.Split.TRAIN,
|
84 |
gen_kwargs={
|
85 |
-
"
|
86 |
},
|
87 |
),
|
88 |
datasets.SplitGenerator(
|
89 |
name=datasets.Split.VALIDATION,
|
90 |
gen_kwargs={
|
91 |
-
"
|
92 |
},
|
93 |
),
|
94 |
datasets.SplitGenerator(
|
95 |
name=datasets.Split.TEST,
|
96 |
gen_kwargs={
|
97 |
-
"
|
98 |
},
|
99 |
),
|
100 |
]
|
101 |
|
102 |
-
def _generate_examples(self,
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
'image': image,
|
112 |
-
'labels': label,
|
113 |
-
}
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
|
|
|
|
|
|
2 |
|
3 |
+
import datasets
|
|
|
4 |
from datasets.tasks import ImageClassification
|
5 |
|
6 |
+
_HOMEPAGE = "https://github.com/your-github/renovation"
|
7 |
|
8 |
_CITATION = """\
|
9 |
+
@ONLINE {renovationdata,
|
10 |
author="Your Name",
|
11 |
+
title="Renovation dataset",
|
12 |
+
month="January",
|
13 |
+
year="2023",
|
14 |
+
url="https://github.com/your-github/renovation"
|
15 |
}
|
16 |
"""
|
17 |
|
18 |
_DESCRIPTION = """\
|
19 |
+
Renovations is a dataset of images of houses taken in the field using smartphone
|
20 |
+
cameras. It consists of 3 classes: cheap, average, and expensive renovations.
|
21 |
+
Data was collected by the your research lab.
|
22 |
"""
|
23 |
|
24 |
_URLS = {
|
25 |
+
"cheap": "https://huggingface.co/datasets/renovation/resolve/main/data/cheap.7z",
|
26 |
+
"average": "https://huggingface.co/datasets/renovation/resolve/main/data/average.7z",
|
27 |
+
"expensive": "https://huggingface.co/datasets/renovation/resolve/main/data/expensive.7z",
|
28 |
}
|
29 |
|
30 |
_NAMES = ["cheap", "average", "expensive"]
|
31 |
|
|
|
|
|
32 |
|
33 |
+
class Renovations(datasets.GeneratorBasedBuilder):
|
34 |
+
"""Renovations house images dataset."""
|
35 |
|
36 |
def _info(self):
|
37 |
return datasets.DatasetInfo(
|
|
|
50 |
)
|
51 |
|
52 |
def _split_generators(self, dl_manager):
|
53 |
+
data_files = dl_manager.download_and_extract(_URLS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
return [
|
55 |
datasets.SplitGenerator(
|
56 |
name=datasets.Split.TRAIN,
|
57 |
gen_kwargs={
|
58 |
+
"files": dl_manager.iter_files([data_files["cheap"]]),
|
59 |
},
|
60 |
),
|
61 |
datasets.SplitGenerator(
|
62 |
name=datasets.Split.VALIDATION,
|
63 |
gen_kwargs={
|
64 |
+
"files": dl_manager.iter_files([data_files["average"]]),
|
65 |
},
|
66 |
),
|
67 |
datasets.SplitGenerator(
|
68 |
name=datasets.Split.TEST,
|
69 |
gen_kwargs={
|
70 |
+
"files": dl_manager.iter_files([data_files["expensive"]]),
|
71 |
},
|
72 |
),
|
73 |
]
|
74 |
|
75 |
+
def _generate_examples(self, files):
|
76 |
+
for i, path in enumerate(files):
|
77 |
+
file_name = os.path.basename(path)
|
78 |
+
if file_name.endswith(".jpg"):
|
79 |
+
yield i, {
|
80 |
+
"image_file_path": path,
|
81 |
+
"image": path,
|
82 |
+
"labels": os.path.basename(os.path.dirname(path)).lower(),
|
83 |
+
}
|
|
|
|
|
|