|
"""nabirds dataset.""" |
|
|
|
import os |
|
|
|
import datasets |
|
from datasets.tasks import ImageClassification |
|
|
|
|
|
_HOMEPAGE = "https://dl.allaboutbirds.org/nabirds" |
|
|
|
_CITATION = """\ |
|
@MISC{Van_Horn_undated-kj, |
|
title = "Building a bird recognition app and large scale dataset with citizen |
|
scientists: The fine print in fine-grained dataset collection", |
|
author = "Van Horn, Grant and Branson, Steve and Farrell, Ryan and Haber, |
|
Scott and Barry, Jessie and Ipeirotis, Panos and Perona, Pietro and |
|
Belongie, Serge and Lab Of Ornithology, Cornell and Tech, Cornell" |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
We worked with citizen scientists and domainexperts to collect NABirds, a new high |
|
quality dataset containing 48,562 images of North American birds with 555 |
|
categories, part annotations and bounding boxes. |
|
""" |
|
|
|
_URLS = { |
|
"train": "data/train.zip", |
|
"test": "data/test.zip", |
|
} |
|
|
|
class Beans(datasets.GeneratorBasedBuilder): |
|
"""Beans plant leaf images dataset.""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"image_file_path": datasets.Value("string"), |
|
"image": datasets.Image(), |
|
"labels": datasets.features.ClassLabel(names_file="classes.txt"), |
|
} |
|
), |
|
supervised_keys=("image", "labels"), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
task_templates=[ImageClassification(image_column="image", label_column="labels")], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_files = dl_manager.download_and_extract(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"files": dl_manager.iter_files([data_files["train"]]), |
|
}, |
|
), |
|
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"): |
|
yield i, { |
|
"image_file_path": path, |
|
"image": path, |
|
"labels": os.path.basename(os.path.dirname(path)), |
|
} |