File size: 2,668 Bytes
f97fadb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34ff160
 
f97fadb
34ff160
 
f97fadb
 
34ff160
 
f97fadb
 
 
 
 
 
 
 
 
 
34ff160
f97fadb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""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_FILE = f"{_REPO}/classes.txt"

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_FILE),
                }
            ),
            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)),
                }