rshrott commited on
Commit
6f69865
1 Parent(s): 25a06e0

Update renovation.py

Browse files
Files changed (1) hide show
  1. 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
- from PIL import Image
11
- from io import BytesIO
12
  from datasets.tasks import ImageClassification
13
 
14
- _HOMEPAGE = "https://huggingface.co/datasets/rshrott/renovation"
15
 
16
  _CITATION = """\
17
- @ONLINE {renovationquality,
18
  author="Your Name",
19
- title="Renovation Quality Dataset",
20
- month="Your Month",
21
- year="Your Year",
22
- url="https://huggingface.co/datasets/rshrott/renovation"
23
  }
24
  """
25
 
26
  _DESCRIPTION = """\
27
- This dataset contains images of various properties, along with labels indicating the quality of renovation - 'cheap', 'average', 'expensive'.
 
 
28
  """
29
 
30
  _URLS = {
31
- "cheap": "https://huggingface.co/datasets/rshrott/renovation/raw/main/cheap.7z",
32
- "average": "https://huggingface.co/datasets/rshrott/renovation/raw/main/average.7z",
33
- "expensive": "https://huggingface.co/datasets/rshrott/renovation/raw/main/expensive.7z",
34
  }
35
 
36
  _NAMES = ["cheap", "average", "expensive"]
37
 
38
- class RenovationQualityDataset(datasets.GeneratorBasedBuilder):
39
- """Renovation Quality Dataset."""
40
 
41
- VERSION = datasets.Version("1.0.0")
 
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
- # Download and extract images
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
- "rows": image_paths[:train_end],
86
  },
87
  ),
88
  datasets.SplitGenerator(
89
  name=datasets.Split.VALIDATION,
90
  gen_kwargs={
91
- "rows": image_paths[train_end:val_end],
92
  },
93
  ),
94
  datasets.SplitGenerator(
95
  name=datasets.Split.TEST,
96
  gen_kwargs={
97
- "rows": image_paths[val_end:],
98
  },
99
  ),
100
  ]
101
 
102
- def _generate_examples(self, rows):
103
- def file_to_image(file_path):
104
- img = Image.open(file_path)
105
- return np.array(img)
106
-
107
- for id_, (image_file_path, label) in enumerate(rows):
108
- image = file_to_image(image_file_path)
109
- yield id_, {
110
- 'image_file_path': image_file_path,
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
+ }