supervisely 6.73.205__py3-none-any.whl → 6.73.206__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.

Potentially problematic release.


This version of supervisely might be problematic. Click here for more details.

@@ -29,7 +29,7 @@ from supervisely.convert.image.yolo.yolo_converter import YOLOConverter
29
29
  from supervisely.convert.image.multi_view.multi_view import MultiViewImageConverter
30
30
  from supervisely.convert.image.label_me.label_me_converter import LabelmeConverter
31
31
  from supervisely.convert.image.label_studio.label_studio_converter import LabelStudioConverter
32
-
32
+ from supervisely.convert.image.high_color.high_color_depth import HighColorDepthImageConverter
33
33
 
34
34
 
35
35
  # Pointcloud
@@ -52,4 +52,3 @@ from supervisely.convert.video.sly.sly_video_converter import SLYVideoConverter
52
52
  # Volume
53
53
  from supervisely.convert.volume.sly.sly_volume_converter import SLYVolumeConverter
54
54
  from supervisely.convert.volume.dicom.dicom_converter import DICOMConverter
55
-
@@ -31,6 +31,7 @@ class AvailableImageConverters:
31
31
  CITYSCAPES = "cityscapes"
32
32
  LABEL_ME = "label_me"
33
33
  LABEL_STUDIO = "label_studio"
34
+ HIGH_COLOR_DEPTH = "high_color_depth"
34
35
 
35
36
 
36
37
  class AvailableVideoConverters:
@@ -3,15 +3,13 @@ from pathlib import Path
3
3
 
4
4
  from tqdm import tqdm
5
5
 
6
- try:
7
- from typing import Literal
8
- except ImportError:
9
- from typing_extensions import Literal
6
+ from typing import Literal, Optional
10
7
 
11
8
  from supervisely._utils import is_production
12
9
  from supervisely.api.api import Api
13
10
  from supervisely.app import get_data_dir
14
11
  from supervisely.convert.image.csv.csv_converter import CSVConverter
12
+ from supervisely.convert.image.high_color.high_color_depth import HighColorDepthImageConverter
15
13
  from supervisely.convert.image.image_converter import ImageConverter
16
14
  from supervisely.convert.pointcloud.pointcloud_converter import PointcloudConverter
