Datasets:

Modalities:
Image
Formats:
parquet
Languages:
English
DOI:
Libraries:
Datasets
Dask
License:
jpodivin commited on
Commit
3d18b90
1 Parent(s): 4ab310f

Multiple configs

Browse files

Signed-off-by: Jiri Podivin <[email protected]>

Files changed (1) hide show
  1. plantorgans.py +42 -16
plantorgans.py CHANGED
@@ -31,15 +31,15 @@ _PANOPTIC_METADATA_URLS = {
31
  class PlantOrgansConfig(datasets.BuilderConfig):
32
  """Builder Config for PlantOrgans"""
33
 
34
- def __init__(self, data_url, metadata_urls, splits, **kwargs):
35
  """BuilderConfig for PlantOrgans.
36
  Args:
37
- data_url: `string`, url to download the zip file from.
38
  metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
39
  **kwargs: keyword arguments forwarded to super.
40
  """
41
  super().__init__(version=datasets.Version("1.0.0"), **kwargs)
42
- self.data_url = data_url
43
  self.metadata_urls = metadata_urls
44
  self.splits = splits
45
 
@@ -51,23 +51,36 @@ class PlantOrgans(datasets.GeneratorBasedBuilder):
51
  PlantOrgansConfig(
52
  name="semantic_segmentation_full",
53
  description="This configuration contains segmentation masks.",
54
- data_url=_BASE_URL,
55
  metadata_urls=_SEMANTIC_METADATA_URLS,
56
  splits=['train', 'test'],
57
  ),
 
 
 
 
 
 
 
58
  ]
59
 
60
  def _info(self):
61
- return datasets.DatasetInfo(
62
- description=_DESCRIPTION,
63
- features=datasets.Features(
64
  {
65
  "image": datasets.Image(),
66
  "mask": datasets.Image(),
67
  "image_name": datasets.Value(dtype="string"),
68
- "class": datasets.Value(dtype="string")
69
- }
70
- ),
 
 
 
 
 
 
 
 
71
  supervised_keys=("image", "mask"),
72
  homepage=_HOMEPAGE,
73
  citation=_CITATION,
@@ -82,18 +95,28 @@ class PlantOrgans(datasets.GeneratorBasedBuilder):
82
 
83
  train_paths = []
84
  test_paths = []
85
-
86
  for p in train_archives_paths:
87
  train_paths.extend(glob.glob(str(p)+'/sourcedata/labeled/**.jpg'))
88
  for p in test_archives_paths:
89
  test_paths.extend(glob.glob(str(p)+'/sourcedata/labeled/**.jpg'))
90
- split_metadata_paths = dl_manager.download(_SEMANTIC_METADATA_URLS)
91
-
92
- mask_archives_paths = dl_manager.download_and_extract(_SEMANTIC_MASKS_URLS)
 
 
 
 
 
 
 
 
 
 
93
 
94
  mask_paths = []
95
  for p in mask_archives_paths:
96
- mask_paths.extend(glob.glob(str(p)+'/semantic_masks/**.png'))
97
 
98
  return [
99
  datasets.SplitGenerator(
@@ -147,5 +170,8 @@ class PlantOrgans(datasets.GeneratorBasedBuilder):
147
  'image_name': Path(r['image_path']).parts[-1],
148
  'class': r['class']
149
  }
150
-
 
 
 
151
  yield i, example
 
31
  class PlantOrgansConfig(datasets.BuilderConfig):
32
  """Builder Config for PlantOrgans"""
33
 
34
+ def __init__(self, data_urls, metadata_urls, splits, **kwargs):
35
  """BuilderConfig for PlantOrgans.
36
  Args:
37
+ data_urls: list of `string`s, urls to download the zip files from.
38
  metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
39
  **kwargs: keyword arguments forwarded to super.
40
  """
41
  super().__init__(version=datasets.Version("1.0.0"), **kwargs)
42
+ self.data_urls = data_urls
43
  self.metadata_urls = metadata_urls
44
  self.splits = splits
45
 
 
51
  PlantOrgansConfig(
52
  name="semantic_segmentation_full",
53
  description="This configuration contains segmentation masks.",
54
+ data_urls=_BASE_URL,
55
  metadata_urls=_SEMANTIC_METADATA_URLS,
56
  splits=['train', 'test'],
57
  ),
58
+ PlantOrgansConfig(
59
+ name="instance_segmentation_full",
60
+ description="This configuration contains segmentation masks.",
61
+ data_urls=_BASE_URL,
62
+ metadata_urls=_PANOPTIC_METADATA_URLS,
63
+ splits=['train', 'test'],
64
+ ),
65
  ]
66
 
67
  def _info(self):
68
+ features=datasets.Features(
 
 
69
  {
70
  "image": datasets.Image(),
71
  "mask": datasets.Image(),
72
  "image_name": datasets.Value(dtype="string"),
73
+ "class": datasets.ClassLabel(
74
+ names=['Fruit', 'Leaf', 'Flower', 'Stem']),
75
+ })
76
+ if self.config.name == 'instance_segmentation_full':
77
+ features['score'] = datasets.Value(dtype="double")
78
+ else:
79
+ features['class'] = datasets.ClassLabel(
80
+ names=['Fruit', 'Leaf', 'Flower', 'Stem'])
81
+ return datasets.DatasetInfo(
82
+ description=_DESCRIPTION,
83
+ features=features,
84
  supervised_keys=("image", "mask"),
85
  homepage=_HOMEPAGE,
86
  citation=_CITATION,
 
95
 
96
  train_paths = []
97
  test_paths = []
98
+
99
  for p in train_archives_paths:
100
  train_paths.extend(glob.glob(str(p)+'/sourcedata/labeled/**.jpg'))
101
  for p in test_archives_paths:
102
  test_paths.extend(glob.glob(str(p)+'/sourcedata/labeled/**.jpg'))
103
+
104
+ if self.config.name == 'instance_segmentation_full':
105
+ metadata_urls = _PANOPTIC_METADATA_URLS
106
+ mask_urls = _MASKS_URLS
107
+ mask_glob = '/_masks/**.png'
108
+ else:
109
+ metadata_urls = _SEMANTIC_METADATA_URLS
110
+ mask_urls = _SEMANTIC_MASKS_URLS
111
+ mask_glob = '/semantic_masks/**.png'
112
+
113
+ split_metadata_paths = dl_manager.download(metadata_urls)
114
+
115
+ mask_archives_paths = dl_manager.download_and_extract(mask_urls)
116
 
117
  mask_paths = []
118
  for p in mask_archives_paths:
119
+ mask_paths.extend(glob.glob(str(p)+mask_glob))
120
 
121
  return [
122
  datasets.SplitGenerator(
 
170
  'image_name': Path(r['image_path']).parts[-1],
171
  'class': r['class']
172
  }
173
+ if self.config.name == 'instance_segmentation_full':
174
+ example['score'] = r['score']
175
+ else:
176
+ example['class'] = r['class']
177
  yield i, example