Datasets:
Tasks:
Image Classification
Size:
1K - 10K
| import os | |
| import datasets | |
| from datasets.tasks import ImageClassification | |
| _HOMEPAGE = "https://universe.roboflow.com/art-dataset/wiki-art/dataset/1" | |
| _LICENSE = "CC BY 4.0" | |
| _CITATION = """\ | |
| @misc{ wiki-art_dataset, | |
| title = { wiki art Dataset }, | |
| type = { Open Source Dataset }, | |
| author = { Art Dataset }, | |
| howpublished = { \\url{ https://universe.roboflow.com/art-dataset/wiki-art } }, | |
| url = { https://universe.roboflow.com/art-dataset/wiki-art }, | |
| journal = { Roboflow Universe }, | |
| publisher = { Roboflow }, | |
| year = { 2022 }, | |
| month = { mar }, | |
| note = { visited on 2023-01-18 }, | |
| } | |
| """ | |
| _CATEGORIES = ['Realism', 'Art_Nouveau_Modern', 'Analytical_Cubism', 'Cubism', 'Expressionism', 'Action_painting', 'Synthetic_Cubism', 'Symbolism', 'Ukiyo_e', 'Naive_Art_Primitivism', 'Post_Impressionism', 'Impressionism', 'Fauvism', 'Rococo', 'Minimalism', 'Mannerism_Late_Renaissance', 'Color_Field_Painting', 'High_Renaissance', 'Romanticism', 'Pop_Art', 'Contemporary_Realism', 'Baroque', 'New_Realism', 'Pointillism', 'Northern_Renaissance', 'Early_Renaissance', 'Abstract_Expressionism'] | |
| class PAINTINGSTYLECLASSIFICATIONConfig(datasets.BuilderConfig): | |
| """Builder Config for painting-style-classification""" | |
| def __init__(self, data_urls, **kwargs): | |
| """ | |
| BuilderConfig for painting-style-classification. | |
| Args: | |
| data_urls: `dict`, name to url to download the zip file from. | |
| **kwargs: keyword arguments forwarded to super. | |
| """ | |
| super(PAINTINGSTYLECLASSIFICATIONConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs) | |
| self.data_urls = data_urls | |
| class PAINTINGSTYLECLASSIFICATION(datasets.GeneratorBasedBuilder): | |
| """painting-style-classification image classification dataset""" | |
| VERSION = datasets.Version("1.0.0") | |
| BUILDER_CONFIGS = [ | |
| PAINTINGSTYLECLASSIFICATIONConfig( | |
| name="full", | |
| description="Full version of painting-style-classification dataset.", | |
| data_urls={ | |
| "train": "https://huggingface.co/datasets/keremberke/painting-style-classification/resolve/main/data/train.zip", | |
| "validation": "https://huggingface.co/datasets/keremberke/painting-style-classification/resolve/main/data/valid.zip", | |
| "test": "https://huggingface.co/datasets/keremberke/painting-style-classification/resolve/main/data/test.zip", | |
| } | |
| , | |
| ), | |
| PAINTINGSTYLECLASSIFICATIONConfig( | |
| name="mini", | |
| description="Mini version of painting-style-classification dataset.", | |
| data_urls={ | |
| "train": "https://huggingface.co/datasets/keremberke/painting-style-classification/resolve/main/data/valid-mini.zip", | |
| "validation": "https://huggingface.co/datasets/keremberke/painting-style-classification/resolve/main/data/valid-mini.zip", | |
| "test": "https://huggingface.co/datasets/keremberke/painting-style-classification/resolve/main/data/valid-mini.zip", | |
| }, | |
| ) | |
| ] | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| features=datasets.Features( | |
| { | |
| "image_file_path": datasets.Value("string"), | |
| "image": datasets.Image(), | |
| "labels": datasets.features.ClassLabel(names=_CATEGORIES), | |
| } | |
| ), | |
| supervised_keys=("image", "labels"), | |
| homepage=_HOMEPAGE, | |
| citation=_CITATION, | |
| license=_LICENSE, | |
| task_templates=[ImageClassification(image_column="image", label_column="labels")], | |
| ) | |
| def _split_generators(self, dl_manager): | |
| data_files = dl_manager.download_and_extract(self.config.data_urls) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={ | |
| "files": dl_manager.iter_files([data_files["train"]]), | |
| }, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.VALIDATION, | |
| gen_kwargs={ | |
| "files": dl_manager.iter_files([data_files["validation"]]), | |
| }, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TEST, | |
| gen_kwargs={ | |
| "files": dl_manager.iter_files([data_files["test"]]), | |
| }, | |
| ), | |
| ] | |
| def _generate_examples(self, files): | |
| for i, path in enumerate(files): | |
| file_name = os.path.basename(path) | |
| if file_name.endswith((".jpg", ".png", ".jpeg", ".bmp", ".tif", ".tiff")): | |
| yield i, { | |
| "image_file_path": path, | |
| "image": path, | |
| "labels": os.path.basename(os.path.dirname(path)), | |
| } | |