Skip to content

Commit 69c35aa

Browse files
Merge pull request #370 from SoumyadeepJana:deepweeds
PiperOrigin-RevId: 264121191
2 parents 4d7308c + 3abaa11 commit 69c35aa

File tree

8 files changed

+145
-0
lines changed

8 files changed

+145
-0
lines changed

tensorflow_datasets/image/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from tensorflow_datasets.image.colorectal_histology import ColorectalHistology
3838
from tensorflow_datasets.image.colorectal_histology import ColorectalHistologyLarge
3939
from tensorflow_datasets.image.cycle_gan import CycleGAN
40+
from tensorflow_datasets.image.deep_weeds import DeepWeeds
4041
from tensorflow_datasets.image.diabetic_retinopathy_detection import DiabeticRetinopathyDetection
4142
from tensorflow_datasets.image.downsampled_imagenet import DownsampledImagenet
4243
from tensorflow_datasets.image.dsprites import Dsprites
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# coding=utf-8
2+
# Copyright 2019 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+
"""Dataset class for DeepWeeds dataset."""
17+
18+
from __future__ import absolute_import
19+
from __future__ import division
20+
from __future__ import print_function
21+
22+
import os
23+
24+
import tensorflow as tf
25+
import tensorflow_datasets.public_api as tfds
26+
27+
28+
_URL = "https://nextcloud.qriscloud.org.au/index.php/s/a3KxPawpqkiorST/download"
29+
30+
_DESCRIPTION = (
31+
"""The DeepWeeds dataset consists of 17,509 images capturing eight different weed species native to Australia """
32+
"""in situ with neighbouring flora.The selected weed species are local to pastoral grasslands across the state of Queensland."""
33+
"""The images were collected from weed infestations at the following sites across Queensland: "Black River", "Charters Towers", """
34+
""" "Cluden", "Douglas", "Hervey Range", "Kelso", "McKinlay" and "Paluma"."""
35+
)
36+
37+
_NAMES = [
38+
"Chinee apple", "Snake weed", "Lantana", "Prickly acacia", "Siam weed",
39+
"Parthenium", "Rubber vine", "Parkinsonia", "Negative"
40+
]
41+
42+
_IMAGE_SHAPE = (256, 256, 3)
43+
44+
_CITATION = """\
45+
@article{DeepWeeds2019,
46+
author = {Alex Olsen and
47+
Dmitry A. Konovalov and
48+
Bronson Philippa and
49+
Peter Ridd and
50+
Jake C. Wood and
51+
Jamie Johns and
52+
Wesley Banks and
53+
Benjamin Girgenti and
54+
Owen Kenny and
55+
James Whinney and
56+
Brendan Calvert and
57+
Mostafa {Rahimi Azghadi} and
58+
Ronald D. White},
59+
title = {{DeepWeeds: A Multiclass Weed Species Image Dataset for Deep Learning}},
60+
journal = {Scientific Reports},
61+
year = 2019,
62+
number = 2058,
63+
month = 2,
64+
volume = 9,
65+
issue = 1,
66+
day = 14,
67+
url = "https://doi.org/10.1038/s41598-018-38343-3",
68+
doi = "10.1038/s41598-018-38343-3"
69+
}
70+
"""
71+
72+
73+
class DeepWeeds(tfds.core.GeneratorBasedBuilder):
74+
"""DeepWeeds Image Dataset Class."""
75+
76+
VERSION = tfds.core.Version("1.0.0")
77+
78+
def _info(self):
79+
"""Define Dataset Info."""
80+
81+
return tfds.core.DatasetInfo(
82+
builder=self,
83+
description=(_DESCRIPTION),
84+
features=tfds.features.FeaturesDict({
85+
"image": tfds.features.Image(shape=_IMAGE_SHAPE),
86+
"label": tfds.features.ClassLabel(names=_NAMES),
87+
}),
88+
supervised_keys=("image", "label"),
89+
urls=[_URL],
90+
citation=_CITATION,
91+
)
92+
93+
def _split_generators(self, dl_manager):
94+
"""Define Splits."""
95+
path = dl_manager.download_and_extract(_URL)
96+
97+
return [
98+
tfds.core.SplitGenerator(
99+
name="train",
100+
gen_kwargs={
101+
"data_dir_path": path,
102+
},
103+
),
104+
]
105+
106+
def _generate_examples(self, data_dir_path):
107+
"""Generate images and labels for splits."""
108+
109+
for file_name in tf.io.gfile.listdir(data_dir_path):
110+
image = os.path.join(data_dir_path, file_name)
111+
label = _NAMES[int(file_name.split("-")[2].split(".")[0])]
112+
yield file_name, {"image": image, "label": label}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# coding=utf-8
2+
# Copyright 2019 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+
from __future__ import absolute_import
17+
from __future__ import division
18+
from __future__ import print_function
19+
from tensorflow_datasets.image import deep_weeds
20+
import tensorflow_datasets.testing as tfds_test
21+
22+
23+
class DeepWeedsTest(tfds_test.DatasetBuilderTestCase):
24+
DATASET_CLASS = deep_weeds.DeepWeeds
25+
SPLITS = {
26+
"train": 4,
27+
}
28+
29+
30+
if __name__ == "__main__":
31+
tfds_test.test_main()
28.8 KB
Loading
35.4 KB
Loading
26.4 KB
Loading
23.7 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://nextcloud.qriscloud.org.au/index.php/s/a3KxPawpqkiorST/download 935276050 d616b33efe097909bdac9623abc5705b59ad11f6796a26a956c1aa5de652f1ba

0 commit comments

Comments
 (0)