BerMaker commited on
Commit
8526963
·
1 Parent(s): d72ab95

Create beans.py

Browse files
Files changed (1) hide show
  1. beans.py +101 -0
beans.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ """Beans leaf dataset with images of diseased and health leaves."""
16
+
17
+ import os
18
+
19
+ import datasets
20
+ from datasets.tasks import ImageClassification
21
+
22
+
23
+ _HOMEPAGE = "https://github.com/AI-Lab-Makerere/ibean/"
24
+
25
+ _CITATION = """\
26
+ @ONLINE {beansdata,
27
+ author="Makerere AI Lab",
28
+ title="Bean disease dataset",
29
+ month="January",
30
+ year="2020",
31
+ url="https://github.com/AI-Lab-Makerere/ibean/"
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ Beans is a dataset of images of beans taken in the field using smartphone
37
+ cameras. It consists of 3 classes: 2 disease classes and the healthy class.
38
+ Diseases depicted include Angular Leaf Spot and Bean Rust. Data was annotated
39
+ by experts from the National Crops Resources Research Institute (NaCRRI) in
40
+ Uganda and collected by the Makerere AI research lab.
41
+ """
42
+
43
+ _URLS = {
44
+ "train": "http://rayoltest.oss-cn-hangzhou-zmf.aliyuncs.com/mars%2Ftmp%2Fdata%2Fvalidation.zip",
45
+ "test": "http://rayoltest.oss-cn-hangzhou-zmf.aliyuncs.com/mars%2Ftmp%2Fdata%2Ftest.zip",
46
+ }
47
+
48
+ _NAMES = ["angular_leaf_spot", "bean_rust", "healthy"]
49
+
50
+
51
+ class Beans(datasets.GeneratorBasedBuilder):
52
+ """Beans plant leaf images dataset."""
53
+
54
+ def _info(self):
55
+ return datasets.DatasetInfo(
56
+ description=_DESCRIPTION,
57
+ features=datasets.Features(
58
+ {
59
+ "image_file_path": datasets.Value("string"),
60
+ "image": datasets.Image(),
61
+ "labels": datasets.features.ClassLabel(names=_NAMES),
62
+ }
63
+ ),
64
+ supervised_keys=("image", "labels"),
65
+ homepage=_HOMEPAGE,
66
+ citation=_CITATION,
67
+ task_templates=[ImageClassification(image_column="image", label_column="labels")],
68
+ )
69
+
70
+ def _split_generators(self, dl_manager):
71
+ data_files = dl_manager.download_and_extract(_URLS)
72
+ return [
73
+ datasets.SplitGenerator(
74
+ name=datasets.Split.TRAIN,
75
+ gen_kwargs={
76
+ "files": dl_manager.iter_files([data_files["train"]]),
77
+ },
78
+ ),
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.VALIDATION,
81
+ gen_kwargs={
82
+ "files": dl_manager.iter_files([data_files["validation"]]),
83
+ },
84
+ ),
85
+ datasets.SplitGenerator(
86
+ name=datasets.Split.TEST,
87
+ gen_kwargs={
88
+ "files": dl_manager.iter_files([data_files["test"]]),
89
+ },
90
+ ),
91
+ ]
92
+
93
+ def _generate_examples(self, files):
94
+ for i, path in enumerate(files):
95
+ file_name = os.path.basename(path)
96
+ if file_name.endswith(".jpg"):
97
+ yield i, {
98
+ "image_file_path": path,
99
+ "image": path,
100
+ "labels": os.path.basename(os.path.dirname(path)).lower(),
101
+ }