supervisely 6.73.398__py3-none-any.whl → 6.73.399__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- supervisely/convert/image/pascal_voc/pascal_voc_converter.py +46 -4
- supervisely/convert/image/pascal_voc/pascal_voc_helper.py +26 -11
- {supervisely-6.73.398.dist-info → supervisely-6.73.399.dist-info}/METADATA +1 -1
- {supervisely-6.73.398.dist-info → supervisely-6.73.399.dist-info}/RECORD +8 -8
- {supervisely-6.73.398.dist-info → supervisely-6.73.399.dist-info}/LICENSE +0 -0
- {supervisely-6.73.398.dist-info → supervisely-6.73.399.dist-info}/WHEEL +0 -0
- {supervisely-6.73.398.dist-info → supervisely-6.73.399.dist-info}/entry_points.txt +0 -0
- {supervisely-6.73.398.dist-info → supervisely-6.73.399.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import os
|
|
2
|
+
from collections import defaultdict
|
|
2
3
|
from typing import Dict, Optional, Set, Union
|
|
3
4
|
|
|
4
|
-
from supervisely import
|
|
5
|
+
from supervisely import (
|
|
6
|
+
Annotation,
|
|
7
|
+
ProjectMeta,
|
|
8
|
+
TagApplicableTo,
|
|
9
|
+
TagMeta,
|
|
10
|
+
TagValueType,
|
|
11
|
+
logger,
|
|
12
|
+
)
|
|
5
13
|
from supervisely.convert.base_converter import AvailableImageConverters
|
|
6
14
|
from supervisely.convert.image.image_converter import ImageConverter
|
|
7
15
|
from supervisely.convert.image.pascal_voc import pascal_voc_helper
|
|
@@ -139,6 +147,7 @@ class PascalVOCConverter(ImageConverter):
|
|
|
139
147
|
|
|
140
148
|
def _create_items(self, possible_pascal_voc_dir: str) -> int:
|
|
141
149
|
existing_cls_names = set([cls.name for cls in self._meta.obj_classes])
|
|
150
|
+
tags_to_values = defaultdict(set)
|
|
142
151
|
detected_ann_cnt = 0
|
|
143
152
|
|
|
144
153
|
images_list = list_files_recursively(self._imgs_dir, valid_extensions=self.allowed_exts)
|
|
@@ -153,13 +162,42 @@ class PascalVOCConverter(ImageConverter):
|
|
|
153
162
|
item_name_noext = get_file_name(item.name)
|
|
154
163
|
item = self._scan_for_item_segm_paths(item, item_name_noext)
|
|
155
164
|
ann_path = img_ann_map.get(item_name_noext) or img_ann_map.get(item.name)
|
|
156
|
-
item = self._scan_for_item_ann_path_and_update_meta(
|
|
165
|
+
item = self._scan_for_item_ann_path_and_update_meta(
|
|
166
|
+
item, ann_path, existing_cls_names, tags_to_values
|
|
167
|
+
)
|
|
157
168
|
|
|
158
169
|
if item.ann_data or item.segm_path:
|
|
159
170
|
detected_ann_cnt += 1
|
|
160
171
|
self._items.append(item)
|
|
172
|
+
self._meta = self._update_meta_with_tags(tags_to_values)
|
|
161
173
|
return detected_ann_cnt
|
|
162
174
|
|
|
175
|
+
def _update_meta_with_tags(self, tags_to_values: Dict[str, Set[str]]) -> ProjectMeta:
|
|
176
|
+
meta = self._meta
|
|
177
|
+
object_class_names = set(meta.obj_classes.keys())
|
|
178
|
+
for tag_name, values in tags_to_values.items():
|
|
179
|
+
tag_meta = meta.get_tag_meta(tag_name)
|
|
180
|
+
if tag_meta is not None:
|
|
181
|
+
continue
|
|
182
|
+
if tag_name in pascal_voc_helper.DEFAULT_SUBCLASSES:
|
|
183
|
+
if values.difference({"0", "1"}):
|
|
184
|
+
logger.warning(
|
|
185
|
+
f"Tag '{tag_name}' has non-binary values.", extra={"values": values}
|
|
186
|
+
)
|
|
187
|
+
tag_meta = TagMeta(tag_name, TagValueType.NONE)
|
|
188
|
+
elif tag_name in object_class_names:
|
|
189
|
+
tag_meta = TagMeta(
|
|
190
|
+
tag_name,
|
|
191
|
+
TagValueType.ONEOF_STRING,
|
|
192
|
+
possible_values=list(values),
|
|
193
|
+
applicable_to=TagApplicableTo.OBJECTS_ONLY,
|
|
194
|
+
applicable_classes=[tag_name],
|
|
195
|
+
)
|
|
196
|
+
else:
|
|
197
|
+
tag_meta = TagMeta(tag_name, TagValueType.ANY_STRING)
|
|
198
|
+
meta = meta.add_tag_meta(tag_meta)
|
|
199
|
+
return meta
|
|
200
|
+
|
|
163
201
|
def _scan_for_item_segm_paths(self, item: Item, item_name_noext: str) -> Item:
|
|
164
202
|
if self._segm_dir is not None:
|
|
165
203
|
segm_path = os.path.join(self._segm_dir, f"{item_name_noext}.png")
|
|
@@ -173,14 +211,18 @@ class PascalVOCConverter(ImageConverter):
|
|
|
173
211
|
return item
|
|
174
212
|
|
|
175
213
|
def _scan_for_item_ann_path_and_update_meta(
|
|
176
|
-
self,
|
|
214
|
+
self,
|
|
215
|
+
item: Item,
|
|
216
|
+
ann_path: Optional[str],
|
|
217
|
+
existing_cls_names: Set[str],
|
|
218
|
+
tags_to_values: Dict[str, Set[str]],
|
|
177
219
|
) -> Item:
|
|
178
220
|
if ann_path is None:
|
|
179
221
|
return item
|
|
180
222
|
if not file_exists(ann_path):
|
|
181
223
|
return item
|
|
182
224
|
self._meta = pascal_voc_helper.update_meta_from_xml(
|
|
183
|
-
ann_path, self._meta, existing_cls_names, self._bbox_classes_map
|
|
225
|
+
ann_path, self._meta, existing_cls_names, self._bbox_classes_map, tags_to_values
|
|
184
226
|
)
|
|
185
227
|
item.ann_data = ann_path
|
|
186
228
|
return item
|
|
@@ -13,7 +13,7 @@ from supervisely.annotation.label import Label
|
|
|
13
13
|
from supervisely.annotation.obj_class import ObjClass
|
|
14
14
|
from supervisely.annotation.obj_class_collection import ObjClassCollection
|
|
15
15
|
from supervisely.annotation.tag import Tag, TagValueType
|
|
16
|
-
from supervisely.annotation.tag_meta import TagMeta
|
|
16
|
+
from supervisely.annotation.tag_meta import TagApplicableTo, TagMeta
|
|
17
17
|
from supervisely.convert.image.image_helper import validate_image_bounds
|
|
18
18
|
from supervisely.geometry.bitmap import Bitmap
|
|
19
19
|
from supervisely.geometry.polygon import Polygon
|
|
@@ -36,6 +36,8 @@ TRAIN_TAG_NAME = "train"
|
|
|
36
36
|
VAL_TAG_NAME = "val"
|
|
37
37
|
TRAINVAL_TAG_NAME = "trainval"
|
|
38
38
|
DEFAULT_OBJECT_FIELDS = {"name", "class", "bndbox"}
|
|
39
|
+
DEFAULT_SUBCLASSES = {"pose", "truncated", "difficult", "occluded", "obstacle", "out-of-scope"}
|
|
40
|
+
|
|
39
41
|
|
|
40
42
|
default_classes_colors = {
|
|
41
43
|
"neutral": (224, 224, 192),
|
|
@@ -179,7 +181,7 @@ def get_ann(
|
|
|
179
181
|
ann = ann.add_labels(labels)
|
|
180
182
|
|
|
181
183
|
if np.sum(colored_img) > 0:
|
|
182
|
-
logger.
|
|
184
|
+
logger.warning(
|
|
183
185
|
f"Not all objects or classes are captured from source segmentation: {item.name}"
|
|
184
186
|
)
|
|
185
187
|
|
|
@@ -214,7 +216,7 @@ def xml_to_sly_labels(
|
|
|
214
216
|
cls_name = renamed_classes[cls_name]
|
|
215
217
|
obj_cls = meta.obj_classes.get(cls_name)
|
|
216
218
|
if obj_cls is None:
|
|
217
|
-
logger.
|
|
219
|
+
logger.warning(f"Class {cls_name} is not found in meta. Skipping.")
|
|
218
220
|
continue
|
|
219
221
|
elif field_name == "bndbox":
|
|
220
222
|
bbox_coords = [
|
|
@@ -227,11 +229,25 @@ def xml_to_sly_labels(
|
|
|
227
229
|
tag_name = renamed_tags[tag_name]
|
|
228
230
|
tag_meta = meta.get_tag_meta(tag_name)
|
|
229
231
|
if tag_meta is None:
|
|
230
|
-
logger.
|
|
232
|
+
logger.warning(f"Tag meta for '{field_name}' is not found in meta. Skipping.")
|
|
231
233
|
continue
|
|
232
|
-
if
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
if tag_meta.value_type == TagValueType.ANY_STRING:
|
|
235
|
+
if not isinstance(value, str):
|
|
236
|
+
value = str(value)
|
|
237
|
+
tags.append(Tag(tag_meta, value))
|
|
238
|
+
elif tag_meta.value_type == TagValueType.NONE:
|
|
239
|
+
if int(value) == 1:
|
|
240
|
+
tags.append(Tag(tag_meta))
|
|
241
|
+
else:
|
|
242
|
+
logger.debug("Tag with value '0' not added to labels.")
|
|
243
|
+
elif tag_meta.value_type == TagValueType.ONEOF_STRING:
|
|
244
|
+
if value not in tag_meta.possible_values:
|
|
245
|
+
logger.warning(
|
|
246
|
+
f"Value '{value}' for tag '{tag_name}' is not in possible values: {tag_meta.possible_values}. Skipping."
|
|
247
|
+
)
|
|
248
|
+
continue
|
|
249
|
+
tags.append(Tag(tag_meta, value))
|
|
250
|
+
|
|
235
251
|
if geometry is None or obj_cls is None:
|
|
236
252
|
continue
|
|
237
253
|
labels.append(Label(geometry, obj_cls, tags))
|
|
@@ -245,6 +261,7 @@ def update_meta_from_xml(
|
|
|
245
261
|
meta: ProjectMeta,
|
|
246
262
|
existing_cls_names: set,
|
|
247
263
|
bbox_classes_map: dict,
|
|
264
|
+
tags_to_values: Dict[str, set],
|
|
248
265
|
) -> ProjectMeta:
|
|
249
266
|
import xml.etree.ElementTree as ET
|
|
250
267
|
|
|
@@ -282,10 +299,8 @@ def update_meta_from_xml(
|
|
|
282
299
|
meta = meta.add_obj_class(obj_cls)
|
|
283
300
|
bbox_classes_map[original_class_name] = class_name
|
|
284
301
|
elif field_name not in DEFAULT_OBJECT_FIELDS:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
tag_meta = TagMeta(field_name, TagValueType.ANY_STRING)
|
|
288
|
-
meta = meta.add_tag_meta(tag_meta)
|
|
302
|
+
value = element.text
|
|
303
|
+
tags_to_values[field_name].add(value)
|
|
289
304
|
|
|
290
305
|
return meta
|
|
291
306
|
|
|
@@ -610,8 +610,8 @@ supervisely/convert/image/multi_view/multi_view.py,sha256=V-6oFN6oDre7UhejfyDkGK
|
|
|
610
610
|
supervisely/convert/image/multispectral/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
611
611
|
supervisely/convert/image/multispectral/multispectral_converter.py,sha256=T3etYVNI0AUUrQsQhxw_r85NthXrqhqmdZQfz8kUY0g,5194
|
|
612
612
|
supervisely/convert/image/pascal_voc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
613
|
-
supervisely/convert/image/pascal_voc/pascal_voc_converter.py,sha256=
|
|
614
|
-
supervisely/convert/image/pascal_voc/pascal_voc_helper.py,sha256=
|
|
613
|
+
supervisely/convert/image/pascal_voc/pascal_voc_converter.py,sha256=JwbkAT3W7aNHuxr9fas9PGrfDy4f5beyx6DWItIdVTw,9247
|
|
614
|
+
supervisely/convert/image/pascal_voc/pascal_voc_helper.py,sha256=Ek2KeQjKhSDup8PBE53Pg82x7HHNjDkWNilmz7BHYj4,30199
|
|
615
615
|
supervisely/convert/image/pdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
616
616
|
supervisely/convert/image/pdf/pdf_converter.py,sha256=LKvVng9jPp0cSIjYEjKLOb48wtdOdB7LXS2gjmOdZhE,2442
|
|
617
617
|
supervisely/convert/image/pdf/pdf_helper.py,sha256=IDwLEvsVy8lu-KC1lXvSRkZZ9BCC6ylebnNEtLQU5L4,1288
|
|
@@ -1114,9 +1114,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
|
1114
1114
|
supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
|
|
1115
1115
|
supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
|
|
1116
1116
|
supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
|
|
1117
|
-
supervisely-6.73.
|
|
1118
|
-
supervisely-6.73.
|
|
1119
|
-
supervisely-6.73.
|
|
1120
|
-
supervisely-6.73.
|
|
1121
|
-
supervisely-6.73.
|
|
1122
|
-
supervisely-6.73.
|
|
1117
|
+
supervisely-6.73.399.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
1118
|
+
supervisely-6.73.399.dist-info/METADATA,sha256=ZxlcTeH4-lJvPtaN7rpoQXr5o-qVhvyYrcfbFUiqm_M,35254
|
|
1119
|
+
supervisely-6.73.399.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
1120
|
+
supervisely-6.73.399.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
|
|
1121
|
+
supervisely-6.73.399.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
|
|
1122
|
+
supervisely-6.73.399.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|