|
import datasets |
|
from datasets.data_files import DataFilesDict |
|
from datasets.packaged_modules.imagefolder.imagefolder import ImageFolder, ImageFolderConfig |
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
class GTSRB(ImageFolder): |
|
R""" |
|
DTD dataset for image classification. |
|
""" |
|
|
|
BUILDER_CONFIG_CLASS = ImageFolderConfig |
|
BUILDER_CONFIGS = [ |
|
ImageFolderConfig( |
|
name="default", |
|
features=("images", "labels"), |
|
data_files=DataFilesDict({split: f"data/{split}.zip" for split in ["train", "test"]}), |
|
) |
|
] |
|
|
|
classnames = [ |
|
"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", |
|
] |
|
|
|
clip_templates = [ |
|
lambda c: f"a photo of a {c} texture.", |
|
lambda c: f"a photo of a {c} pattern.", |
|
lambda c: f"a photo of a {c} thing.", |
|
lambda c: f"a photo of a {c} object.", |
|
lambda c: f"a photo of the {c} texture.", |
|
lambda c: f"a photo of the {c} pattern.", |
|
lambda c: f"a photo of the {c} thing.", |
|
lambda c: f"a photo of the {c} object.", |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description="DTD dataset for image classification.", |
|
features=datasets.Features( |
|
{ |
|
"image": datasets.Image(), |
|
"label": datasets.ClassLabel(names=self.classnames), |
|
} |
|
), |
|
supervised_keys=("image", "label"), |
|
task_templates=[datasets.ImageClassification(image_column="image", label_column="label")], |
|
) |
|
|