|
import os |
|
import glob |
|
import random |
|
|
|
import datasets |
|
from datasets.tasks import ImageClassification |
|
|
|
_HOMEPAGE = "https://github.com/your-github/renovation" |
|
|
|
_CITATION = """\ |
|
@ONLINE {renovationdata, |
|
author="Your Name", |
|
title="Renovation dataset", |
|
month="January", |
|
year="2023", |
|
url="https://github.com/your-github/renovation" |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Renovations is a dataset of images of houses taken in the field using smartphone |
|
cameras. It consists of 3 classes: cheap, average, and expensive renovations. |
|
Data was collected by the your research lab. |
|
""" |
|
|
|
_URLS = { |
|
"cheap": "https://huggingface.co/datasets/rshrott/renovation/resolve/main/cheap.zip", |
|
"average": "https://huggingface.co/datasets/rshrott/renovation/resolve/main/average.zip", |
|
"expensive": "https://huggingface.co/datasets/rshrott/renovation/resolve/main/expensive.zip", |
|
} |
|
|
|
_NAMES = ["cheap", "average", "expensive"] |
|
|
|
class Renovations(datasets.GeneratorBasedBuilder): |
|
"""Renovations house images dataset.""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"image_file_path": datasets.Value("string"), |
|
"image": datasets.Image(), |
|
"labels": datasets.features.ClassLabel(names=_NAMES), |
|
} |
|
), |
|
supervised_keys=("image", "labels"), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
task_templates=[ImageClassification(image_column="image", label_column="labels")], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_files = dl_manager.download_and_extract(_URLS) |
|
files = glob.glob(data_files["cheap"] + '/*.jpeg', recursive=True) + \ |
|
glob.glob(data_files["average"] + '/*.jpeg', recursive=True) + \ |
|
glob.glob(data_files["expensive"] + '/*.jpeg', recursive=True) |
|
|
|
|
|
random.shuffle(files) |
|
num_files = len(files) |
|
train_files = files[:int(num_files*0.7)] |
|
val_files = files[int(num_files*0.7):int(num_files*0.85)] |
|
test_files = files[int(num_files*0.85):] |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"files": train_files, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"files": val_files, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"files": test_files, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, files): |
|
print(f"Processing {len(files)} files:") |
|
for i, path in enumerate(files): |
|
print(f"Processing file {i}: {path}") |
|
label = os.path.basename(os.path.dirname(path)).lower() |
|
print(f"Label: {label}") |
|
yield i, { |
|
"image_file_path": path, |
|
"image": path, |
|
"labels": label, |
|
} |
|
|