|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
import pandas as pd |
|
import os |
|
import datasets |
|
from PIL import Image |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@misc{www.metmuseum.github.io, title={Metropolitan Museum of Art Open Access Collection}, url={https://metmuseum.github.io/}, journal={https://metmuseum.github.io/}} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
Dataset containing 243585 pieces of visual art from various artists, |
|
taken from the Metropolitan Museum of Art's Open Access Collection. |
|
The Metropolitan Museum of Art (The Met) hosts images and metadata for |
|
all objects in its collection, and these can be explored using the following |
|
link: https://www.metmuseum.org/art/collection/search . |
|
|
|
Of the approximately 450,000 objects in the collection, The Met has deemed |
|
approximately 243,600 of them to be in the public domain. As such, The Met has |
|
granted a CC0 license to the images and metadata for these objects. Thus, |
|
they may be freely used, collected, remixed, and redistributed for |
|
commercial or non-commercial means, without the museum's express permission. |
|
|
|
In addition to the images, the dataset includes additional class labels and features for each image : |
|
|
|
* "department": The object's department in the museum collection, e.g. "Drawing and Prints" or "Islamic Art". |
|
* "artist": The artist's name, if applicable. |
|
* "object_id": The ID used to identify the object in The Met's collection. |
|
* "object_date": The year or approximate year(s) in which the object was made. |
|
* "title": The object's title, if applicable. |
|
* "object_name": The object's name, if applicable, e.g "Photograph" or "Drawing". Has more to do with the object's Medium than its title. |
|
* "medium": The object's medium, e.g. "Albumen silver print" or "Bronze". |
|
* "classification": The object's classification, e.g. "Woodwork" or "Ceramics-Porcelain". |
|
* "filesize_bytes": The size, in bytes, of the image file. |
|
* "width": The width, in pixels, of the image file. |
|
* "height": The height, in pixels, of the image file. |
|
* "original_link": A link to the original listing page for the object in The Met's collection. |
|
|
|
Note: |
|
* The authors are neither responsible for the content nor the meaning of these images. |
|
|
|
By using the Metropolitan Museum of Art Open Access dataset, you agree to obey the terms and conditions of metmuseum.org (https://www.metmuseum.org/information/terms-and-conditions). |
|
|
|
Text features taken from the archive @ https://github.com/metmuseum/openaccess/blob/master/MetObjects.csv |
|
Images collected using The Met's API (see dataset homepage for more information). |
|
""" |
|
|
|
_HOMEPAGE = "https://www.metmuseum.github.io" |
|
|
|
_LICENSE = "CC0" |
|
|
|
_URLS = {"default": ""} |
|
|
|
_departments = [ |
|
"The American Wing", |
|
"European Sculpture and Decorative Arts", |
|
"Modern and Contemporary Art", |
|
"Arms and Armor", |
|
"Medieval Art", |
|
"Asian Art", |
|
"Islamic Art", |
|
"Costume Institute", |
|
"Arts of Africa, Oceania, and the Americas", |
|
"Drawings and Prints", |
|
"Greek and Roman Art", |
|
"Photographs", |
|
"Ancient Near Eastern Art", |
|
"Egyptian Art", |
|
"European Paintings", |
|
"Robert Lehman Collection", |
|
"The Cloisters", |
|
"Musical Instruments", |
|
"The Libraries", |
|
] |
|
|
|
|
|
class MetMuseum(datasets.GeneratorBasedBuilder): |
|
"""MetMuseum Dataset""" |
|
|
|
VERSION = datasets.Version("0.2.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="default", |
|
version=VERSION, |
|
description="The default version containing 81444 images with 3 labels for each", |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "default" |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"image": datasets.Image(), |
|
"department": datasets.ClassLabel( |
|
num_classes=len(_departments), names=_departments |
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls = _URLS[self.config.name] |
|
|
|
data_dir = "/Users/miccull/projects/opensource/cloob/all-images" |
|
filepath_csv = os.path.join("/Users/miccull/projects/opensource/cloob/metObjectsFinal_all_images.csv") |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"datadir": data_dir |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, datadir): |
|
df = pd.read_csv(datadir + '/../metObjectsFinal_all_images.csv', nrows=100) |
|
df.columns = [col.replace(' ','') for col in df.columns] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(len(df)): |
|
fname = os.path.join(datadir, df["basename"][i]) |
|
with open(fname, 'rb') as f: |
|
img_bytes = f.read() |
|
yield i, { |
|
"image": {'path': os.path.join(datadir, df["basename"][i]), 'bytes':img_bytes}, |
|
"department": df['Department'][i], |
|
"artist": df['ArtistDisplayName'][i[]], |
|
"object_id": df['ObjectID'][i], |
|
"accession_year": df['AccessionYear'][i], |
|
"title": df['Title'][i], |
|
"object_name":df['ObjectName'][i], |
|
"medium": df['Medium'][i], |
|
"object_date": df['ObjectDate'][i], |
|
"filesize_bytes": df['filesize_bytes'], |
|
"width": df['width'][i], |
|
"height": df['height'][i], |
|
"original_link": df['LinkResource'], |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|