File size: 2,754 Bytes
d61a5ba 6f69865 fc74c6f 6f69865 fc74c6f 6f69865 1af3915 6f69865 fc74c6f 6f69865 fc74c6f 498fbdd 28ae5ed 498fbdd fc74c6f 1af3915 fc74c6f 6f69865 ea0a244 fc74c6f 3f0c3b8 d61a5ba 4058cac fc74c6f 4058cac fc74c6f 4058cac fc74c6f eb03b30 6f69865 eb03b30 6f69865 eb03b30 6f69865 eb03b30 6f69865 eb03b30 6f69865 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import os
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.7z",
"average": "https://huggingface.co/datasets/rshrott/renovation/resolve/main/average.7z",
"expensive": "https://huggingface.co/datasets/rshrott/renovation/resolve/main/expensive.7z",
}
_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)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"files": dl_manager.iter_files([data_files["cheap"]]),
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"files": dl_manager.iter_files([data_files["average"]]),
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"files": dl_manager.iter_files([data_files["expensive"]]),
},
),
]
def _generate_examples(self, files):
for i, path in enumerate(files):
file_name = os.path.basename(path)
if file_name.endswith(".jpg"):
yield i, {
"image_file_path": path,
"image": path,
"labels": os.path.basename(os.path.dirname(path)).lower(),
}
|