|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""DTD loading script.""" |
|
|
|
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
|
@InProceedings{cimpoi14describing, |
|
|
Author = {M. Cimpoi and S. Maji and I. Kokkinos and S. Mohamed and and A. Vedaldi}, |
|
|
Title = {Describing Textures in the Wild}, |
|
|
Booktitle = {Proceedings of the {IEEE} Conf. on Computer Vision and Pattern Recognition ({CVPR})}, |
|
|
Year = {2014}} |
|
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
|
DTD is a texture database, consisting of 5640 images, organized according to a list of 47 terms (categories) inspired from human perception. There are 120 images for each category. Image sizes range between 300x300 and 640x640, and the images contain at least 90% of the surface representing the category attribute. The images were collected from Google and Flickr by entering our proposed attributes and related terms as search queries. The images were annotated using Amazon Mechanical Turk in several iterations. For each image we provide key attribute (main category) and a list of joint attributes. |
|
|
""" |
|
|
|
|
|
_HOMEPAGE = "https://www.robots.ox.ac.uk/%7Evgg/data/dtd/index.html" |
|
|
|
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
_URL = "https://www.robots.ox.ac.uk/~vgg/data/dtd/download/dtd-r1.0.1.tar.gz" |
|
|
|
|
|
_NAMES = [ |
|
|
"banded", |
|
|
"blotchy", |
|
|
"braided", |
|
|
"bubbly", |
|
|
"bumpy", |
|
|
"chequered", |
|
|
"cobwebbed", |
|
|
"cracked", |
|
|
"crosshatched", |
|
|
"crystalline", |
|
|
"dotted", |
|
|
"fibrous", |
|
|
"flecked", |
|
|
"freckled", |
|
|
"frilly", |
|
|
"gauzy", |
|
|
"grid", |
|
|
"grooved", |
|
|
"honeycombed", |
|
|
"interlaced", |
|
|
"knitted", |
|
|
"lacelike", |
|
|
"lined", |
|
|
"marbled", |
|
|
"matted", |
|
|
"meshed", |
|
|
"paisley", |
|
|
"perforated", |
|
|
"pitted", |
|
|
"pleated", |
|
|
"polka-dotted", |
|
|
"porous", |
|
|
"potholed", |
|
|
"scaly", |
|
|
"smeared", |
|
|
"spiralled", |
|
|
"sprinkled", |
|
|
"stained", |
|
|
"stratified", |
|
|
"striped", |
|
|
"studded", |
|
|
"swirly", |
|
|
"veined", |
|
|
"waffled", |
|
|
"woven", |
|
|
"wrinkled", |
|
|
"zigzagged", |
|
|
] |
|
|
|
|
|
|
|
|
class DTDDataset(datasets.GeneratorBasedBuilder): |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
datasets.BuilderConfig( |
|
|
name=f"partition_{idx}", |
|
|
version=datasets.Version("1.0.0"), |
|
|
description=f"DTD defines 10-fold CV partitions. This part of the dataset covers the {idx} fold.", |
|
|
) |
|
|
for idx in range(1, 11) |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
features = datasets.Features( |
|
|
{ |
|
|
"image": datasets.Image(), |
|
|
"label": datasets.features.ClassLabel(names=_NAMES), |
|
|
} |
|
|
) |
|
|
|
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=features, |
|
|
homepage=_HOMEPAGE, |
|
|
license=_LICENSE, |
|
|
citation=_CITATION, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
data_dir = dl_manager.download_and_extract(_URL) |
|
|
partition_id = self.config.name.split("_")[1] |
|
|
images_dir = Path(data_dir) / "dtd" / "images" |
|
|
labels_dir = Path(data_dir) / "dtd" / "labels" |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={ |
|
|
"images_dir": images_dir, |
|
|
"labels_dir": labels_dir, |
|
|
"partition_id": partition_id, |
|
|
"split": "train", |
|
|
}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.VALIDATION, |
|
|
gen_kwargs={ |
|
|
"images_dir": images_dir, |
|
|
"labels_dir": labels_dir, |
|
|
"partition_id": partition_id, |
|
|
"split": "val", |
|
|
}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TEST, |
|
|
gen_kwargs={ |
|
|
"images_dir": images_dir, |
|
|
"labels_dir": labels_dir, |
|
|
"partition_id": partition_id, |
|
|
"split": "test", |
|
|
}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples(self, images_dir, labels_dir, partition_id, split): |
|
|
with open( |
|
|
labels_dir / f"{split}{partition_id}.txt", "r", encoding="utf-8" |
|
|
) as split_file: |
|
|
for line in split_file: |
|
|
fname = line.strip() |
|
|
label = fname.split("/")[0] |
|
|
record = { |
|
|
"image": str(images_dir / fname), |
|
|
"label": label, |
|
|
} |
|
|
yield fname, record |