|
from functools import cached_property |
|
from pathlib import Path |
|
|
|
import datasets |
|
|
|
_VERSION = "0.1.0" |
|
|
|
_CITATION = """ |
|
@inproceedings{5539970, |
|
title = {SUN database: Large-scale scene recognition from abbey to zoo}, |
|
author = {Xiao, Jianxiong and Hays, James and Ehinger, Krista A. and Oliva, Aude and Torralba, Antonio}, |
|
year = 2010, |
|
booktitle = {2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition}, |
|
volume = {}, |
|
number = {}, |
|
pages = {3485--3492}, |
|
doi = {10.1109/CVPR.2010.5539970}, |
|
keywords = {Sun;Large-scale systems;Layout;Humans;Image databases;Computer vision;Anthropometry;Bridges;Legged locomotion;Spatial databases} |
|
} |
|
@article{Xiao2014SUNDE, |
|
title = {SUN Database: Exploring a Large Collection of Scene Categories}, |
|
author = {Jianxiong Xiao and Krista A. Ehinger and James Hays and Antonio Torralba and Aude Oliva}, |
|
year = 2014, |
|
journal = {International Journal of Computer Vision}, |
|
volume = 119, |
|
pages = {3--22}, |
|
url = {https://api.semanticscholar.org/CorpusID:10224573} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """ |
|
Scene categorization is a fundamental problem in computer vision. |
|
However, scene understanding research has been constrained by the limited scope of currently-used databases which do not capture the full variety of scene categories. |
|
Whereas standard databases for object categorization contain hundreds of different classes of objects, the largest available dataset of scene categories contains only 15 classes. |
|
In this paper we propose the extensive Scene UNderstanding (SUN) database that contains 899 categories and 130,519 images. |
|
We use 397 well-sampled categories to evaluate numerous state-of-the-art algorithms for scene recognition and establish new bounds of performance. |
|
We measure human scene classification performance on the SUN database and compare this with computational methods. |
|
""" |
|
|
|
_HOMEPAGE = "https://vision.princeton.edu/projects/2010/SUN/" |
|
|
|
_LICENSE = "" |
|
|
|
_URL = "http://vision.princeton.edu/projects/2010/SUN/SUN397.tar.gz" |
|
|
|
|
|
class SUN397(datasets.GeneratorBasedBuilder): |
|
DEFAULT_WRITER_BATCH_SIZE = 1000 |
|
|
|
@cached_property |
|
def archive_path(self): |
|
dl_manager = datasets.DownloadManager() |
|
return Path(dl_manager.download_and_extract(_URL)) / "SUN397" |
|
|
|
@property |
|
def features(self): |
|
return datasets.Features( |
|
{ |
|
"image": datasets.Image(mode="RGB"), |
|
"label": datasets.ClassLabel(names_file=self.archive_path / "ClassName.txt"), |
|
} |
|
) |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
features=self.features, |
|
supervised_keys=None, |
|
description=_DESCRIPTION, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
version=_VERSION, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
images = sorted(list(self.archive_path.rglob("*.jpg"))) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"images": images}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, images: list[Path]): |
|
for i, image in enumerate(images): |
|
yield ( |
|
i, |
|
{ |
|
"image": str(image), |
|
"label": f"/{image.relative_to(self.archive_path).parent}", |
|
}, |
|
) |
|
|