dating-historical-color-images / dating-historical-color-images.py
davanstrien's picture
davanstrien HF staff
fix formatting
1db2bc3
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Dataset for dating historical color images"""
from pathlib import Path
import datasets
_CITATION = """@inproceedings{10.1007/978-3-642-33783-3_36,
author = {Palermo, Frank and Hays, James and Efros, Alexei A.},
title = {Dating Historical Color Images},
year = {2012},
isbn = {9783642337826},
publisher = {Springer-Verlag},
address = {Berlin, Heidelberg},
url = {https://doi.org/10.1007/978-3-642-33783-3_36},
doi = {10.1007/978-3-642-33783-3_36},
abstract = {We introduce the task of automatically estimating the age of historical color photographs. We suggest features which attempt to capture temporally discriminative information based on the evolution of color imaging processes over time and evaluate the performance of both these novel features and existing features commonly utilized in other problem domains on a novel historical image data set. For the challenging classification task of sorting historical color images into the decade during which they were photographed, we demonstrate significantly greater accuracy than that shown by untrained humans on the same data set. Additionally, we apply the concept of data-driven camera response function estimation to historical color imagery, demonstrating its relevance to both the age estimation task and the popular application of imitating the appearance of vintage color photography.},
booktitle = {Proceedings of the 12th European Conference on Computer Vision - Volume Part VI},
pages = {499–512},
numpages = {14},
location = {Florence, Italy},
series = {ECCV'12}
}
"""
_DESCRIPTION = """\
This dataset contains color photographs taken between the 1930s and 1970s.
The goal of the dataset is to develop methods for dating historical color photographs
"""
_HOMEPAGE = "http://graphics.cs.cmu.edu/projects/historicalColor/"
_URLS = "http://graphics.cs.cmu.edu/projects/historicalColor/HistoricalColor-ECCV2012-DecadeDatabase.tar"
class IllustratedAds(datasets.GeneratorBasedBuilder):
"""Dating Historical Color Images dataset"""
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
"image": datasets.Image(),
"label": datasets.ClassLabel(
names=["1930s", "1940s", "1950s", "1960s", "1970s"]
),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
images = dl_manager.download(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"archive": dl_manager.iter_archive(images)},
),
]
def _generate_examples(self, archive):
id_ = 0
for fname, fobject in archive:
if Path(fname).suffix != ".jpg":
continue
image = fobject.read()
label = str(Path(fname).parts[-2])
id_ += 1
yield id_, {"image": image, "label": label}