|
"""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. |
|
""" |
|
|
|
_REPO = "https://huggingface.co/datasets/gjuggler/bird-data/resolve/main" |
|
|
|
_URLS = { |
|
"train": f"{_REPO}/data/train.zip", |
|
"test": f"{_REPO}/data/test.zip", |
|
} |
|
|
|
_CLASSES = """Abert's Towhee |
|
Acorn Woodpecker |
|
Allen's Hummingbird |
|
American Avocet |
|
American Black Duck |
|
American Coot |
|
American Crow |
|
American Dipper |
|
American Goldfinch |
|
American Kestrel |
|
American Oystercatcher |
|
American Pipit |
|
American Redstart |
|
American Robin |
|
American Tree Sparrow |
|
American White Pelican |
|
American Wigeon |
|
American Woodcock |
|
Anhinga |
|
Anna's Hummingbird |
|
Ash-throated Flycatcher |
|
Bald Eagle |
|
Baltimore Oriole |
|
Band-tailed Pigeon |
|
Bank Swallow |
|
Barn Owl |
|
Barn Swallow |
|
Barred Owl |
|
Barrow's Goldeneye |
|
Bay-breasted Warbler |
|
Bell's Vireo |
|
Belted Kingfisher |
|
Bewick's Wren |
|
Black Guillemot |
|
Black Oystercatcher |
|
Black Phoebe |
|
Black Rosy-Finch |
|
Black Scoter |
|
Black Skimmer |
|
Black Tern |
|
Black Turnstone |
|
Black Vulture |
|
Black-and-white Warbler |
|
Black-bellied Plover |
|
Black-bellied Whistling-Duck |
|
Black-billed Cuckoo |
|
Black-billed Magpie |
|
Black-capped Chickadee |
|
Black-chinned Hummingbird |
|
Black-crested Titmouse |
|
Black-crowned Night-Heron |
|
Black-headed Grosbeak |
|
Black-legged Kittiwake |
|
Black-necked Stilt |
|
Black-tailed Gnatcatcher |
|
Black-throated Blue Warbler |
|
Black-throated Gray Warbler |
|
Black-throated Green Warbler |
|
Blackburnian Warbler |
|
Blackpoll Warbler |
|
Blue Grosbeak |
|
Blue Jay |
|
Blue-gray Gnatcatcher |
|
Blue-headed Vireo |
|
Blue-winged Teal |
|
Blue-winged Warbler |
|
Boat-tailed Grackle |
|
Bobolink |
|
Bohemian Waxwing |
|
Bonaparte's Gull |
|
Boreal Chickadee |
|
Brandt's Cormorant |
|
Brant |
|
Brewer's Blackbird |
|
Brewer's Sparrow |
|
Bridled Titmouse |
|
Broad-billed Hummingbird |
|
Broad-tailed Hummingbird |
|
Broad-winged Hawk |
|
Bronzed Cowbird |
|
Brown Creeper |
|
Brown Pelican |
|
Brown Thrasher |
|
Brown-capped Rosy-Finch |
|
Brown-headed Cowbird |
|
Brown-headed Nuthatch |
|
Bufflehead |
|
Bullock's Oriole |
|
Burrowing Owl |
|
Bushtit |
|
Cackling Goose |
|
Cactus Wren |
|
California Gull |
|
California Quail |
|
California Thrasher |
|
California Towhee |
|
Calliope Hummingbird |
|
Canada Goose |
|
Canada Warbler |
|
Canvasback |
|
Canyon Towhee |
|
Canyon Wren |
|
Cape May Warbler |
|
Carolina Chickadee |
|
Carolina Wren |
|
Caspian Tern |
|
Cassin's Finch |
|
Cassin's Kingbird |
|
Cassin's Vireo |
|
Cattle Egret |
|
Cave Swallow |
|
Cedar Waxwing |
|
Chestnut-backed Chickadee |
|
Chestnut-sided Warbler |
|
Chihuahuan Raven |
|
Chimney Swift |
|
Chipping Sparrow |
|
Cinnamon Teal |
|
Clark's Grebe |
|
Clark's Nutcracker |
|
Clay-colored Sparrow |
|
Cliff Swallow |
|
Common Eider |
|
Common Gallinule |
|
Common Goldeneye |
|
Common Grackle |
|
Common Ground-Dove |
|
Common Loon |
|
Common Merganser |
|
Common Nighthawk |
|
Common Raven |
|
Common Redpoll |
|
Common Tern |
|
Common Yellowthroat |
|
Cooper's Hawk |
|
Cordilleran Flycatcher |
|
Costa's Hummingbird |
|
Crested Caracara |
|
Curve-billed Thrasher |
|
Dark-eyed Junco |
|
Dickcissel |
|
Double-crested Cormorant |
|
Downy Woodpecker |
|
Dunlin |
|
Eared Grebe |
|
Eastern Bluebird |
|
Eastern Kingbird |
|
Eastern Meadowlark |
|
Eastern Phoebe |
|
Eastern Screech-Owl |
|
Eastern Towhee |
|
Eastern Wood-Pewee |
|
Eurasian Collared-Dove |
|
Eurasian Eagle-Owl |
|
European Starling |
|
Evening Grosbeak |
|
Field Sparrow |
|
Fish Crow |
|
Florida Scrub-Jay |
|
Forster's Tern |
|
Fox Sparrow |
|
Gadwall |
|
Gambel's Quail |
|
Gila Woodpecker |
|
Glaucous-winged Gull |
|
Glossy Ibis |
|
Golden Eagle |
|
Golden-crowned Kinglet |
|
Golden-crowned Sparrow |
|
Golden-fronted Woodpecker |
|
Gray Catbird |
|
Gray Jay |
|
Gray-crowned Rosy-Finch |
|
Great Black-backed Gull |
|
Great Blue Heron |
|
Great Cormorant |
|
Great Crested Flycatcher |
|
Great Egret |
|
Great Horned Owl |
|
Great-tailed Grackle |
|
Greater Roadrunner |
|
Greater Scaup |
|
Greater White-fronted Goose |
|
Greater Yellowlegs |
|
Green Heron |
|
Green-tailed Towhee |
|
Green-winged Teal |
|
Hairy Woodpecker |
|
Harlequin Duck |
|
Harris's Hawk |
|
Harris's Sparrow |
|
Heermann's Gull |
|
Hermit Thrush |
|
Hermit Warbler |
|
Herring Gull |
|
Hoary Redpoll |
|
Hooded Merganser |
|
Hooded Oriole |
|
Hooded Warbler |
|
Horned Grebe |
|
Horned Lark |
|
House Finch |
|
House Sparrow |
|
House Wren |
|
Hutton's Vireo |
|
Inca Dove |
|
Indigo Bunting |
|
Juniper Titmouse |
|
Killdeer |
|
Ladder-backed Woodpecker |
|
Lark Bunting |
|
Lark Sparrow |
|
Laughing Gull |
|
Lazuli Bunting |
|
Least Flycatcher |
|
Least Sandpiper |
|
Lesser Goldfinch |
|
Lesser Scaup |
|
Lesser Yellowlegs |
|
Lincoln's Sparrow |
|
Little Blue Heron |
|
Loggerhead Shrike |
|
Long-billed Curlew |
|
Long-tailed Duck |
|
Louisiana Waterthrush |
|
MacGillivray's Warbler |
|
Magnolia Warbler |
|
Mallard |
|
Marbled Godwit |
|
Marsh Wren |
|
Merlin |
|
Mew Gull |
|
Mexican Jay |
|
Mississippi Kite |
|
Monk Parakeet |
|
Mottled Duck |
|
Mountain Bluebird |
|
Mountain Chickadee |
|
Mourning Dove |
|
Mourning Warbler |
|
Mute Swan |
|
Nashville Warbler |
|
Neotropic Cormorant |
|
Northern Bobwhite |
|
Northern Cardinal |
|
Northern Flicker |
|
Northern Gannet |
|
Northern Harrier |
|
Northern Mockingbird |
|
Northern Parula |
|
Northern Pintail |
|
Northern Pygmy-Owl |
|
Northern Rough-winged Swallow |
|
Northern Saw-whet Owl |
|
Northern Shoveler |
|
Northern Shrike |
|
Northern Waterthrush |
|
Northwestern Crow |
|
Nuttall's Woodpecker |
|
Oak Titmouse |
|
Orange-crowned Warbler |
|
Orchard Oriole |
|
Osprey |
|
Ovenbird |
|
Pacific Loon |
|
Pacific Wren |
|
Pacific-slope Flycatcher |
|
Painted Bunting |
|
Palm Warbler |
|
Pelagic Cormorant |
|
Peregrine Falcon |
|
Phainopepla |
|
Pied-billed Grebe |
|
Pigeon Guillemot |
|
Pileated Woodpecker |
|
Pine Grosbeak |
|
Pine Siskin |
|
Pine Warbler |
|
Plumbeous Vireo |
|
Prairie Falcon |
|
Prairie Warbler |
|
Prothonotary Warbler |
|
Purple Finch |
|
Purple Gallinule |
|
Purple Martin |
|
Pygmy Nuthatch |
|
Pyrrhuloxia |
|
Red Crossbill |
|
Red-bellied Woodpecker |
|
Red-breasted Merganser |
|
Red-breasted Nuthatch |
|
Red-breasted Sapsucker |
|
Red-eyed Vireo |
|
Red-headed Woodpecker |
|
Red-naped Sapsucker |
|
Red-necked Grebe |
|
Red-shouldered Hawk |
|
Red-tailed Hawk |
|
Red-throated Loon |
|
Red-winged Blackbird |
|
Reddish Egret |
|
Redhead |
|
Ring-billed Gull |
|
Ring-necked Duck |
|
Ring-necked Pheasant |
|
Rock Pigeon |
|
Rose-breasted Grosbeak |
|
Roseate Spoonbill |
|
Ross's Goose |
|
Rough-legged Hawk |
|
Royal Tern |
|
Ruby-crowned Kinglet |
|
Ruby-throated Hummingbird |
|
Ruddy Duck |
|
Ruddy Turnstone |
|
Ruffed Grouse |
|
Rufous Hummingbird |
|
Rufous-crowned Sparrow |
|
Rusty Blackbird |
|
Sanderling |
|
Sandhill Crane |
|
Savannah Sparrow |
|
Say's Phoebe |
|
Scaled Quail |
|
Scarlet Tanager |
|
Scissor-tailed Flycatcher |
|
Semipalmated Plover |
|
Semipalmated Sandpiper |
|
Sharp-shinned Hawk |
|
Short-billed Dowitcher |
|
Snow Bunting |
|
Snow Goose |
|
Snowy Egret |
|
Snowy Owl |
|
Solitary Sandpiper |
|
Song Sparrow |
|
Spotted Sandpiper |
|
Spotted Towhee |
|
Steller's Jay |
|
Summer Tanager |
|
Surf Scoter |
|
Surfbird |
|
Swainson's Hawk |
|
Swainson's Thrush |
|
Swallow-tailed Kite |
|
Swamp Sparrow |
|
Tennessee Warbler |
|
Townsend's Solitaire |
|
Townsend's Warbler |
|
Tree Swallow |
|
Tricolored Heron |
|
Trumpeter Swan |
|
Tufted Titmouse |
|
Tundra Swan |
|
Turkey Vulture |
|
Varied Thrush |
|
Vaux's Swift |
|
Veery |
|
Verdin |
|
Vermilion Flycatcher |
|
Vesper Sparrow |
|
Violet-green Swallow |
|
Warbling Vireo |
|
Western Bluebird |
|
Western Grebe |
|
Western Gull |
|
Western Kingbird |
|
Western Meadowlark |
|
Western Sandpiper |
|
Western Screech-Owl |
|
Western Scrub-Jay |
|
Western Tanager |
|
Western Wood-Pewee |
|
Whimbrel |
|
White Ibis |
|
White-breasted Nuthatch |
|
White-crowned Sparrow |
|
White-eyed Vireo |
|
White-faced Ibis |
|
White-tailed Kite |
|
White-throated Sparrow |
|
White-throated Swift |
|
White-winged Crossbill |
|
White-winged Dove |
|
White-winged Scoter |
|
Wild Turkey |
|
Willet |
|
Wilson's Phalarope |
|
Wilson's Snipe |
|
Wilson's Warbler |
|
Winter Wren |
|
Wood Duck |
|
Wood Stork |
|
Wood Thrush |
|
Wrentit |
|
Yellow Warbler |
|
Yellow-bellied Sapsucker |
|
Yellow-billed Cuckoo |
|
Yellow-billed Magpie |
|
Yellow-breasted Chat |
|
Yellow-crowned Night-Heron |
|
Yellow-headed Blackbird |
|
Yellow-rumped Warbler |
|
Yellow-throated Vireo |
|
Yellow-throated Warbler |
|
""".splitlines() |
|
|
|
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=_CLASSES), |
|
} |
|
), |
|
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)), |
|
} |