nateraw commited on
Commit
15a9de8
1 Parent(s): bd999a7

Create beans.py

Browse files
Files changed (1) hide show
  1. beans.py +89 -0
beans.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The TensorFlow Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Beans leaf dataset with images of diseased and health leaves."""
17
+
18
+ from pathlib import Path
19
+
20
+ import datasets
21
+
22
+ _CITATION = """\
23
+ @ONLINE {beansdata,
24
+ author="Makerere AI Lab",
25
+ title="Bean disease dataset",
26
+ month="January",
27
+ year="2020",
28
+ url="https://github.com/AI-Lab-Makerere/ibean/"
29
+ }
30
+ """
31
+
32
+ _DESCRIPTION = """\
33
+ Beans is a dataset of images of beans taken in the field using smartphone
34
+ cameras. It consists of 3 classes: 2 disease classes and the healthy class.
35
+ Diseases depicted include Angular Leaf Spot and Bean Rust. Data was annotated
36
+ by experts from the National Crops Resources Research Institute (NaCRRI) in
37
+ Uganda and collected by the Makerere AI research lab.
38
+ """
39
+
40
+ _URLS = {
41
+ 'train': "https://storage.googleapis.com/ibeans/train.zip",
42
+ 'validation': "https://storage.googleapis.com/ibeans/validation.zip",
43
+ 'test': "https://storage.googleapis.com/ibeans/test.zip"
44
+ }
45
+
46
+ _NAMES = ["angular_leaf_spot", "bean_rust", "healthy"]
47
+
48
+ class Beans(datasets.GeneratorBasedBuilder):
49
+ """Beans plant leaf images dataset."""
50
+
51
+ def _info(self):
52
+ return datasets.DatasetInfo(
53
+ description=_DESCRIPTION,
54
+ features=datasets.Features({
55
+ "file":
56
+ datasets.Value("string"),
57
+ "labels":
58
+ datasets.features.ClassLabel(names=sorted(tuple(_NAMES))),
59
+ }),
60
+ supervised_keys=("file", "labels"),
61
+ homepage="https://github.com/AI-Lab-Makerere/ibean/",
62
+ citation=_CITATION
63
+ )
64
+
65
+ def _split_generators(self, dl_manager):
66
+ data_files = dl_manager.download_and_extract(_URLS)
67
+ return [
68
+ datasets.SplitGenerator(
69
+ name=datasets.Split.TRAIN,
70
+ gen_kwargs={
71
+ "archive": data_files['train'],
72
+ }),
73
+ datasets.SplitGenerator(
74
+ name=datasets.Split.VALIDATION,
75
+ gen_kwargs={
76
+ "archive": data_files['validation'],
77
+ }),
78
+ datasets.SplitGenerator(
79
+ name=datasets.Split.TEST,
80
+ gen_kwargs={
81
+ "archive": data_files['test'],
82
+ }),
83
+ ]
84
+
85
+ def _generate_examples(self, archive):
86
+ labels = self.info.features['labels']
87
+ for i, path in enumerate(Path(archive).glob('**/*')):
88
+ if path.suffix == '.jpg':
89
+ yield i, dict(file=path.as_posix(), labels=labels.encode_example(path.parent.name.lower()))