renovation / renovation.py
rshrott's picture
Update renovation.py
ea0a244
raw
history blame
2.78 kB
import os
import csv
import datasets
from datasets.tasks import ImageClassification
_HOMEPAGE = "https://huggingface.co/datasets/rshrott/renovation"
_CITATION = """\
@ONLINE {renovationquality,
author="Your Name",
title="Renovation Quality Dataset",
month="Your Month",
year="Your Year",
url="https://huggingface.co/datasets/rshrott/renovation"
}
"""
_DESCRIPTION = """\
This dataset contains images of various properties, along with labels indicating the quality of renovation - 'cheap', 'average', 'expensive'.
"""
_URL = "https://huggingface.co/datasets/rshrott/renovation/blob/main/labels.csv"
_NAMES = ["cheap", "average", "expensive"]
class RenovationQualityDataset(datasets.GeneratorBasedBuilder):
"""Renovation Quality Dataset."""
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"image": datasets.Value("string"),
"label": datasets.features.ClassLabel(names=_NAMES),
}
),
supervised_keys=("image", "label"),
homepage=_HOMEPAGE,
citation=_CITATION,
task_templates=[ImageClassification(image_column="image", label_column="label")],
)
def _split_generators(self, dl_manager):
csv_path = dl_manager.download(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": csv_path,
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": csv_path,
"split": "validation",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": csv_path,
"split": "test",
},
),
]
def _generate_examples(self, filepath, split):
with open(filepath, "r") as f:
reader = csv.reader(f)
next(reader) # skip header
rows = list(reader)
if split == 'train':
rows = rows[:int(0.8 * len(rows))]
elif split == 'validation':
rows = rows[int(0.8 * len(rows)):int(0.9 * len(rows))]
else: # test
rows = rows[int(0.9 * len(rows)):]
for id_, row in enumerate(rows):
yield id_, {
'image': row[0],
'label': row[1],
}