supervisely 6.73.398__py3-none-any.whl → 6.73.400__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.
@@ -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 Annotation, ProjectMeta, logger
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(item, ann_path, existing_cls_names)
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, item: Item, ann_path: Optional[str], existing_cls_names: Set[str]
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.warn(
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.warn(f"Class {cls_name} is not found in meta. Skipping.")
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.warn(f"Tag meta for '{field_name}' is not found in meta. Skipping.")
232
+ logger.warning(f"Tag meta for '{field_name}' is not found in meta. Skipping.")
231
233
  continue
232
- if not isinstance(value, str):
233
- value = str(value)
234
- tags.append(Tag(tag_meta, value))
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
- tag_meta = meta.get_tag_meta(field_name)
286
- if tag_meta is None:
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.398
3
+ Version: 6.73.400
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -1,5 +1,5 @@
1
1
  supervisely/README.md,sha256=XM-DiMC6To3I9RjQZ0c61905EFRR_jnCUx2q3uNR-X8,3331
2
- supervisely/__init__.py,sha256=tliCAEdCVwLeYtNSmvSGKm1JOK1aXsP0ckJ3042J-0U,10935
2
+ supervisely/__init__.py,sha256=5wSN2Mq7CuqG9rnlbqXmRwTYUs3ARPN2LMbFZA5gAv8,11010
3
3
  supervisely/_utils.py,sha256=Wrnck4645QXRZdmMpqIRQ_t6QynEAkYaFfcialxQBIE,19157
4
4
  supervisely/function_wrapper.py,sha256=R5YajTQ0GnRp2vtjwfC9hINkzQc0JiyGsu8TER373xY,1912
5
5
  supervisely/sly_logger.py,sha256=z92Vu5hmC0GgTIJO1n6kPDayRW9__8ix8hL6poDZj-Y,6274
@@ -22,23 +22,23 @@ supervisely/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  supervisely/api/advanced_api.py,sha256=Nd5cCnHFWc3PSUrCtENxTGtDjS37_lCHXsgXvUI3Ti8,2054
23
23
  supervisely/api/agent_api.py,sha256=8EQBwD6v7KLS0-xKcZ12B7mtzKwG7RRgq1fk1vaN144,8893
24
24
  supervisely/api/annotation_api.py,sha256=U6dHUIOt6Fe8XcbX1MA19z-fg91maOumJAawKG5ZJsk,82876
25
- supervisely/api/api.py,sha256=HyW8K0AEsiFf3HV2o9HbS-UJZfuMwWGIJPERbNifgWg,67695
26
- supervisely/api/app_api.py,sha256=u0DLOTS0jMD73bUFDmJkr1y3Tfw70hmbox1gq5Tw1a4,75707
25
+ supervisely/api/api.py,sha256=pEgRIWlVqDdtDjAeL_nx2Rwldm6ANwLLacm6kLnyvbE,67723
26
+ supervisely/api/app_api.py,sha256=HaltkadXqel7hFBQdwsn5Qvmrx5eEqDXUu6X98nHerk,76226
27
27
  supervisely/api/constants.py,sha256=WfqIcEpRnU4Mcfb6q0njeRs2VVSoTAJaIyrqBkBjP8I,253
28
28
  supervisely/api/dataset_api.py,sha256=7idBMFL8jumWNw-wlBAbQWC09RskG-3GlidfPDukq3Q,47930
29
- supervisely/api/entities_collection_api.py,sha256=6nbh5KxBzqGwtjV9tgzMFHBKVla2x-pgIV_xfSL6j4E,9960
29
+ supervisely/api/entities_collection_api.py,sha256=Be13HsfMFLmq9XpiOfQog0Y569kbUn52hXv6x5vX3Vg,22624
30
30
  supervisely/api/file_api.py,sha256=gNXNsikocSYRojoZrVmXIqXycqXm0e320piAwaLN6JI,92978
31
31
  supervisely/api/github_api.py,sha256=NIexNjEer9H5rf5sw2LEZd7C1WR-tK4t6IZzsgeAAwQ,623
32
32
  supervisely/api/image_annotation_tool_api.py,sha256=YcUo78jRDBJYvIjrd-Y6FJAasLta54nnxhyaGyanovA,5237
33
- supervisely/api/image_api.py,sha256=mjKuX6jG5TK_V8EQyqcD6eSBAK1oJbVJZCDtflO00mg,227764
33
+ supervisely/api/image_api.py,sha256=kDx5VO-1IXrN6HDTta9CYjlPGHGiXOh2zv1wO5rON0s,232422
34
34
  supervisely/api/import_storage_api.py,sha256=BDCgmR0Hv6OoiRHLCVPKt3iDxSVlQp1WrnKhAK_Zl84,460
35
35
  supervisely/api/issues_api.py,sha256=BqDJXmNoTzwc3xe6_-mA7FDFC5QQ-ahGbXk_HmpkSeQ,17925
36
36
  supervisely/api/labeling_job_api.py,sha256=G2_BV_WtA2lAhfw_nAQmWmv1P-pwimD0ba9GVKoGjiA,55537
37
37
  supervisely/api/labeling_queue_api.py,sha256=ilNjAL1d9NSa9yabQn6E-W26YdtooT3ZGXIFZtGnAvY,30158
38
- supervisely/api/module_api.py,sha256=LKRciU6kKiBTUxb_3iYd5yfUBrhm9Sl0epDd8YBTnPc,45413
38
+ supervisely/api/module_api.py,sha256=Pqj_BxgHmfba0MGA5PPNU-dbSrwR4Fcyfaqnc-cKwGI,46006
39
39
  supervisely/api/object_class_api.py,sha256=7-npNFMYjWNtSXYZg6syc6bX56_oCzDU2kFRPGQWCwA,10399
40
40
  supervisely/api/plugin_api.py,sha256=SFm0IlTTOjuHBLUMgG4d4k6U3cWJocE-SVb-f08fwMQ,5286
41
- supervisely/api/project_api.py,sha256=WNTMqAa0ZedYesfiZEkZtaFr5huxIpJ8TFYygTnlAWQ,80309
41
+ supervisely/api/project_api.py,sha256=WELYM9ktA0L5TgQ2VgICxNPVWUA7LCzMi1ntBWXSIfg,88664
42
42
  supervisely/api/project_class_api.py,sha256=5cyjdGPPb2tpttu5WmYoOxUNiDxqiojschkhZumF0KM,1426
43
43
  supervisely/api/remote_storage_api.py,sha256=1O4rTIwW8s9gxC00yvFuKbEMGNsa7YSRlZ8j494ARwY,17793
44
44
  supervisely/api/report_api.py,sha256=Om7CGulUbQ4BuJ16eDtz7luLe0JQNqab-LoLpUXu7YE,7123
@@ -69,7 +69,7 @@ supervisely/api/pointcloud/pointcloud_object_api.py,sha256=bO1USWb9HAywG_CW4CDu1
69
69
  supervisely/api/pointcloud/pointcloud_tag_api.py,sha256=iShtr052nOElxsyMyZEUT2vypEm6kP00gnP13ABX24A,4691
70
70
  supervisely/api/video/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
71
  supervisely/api/video/video_annotation_api.py,sha256=LAdZUC5qB6Q3ufDEUfWERYiglM3I_MYg9Yv1Nn6aKZ4,14137
72
- supervisely/api/video/video_api.py,sha256=0IAmhidtlIr3N_tcOG_YrALQ_TBOAf2tsQei5_RrRuM,94503
72
+ supervisely/api/video/video_api.py,sha256=H4Lm6S4CSZ2fP2mCchWtqUrczlzfDVsb7Tc5ZNPXDcc,94738
73
73
  supervisely/api/video/video_figure_api.py,sha256=quksohjhgrK2l2-PtbbNE99fOW6uWXX59-_4xfc-I-k,6244
74
74
  supervisely/api/video/video_frame_api.py,sha256=4GwSI4xdCNYEUvTqzKc-Ewd44fw5zqkFoD24jrrN_aY,10214
75
75
  supervisely/api/video/video_object_api.py,sha256=IC0NP8EoIT_d3xxDRgz2cA3ixSiuJ5ymy64eS-RfmDM,2227
@@ -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=zpn_s_WT1Z72WztXlPEJIBfO7-DbHCnjsOZFGOoYMCA,7729
614
- supervisely/convert/image/pascal_voc/pascal_voc_helper.py,sha256=vu6L2Gm1IU5aDPGibngVJvdje0ndS8NW-0WRhmr6vPE,29415
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.398.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1118
- supervisely-6.73.398.dist-info/METADATA,sha256=63LzbyDrvBYTjAZtYOo7Wp9ealkOXaqXMsjXZL4UtGw,35254
1119
- supervisely-6.73.398.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1120
- supervisely-6.73.398.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1121
- supervisely-6.73.398.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1122
- supervisely-6.73.398.dist-info/RECORD,,
1117
+ supervisely-6.73.400.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1118
+ supervisely-6.73.400.dist-info/METADATA,sha256=OAhC-qZAZEo5vAWfXk7ZiFnIKM_iigbJZErhN6eSFJo,35254
1119
+ supervisely-6.73.400.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1120
+ supervisely-6.73.400.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1121
+ supervisely-6.73.400.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1122
+ supervisely-6.73.400.dist-info/RECORD,,