17
15
  from supervisely.convert.pointcloud_episodes.pointcloud_episodes_converter import (
@@ -33,21 +31,17 @@ from supervisely.io.fs import (
33
31
  from supervisely.project.project_type import ProjectType
34
32
  from supervisely.sly_logger import logger
35
33
  from supervisely.task.progress import Progress
34
+ from supervisely.project.project_settings import LabelingInterface
36
35
 
37
36
 
38
37
  class ImportManager:
38
+
39
39
  def __init__(
40
40
  self,
41
41
  input_data: str,
42
42
  project_type: ProjectType,
43
- team_id: int = None,
44
- labeling_interface: Literal[
45
- "default",
46
- "multi_view",
47
- "multispectral",
48
- "images_with_16_color",
49
- "medical_imaging_single",
50
- ] = "default",
43
+ team_id: Optional[int] = None,
44
+ labeling_interface: LabelingInterface = LabelingInterface.DEFAULT,
51
45
  upload_as_links: bool = False,
52
46
  ):
53
47
  self._api = Api.from_env()
@@ -69,7 +63,7 @@ class ImportManager:
69
63
 
70
64
  self._modality = project_type
71
65
  self._converter = self.get_converter()
72
- if isinstance(self._converter, CSVConverter):
66
+ if isinstance(self._converter, (HighColorDepthImageConverter, CSVConverter)):
73
67
  self._converter.team_id = self._team_id
74
68
 
75
69
  @property
File without changes
@@ -0,0 +1,141 @@
1
+ import os
2
+ from collections import defaultdict
3
+ from typing import Dict, Generator, Union
4
+
5
+ import cv2
6
+ import numpy as np
7
+ import tqdm
8
+
9
+ from supervisely import ProjectMeta, generate_free_name, is_development, logger
10
+ from supervisely._utils import batched
11
+ from supervisely.annotation.annotation import Annotation
12
+ from supervisely.api.api import Api
13
+ from supervisely.convert.base_converter import AvailableImageConverters
14
+ from supervisely.convert.image.high_color import high_color_helper as helpers
15
+ from supervisely.convert.image.image_converter import ImageConverter
16
+ from supervisely.io.env import task_id as get_task_id
17
+ from supervisely.io.env import team_id as get_team_id
18
+ from supervisely.io.fs import list_files_recursively
19
+ from supervisely.io.json import load_json_file
20
+ from supervisely.project.project_settings import LabelingInterface
21
+ from supervisely.team_files import RECOMMENDED_IMPORT_BACKUP_PATH
22
+
23
+
24
+ class HighColorDepthImageConverter(ImageConverter):
25
+ # allowed_exts = [".png", ".tiff", ".tif", ".bmp", ".exr", ".hdr"]
26
+ allowed_exts = [".exr", ".hdr"]
27
+
28
+ class Item(ImageConverter.Item):
29
+
30
+ def __init__(self, *args, **kwargs):
31
+ super().__init__(*args, **kwargs)
32
+ self._original_path = None
33
+
34
+ @property
35
+ def original_path(self) -> Union[str, None]:
36
+ return self._original_path
37
+
38
+ @original_path.setter
39
+ def original_path(self, original_path: str) -> None:
40
+ self._original_path = original_path
41
+
42
+ def __init__(self, *args, **kwargs):
43
+ super().__init__(*args, **kwargs)
44
+ self._team_id = None
45
+
46
+ def __str__(self):
47
+ return AvailableImageConverters.HIGH_COLOR_DEPTH
48
+
49
+ def validate_labeling_interface(self) -> bool:
50
+ """Only multi_view labeling interface can be used to group images on single screen."""
51
+ return self._labeling_interface in [
52
+ LabelingInterface.DEFAULT,
53
+ LabelingInterface.IMAGES_WITH_16_COLOR,
54
+ ]
55
+
56
+ def validate_format(self) -> bool:
57
+ logger.debug(f"Validating format: {self.__str__()}")
58
+
59
+ for image_path in self._find_high_color_depth_image_generator(self._input_data):
60
+ item = self.Item(image_path)
61
+ self._items.append(item)
62
+
63
+ if self.items_count == 0:
64
+ logger.debug(f"Not found any images with high color depth in '{self._input_data}'")
65
+ return False
66
+
67
+ return True
68
+
69
+ def _find_high_color_depth_image_generator(self, input_data: str) -> Generator[str, None, None]:
70
+ for image_path in list_files_recursively(input_data, valid_extensions=self.allowed_exts):
71
+ if self._is_high_color_depth_image(image_path):
72
+ yield image_path
73
+
74
+ def _is_high_color_depth_image(self, image_path: str) -> bool:
75
+ image = helpers.read_high_color_images(image_path)
76
+ if image is None:
77
+ return False
78
+ return image.dtype in self._supported_depths
79
+
80
+ @property
81
+ def _supported_depths(self):
82
+ return [np.uint16, np.int16, np.float16, np.float32, np.float64, np.uint32]
83
+
84
+ def to_supervisely(self, *args, **kwargs):
85
+ return None
86
+
87
+ def upload_dataset(
88
+ self,
89
+ api: Api,
90
+ dataset_id: int,
91
+ batch_size: int = 50,
92
+ log_progress=True,
93
+ ) -> None:
94
+ """Upload converted data to Supervisely"""
95
+ team_id = get_team_id()
96
+ backup_dir = os.path.join(RECOMMENDED_IMPORT_BACKUP_PATH, str(get_task_id()))
97
+
98
+ # progress, progress_cb = None, None
99
+ # if log_progress:
100
+ # progress, progress_cb = self.get_progress(
101
+ # len(self.get_items()),
102
+ # "Backing up original files and converting images to nrrd...",
103
+ # )
104
+
105
+ # Back up original files to avoid data loss and convert images to nrrd format
106
+ with tqdm.tqdm(
107
+ total=len(self.get_items()),
108
+ desc="Backing up original files and converting images to nrrd...",
109
+ ) as pbar:
110
+ for batch_items in batched(self.get_items(), batch_size=batch_size):
111
+
112
+ local_paths, remote_paths = [], []
113
+
114
+ for item in batch_items:
115
+ local_paths.append(item.path)
116
+
117
+ remote_path = os.path.join(backup_dir, item.name)
118
+ remote_paths.append(remote_path)
119
+
120
+ item.original_path = remote_path
121
+ image = helpers.read_high_color_images(item.path)
122
+
123
+ orig_item_name = item.name
124
+ nrrd_path = item.path + ".nrrd"
125
+ nrrd_path = helpers.save_nrrd(image, nrrd_path)
126
+ item.path = nrrd_path
127
+
128
+ item_meta = {}
129
+ # Add original file path to image meta
130
+ item_meta["original_file_path"] = os.path.join(backup_dir, orig_item_name)
131
+ if item.meta:
132
+ item_meta.update(item.meta)
133
+ item.set_meta_data(item_meta)
134
+
135
+ api.file.upload_bulk(team_id, local_paths, remote_paths)
136
+ pbar.update(len(batch_items))
137
+
138
+ if log_progress and is_development():
139
+ pbar.close()
140
+
141
+ super().upload_dataset(api, dataset_id, batch_size, log_progress, self.get_items())
@@ -0,0 +1,57 @@
1
+ import os
2
+
3
+ import cv2
4
+ import nrrd
5
+ import numpy as np
6
+
7
+ from supervisely._utils import generate_free_name
8
+ from supervisely.imaging.image import fliplr
9
+ from supervisely.io.fs import get_file_ext
10
+
11
+
12
+ def read_high_color_images(image_path: str) -> np.ndarray:
13
+ """Read high color images"""
14
+
15
+ ext = get_file_ext(image_path).lower()
16
+ if ext in [".exr", ".hdr"]:
17
+ os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
18
+
19
+ image = cv2.imread(image_path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
20
+ if image.ndim == 3:
21
+ # Convert the image to grayscale if it has 3 dimensions
22
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
23
+ # Normalize the image to 0-255
24
+ image = cv2.normalize(image, None, 0, 255, cv2.NORM_MINMAX)
25
+ # Convert to uint16
26
+ image = image.astype(np.uint16)
27
+
28
+ elif ext in [".tiff", ".tif"]:
29
+ import tifffile
30
+
31
+ image = tifffile.imread(image_path)
32
+ else:
33
+ image = cv2.imread(image_path)
34
+
35
+ return image
36
+
37
+
38
+ def save_nrrd(image: np.ndarray, save_path: str) -> str:
39
+ """Save numpy image as nrrd file"""
40
+
41
+ # Ensure the image is 2D
42
+ if image.ndim != 2:
43
+ raise ValueError("The image must be 2D to save as NRRD.")
44
+
45
+ image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE)
46
+ image = fliplr(image)
47
+
48
+ used_names = {os.path.basename(save_path)}
49
+
50
+ name = os.path.basename(save_path)
51
+ while os.path.exists(save_path):
52
+ name = generate_free_name(used_names, name, True, True)
53
+ save_path = os.path.join(os.path.dirname(save_path), name)
54
+
55
+ nrrd.write(save_path, image)
56
+
57
+ return save_path
@@ -1,5 +1,5 @@
1
- import os
2
1
  import mimetypes
2
+ import os
3
3
  from typing import Dict, List, Optional, Tuple, Union
4
4
 
5
5
  import cv2
@@ -16,10 +16,10 @@ from supervisely import (
16
16
  is_development,
17
17
  logger,
18
18
  )
19
- from supervisely.convert.base_converter import BaseConverter
20
19
  from supervisely.api.api import ApiContext
20
+ from supervisely.convert.base_converter import BaseConverter
21
21
  from supervisely.imaging.image import SUPPORTED_IMG_EXTS, is_valid_ext
22
- from supervisely.io.fs import get_file_ext, get_file_name, dirs_filter, list_files
22
+ from supervisely.io.fs import dirs_filter, get_file_ext, get_file_name, list_files
23
23
  from supervisely.io.json import load_json_file
24
24
  from supervisely.project.project_settings import LabelingInterface
25
25
 
@@ -31,12 +31,13 @@ class ImageConverter(BaseConverter):
31
31
  modality = "images"
32
32
 
33
33
  class Item(BaseConverter.BaseItem):
34
+
34
35
  def __init__(
35
36
  self,
36
37
  item_path: str,
37
38
  ann_data: Union[str, dict] = None,
38
39
  meta_data: Union[str, dict] = None,
39
- shape: Union[Tuple, List] = None,
40
+ shape: Optional[Union[Tuple, List]] = None,
40
41
  custom_data: Optional[dict] = None,
41
42
  ):
42
43
  self._path: str = item_path
@@ -51,7 +52,7 @@ class ImageConverter(BaseConverter):
51
52
  def meta(self) -> Union[str, dict]:
52
53
  return self._meta_data
53
54
 
54
- def set_shape(self, shape: Tuple[int, int] = None) -> None:
55
+ def set_shape(self, shape: Optional[Tuple[int, int]] = None) -> None:
55
56
  try:
56
57
  if shape is not None:
57
58
  self._shape = shape
@@ -145,7 +146,14 @@ class ImageConverter(BaseConverter):
145
146
  )
146
147
  item_names.append(name)
147
148
  item_paths.append(item.path)
148
- item_metas.append(load_json_file(item.meta) if item.meta else {})
149
+
150
+ if isinstance(item.meta, str): # path to file
151
+ item_metas.append(load_json_file(item.meta))
152
+ elif isinstance(item.meta, dict):
153
+ item_metas.append(item.meta)
154
+ else:
155
+ item_metas.append({})
156
+
149
157
  if ann is not None:
150
158
  anns.append(ann)
151
159
 
@@ -199,7 +207,11 @@ class ImageConverter(BaseConverter):
199
207
 
200
208
  def _is_meta_dir(dirpath: str) -> bool:
201
209
  if os.path.basename(dirpath).lower() == "meta":
202
- jsons = list_files(dirpath, valid_extensions=[".json"], ignore_valid_extensions_case=True)
210
+ jsons = list_files(
211
+ dirpath,
212
+ valid_extensions=[".json"],
213
+ ignore_valid_extensions_case=True,
214
+ )
203
215
  return len(jsons) > 0
204
216
  return False
205
217
 
@@ -1 +1,5 @@
1
- from supervisely.team_files.team_files_path import RECOMMENDED_EXPORT_PATH
1
+ from supervisely.team_files.team_files_path import (
2
+ RECOMMENDED_BACKUP_PATH,
3
+ RECOMMENDED_EXPORT_PATH,
4
+ RECOMMENDED_IMPORT_BACKUP_PATH,
5
+ )
@@ -1,3 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  RECOMMENDED_EXPORT_PATH = "/tmp/supervisely/export/"
4
+ RECOMMENDED_BACKUP_PATH = "/system/"
5
+ RECOMMENDED_IMPORT_BACKUP_PATH = RECOMMENDED_BACKUP_PATH + "imports/"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.205
3
+ Version: 6.73.206
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -553,11 +553,11 @@ supervisely/cli/teamfiles/teamfiles_upload.py,sha256=xnsW2rvdq1e-KGjF1tMBu7Oxh3n
553
553
  supervisely/collection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
554
554
  supervisely/collection/key_indexed_collection.py,sha256=x2UVlkprspWhhae9oLUzjTWBoIouiWY9UQSS_MozfH0,37643
555
555
  supervisely/collection/str_enum.py,sha256=Zp29yFGvnxC6oJRYNNlXhO2lTSdsriU1wiGHj6ahEJE,1250
556
- supervisely/convert/__init__.py,sha256=JZJl9I8bqiACgRi6mBdTQA6SwMxQQ82FQIGPgr3v0us,2478
557
- supervisely/convert/base_converter.py,sha256=dAUjG8ZPNbURZmZ1iy2O7VJlwPMN4zwlEETaL1Q1Wcg,14301
558
- supervisely/convert/converter.py,sha256=gOdi_2JQClrLkT303IQxKC7FKrUj3TGTyFiI0BZAIeg,8665
556
+ supervisely/convert/__init__.py,sha256=gRTV93OYJPI3FNfy78HO2SfR59qQ3FFKFSy_jw1adJ8,2571
557
+ supervisely/convert/base_converter.py,sha256=F5oCwQZ_w7XlIIQnW-y-2scvA9sC8vCJL2XMP3DtPZg,14343
558
+ supervisely/convert/converter.py,sha256=0F93xZmyprua63C6KxIeh0AbaFab81LiWqlkOVrkaYU,8672
559
559
  supervisely/convert/image/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
560
- supervisely/convert/image/image_converter.py,sha256=T53qY5A84TkspZJA4MVXqWmPi6OHt4Igtb0QQyAra5g,9135
560
+ supervisely/convert/image/image_converter.py,sha256=Er-QX6qyVO4p72iJ3ae0YMF9gSfm_SUimoH6id0MIIs,9446
561
561
  supervisely/convert/image/image_helper.py,sha256=21cpHiSzHS7brQpP15MAkrGh1lj7pOWh9Z976cObyIw,3145
562
562
  supervisely/convert/image/cityscapes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
563
563
  supervisely/convert/image/cityscapes/cityscapes_converter.py,sha256=msmsR2W-Xiod06dwn-MzmkbrEmQQqlKh7zyfTrW6YQw,7854
@@ -569,6 +569,9 @@ supervisely/convert/image/coco/coco_helper.py,sha256=ZjHlQIF7RReNROVGo5ZUANGv5iR
569
569
  supervisely/convert/image/csv/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
570
570
  supervisely/convert/image/csv/csv_converter.py,sha256=iLyc2PAVtlsAq7blnGH4iS1_D7Ai6-4UsdI_RlDVB9Q,11677
571
571
  supervisely/convert/image/csv/csv_helper.py,sha256=-nR192IfMU0vTlNRoKXu5FS6tTs9fENqySyeKKyemRs,8409
572
+ supervisely/convert/image/high_color/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
573
+ supervisely/convert/image/high_color/high_color_depth.py,sha256=t1LsOnEwhSmXUWxs2K7e_EHit5H0132_UibtFIt1P_w,5276
574
+ supervisely/convert/image/high_color/high_color_helper.py,sha256=bD5Jl6lmKbiNG_8Bpy-WvIYjSJqwdaVmXrHGVZT6o2w,1630
572
575
  supervisely/convert/image/label_me/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
573
576
  supervisely/convert/image/label_me/label_me_converter.py,sha256=E8epO8METLslVLy51AW7FoZto1jrPSFUZHDwzOnHbTk,3081
574
577
  supervisely/convert/image/label_me/label_me_helper.py,sha256=_JO-IS2iiGVcWBHFoC8-LDBW4deJ_Rt4s3Sl5rFjXFg,8279
@@ -909,8 +912,8 @@ supervisely/task/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
909
912
  supervisely/task/paths.py,sha256=Zk9zPhuJuq2eZnb8rLt1ED6sbwX6ikHYRSZQvDP0OBg,1197
910
913
  supervisely/task/progress.py,sha256=C7E9rDNnNYJezjmjCJPL1oXqH-LVm15p3OLetvapWaE,27667
911
914
  supervisely/task/task_logger.py,sha256=_uDfqEtiwetga6aDAqcTKCKqHjZJSuUXTsHSQFNxAvI,3531
912
- supervisely/team_files/__init__.py,sha256=3A43gNg_NL9ZHPrmHzOc1CLF6EUlDCfrT-gDcGiNj2E,74
913
- supervisely/team_files/team_files_path.py,sha256=AN7Ff80RwUtHt58R97MzJWDsYOeUp604yS0NakIUehI,70
915
+ supervisely/team_files/__init__.py,sha256=mtz0Z7eFvsykOcEnSVZ-5bNHsq0_YsNBjZK3qngO-DY,149
916
+ supervisely/team_files/team_files_path.py,sha256=dSqz-bycImQYwAs62TD1zCD1NQdysqCQIBhEVh9EDjw,177
914
917
  supervisely/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
915
918
  supervisely/user/user.py,sha256=4GSVIupPAxWjIxZmUtH3Dtms_vGV82-49kM_aaR2gBI,319
916
919
  supervisely/video/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -953,9 +956,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
953
956
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
954
957
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
955
958
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
956
- supervisely-6.73.205.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
957
- supervisely-6.73.205.dist-info/METADATA,sha256=Ie1M5PxEQCoDhgiXb2RL1NiA8tkVmDO5h0QRzbOJ140,33077
958
- supervisely-6.73.205.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
959
- supervisely-6.73.205.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
960
- supervisely-6.73.205.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
961
- supervisely-6.73.205.dist-info/RECORD,,
959
+ supervisely-6.73.206.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
960
+ supervisely-6.73.206.dist-info/METADATA,sha256=MQ9ZNLjLwIGBKpZiYf2S-F148rr3-bWJgg55ndrpleo,33077
961
+ supervisely-6.73.206.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
962
+ supervisely-6.73.206.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
963
+ supervisely-6.73.206.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
964
+ supervisely-6.73.206.dist-info/RECORD,,