apetulante commited on
Commit
05cf4f5
·
1 Parent(s): 883c2d9

Create new file

Browse files
Files changed (1) hide show
  1. mortars_test.py +94 -0
mortars_test.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = ""
24
+
25
+ _CITATION = ""
26
+
27
+ _DESCRIPTION = """\
28
+ Beans is a dataset of images of beans taken in the field using smartphone
29
+ cameras. It consists of 3 classes: 2 disease classes and the healthy class.
30
+ Diseases depicted include Angular Leaf Spot and Bean Rust. Data was annotated
31
+ by experts from the National Crops Resources Research Institute (NaCRRI) in
32
+ Uganda and collected by the Makerere AI research lab.
33
+ """
34
+
35
+ _URLS = {
36
+ "train": "https://huggingface.co/datasets/apetulante/mortars_test/main/data/train.zip",
37
+ "validation": "https://huggingface.co/datasets/apetulante/mortars_test/main/data/validation.zip",
38
+ "test": "https://huggingface.co/datasets/apetulante/mortars_test/main/data/test.zip",
39
+ }
40
+
41
+ _NAMES = ["Obsidian", "Chert", "Sand"]
42
+
43
+
44
+ class Mortars(datasets.GeneratorBasedBuilder):
45
+ """Beans plant leaf images dataset."""
46
+
47
+ def _info(self):
48
+ return datasets.DatasetInfo(
49
+ description=_DESCRIPTION,
50
+ features=datasets.Features(
51
+ {
52
+ "image_file_path": datasets.Value("string"),
53
+ "image": datasets.Image(),
54
+ "labels": datasets.features.ClassLabel(names=_NAMES),
55
+ }
56
+ ),
57
+ supervised_keys=("image", "labels"),
58
+ homepage=_HOMEPAGE,
59
+ citation=_CITATION,
60
+ task_templates=[ImageClassification(image_column="image", label_column="labels")],
61
+ )
62
+
63
+ def _split_generators(self, dl_manager):
64
+ data_files = dl_manager.download_and_extract(_URLS)
65
+ return [
66
+ datasets.SplitGenerator(
67
+ name=datasets.Split.TRAIN,
68
+ gen_kwargs={
69
+ "files": dl_manager.iter_files([data_files["train"]]),
70
+ },
71
+ ),
72
+ datasets.SplitGenerator(
73
+ name=datasets.Split.VALIDATION,
74
+ gen_kwargs={
75
+ "files": dl_manager.iter_files([data_files["validation"]]),
76
+ },
77
+ ),
78
+ datasets.SplitGenerator(
79
+ name=datasets.Split.TEST,
80
+ gen_kwargs={
81
+ "files": dl_manager.iter_files([data_files["test"]]),
82
+ },
83
+ ),
84
+ ]
85
+
86
+ def _generate_examples(self, files):
87
+ for i, path in enumerate(files):
88
+ file_name = os.path.basename(path)
89
+ if file_name.endswith(".bmp"):
90
+ yield i, {
91
+ "image_file_path": path,
92
+ "image": path,
93
+ "labels": os.path.basename(os.path.dirname(path)).lower(),
94
+ }