samgis_core 1.1.0__py3-none-any.whl → 1.1.2__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.
- samgis_core/prediction_api/sam_onnx.py +13 -7
- samgis_core/utilities/serialize.py +2 -3
- samgis_core/utilities/type_hints.py +38 -13
- {samgis_core-1.1.0.dist-info → samgis_core-1.1.2.dist-info}/METADATA +1 -1
- {samgis_core-1.1.0.dist-info → samgis_core-1.1.2.dist-info}/RECORD +6 -6
- {samgis_core-1.1.0.dist-info → samgis_core-1.1.2.dist-info}/WHEEL +0 -0
@@ -32,7 +32,7 @@ from onnxruntime import get_available_providers, InferenceSession
|
|
32
32
|
|
33
33
|
from samgis_core import app_logger, MODEL_FOLDER
|
34
34
|
from samgis_core.utilities.constants import DEFAULT_INPUT_SHAPE, MODEL_ENCODER_NAME, MODEL_DECODER_NAME
|
35
|
-
from samgis_core.utilities.type_hints import PIL_Image,
|
35
|
+
from samgis_core.utilities.type_hints import PIL_Image, ListDict, TupleNdarrayInt, EmbeddingDict, EmbeddingImage
|
36
36
|
|
37
37
|
|
38
38
|
class SegmentAnythingONNX:
|
@@ -197,6 +197,12 @@ class SegmentAnythingONNX:
|
|
197
197
|
def encode(self, cv_image: ndarray) -> EmbeddingImage:
|
198
198
|
"""
|
199
199
|
Calculate embedding and metadata for a single image.
|
200
|
+
|
201
|
+
Args:
|
202
|
+
cv_image: input image to embed
|
203
|
+
|
204
|
+
Returns:
|
205
|
+
embedding image dict useful to store and cache image embeddings
|
200
206
|
"""
|
201
207
|
original_size = cv_image.shape[:2]
|
202
208
|
|
@@ -251,8 +257,8 @@ class SegmentAnythingONNX:
|
|
251
257
|
|
252
258
|
|
253
259
|
def get_raster_inference(
|
254
|
-
img: PIL_Image or ndarray, prompt:
|
255
|
-
) ->
|
260
|
+
img: PIL_Image or ndarray, prompt: ListDict, models_instance: SegmentAnythingONNX, model_name: str
|
261
|
+
) -> TupleNdarrayInt:
|
256
262
|
"""
|
257
263
|
Get inference output for a given image using a SegmentAnythingONNX model
|
258
264
|
|
@@ -312,7 +318,7 @@ def get_inference_embedding(
|
|
312
318
|
|
313
319
|
|
314
320
|
def get_raster_inference_using_existing_embedding(
|
315
|
-
embedding: dict, prompt:
|
321
|
+
embedding: dict, prompt: ListDict, models_instance: SegmentAnythingONNX) -> TupleNdarrayInt:
|
316
322
|
"""
|
317
323
|
Get inference output for a given image using a SegmentAnythingONNX model, using an existing embedding instead of a
|
318
324
|
new ndarray or PIL image
|
@@ -339,8 +345,8 @@ def get_raster_inference_using_existing_embedding(
|
|
339
345
|
|
340
346
|
|
341
347
|
def get_raster_inference_with_embedding_from_dict(
|
342
|
-
img: PIL_Image or ndarray, prompt:
|
343
|
-
embedding_key: str, embedding_dict: dict) ->
|
348
|
+
img: PIL_Image or ndarray, prompt: ListDict, models_instance: SegmentAnythingONNX, model_name: str,
|
349
|
+
embedding_key: str, embedding_dict: dict) -> TupleNdarrayInt:
|
344
350
|
"""
|
345
351
|
Get inference output using a SegmentAnythingONNX model, but get the image embedding from the given embedding dict
|
346
352
|
instead of creating a new embedding. This function needs the img argument to update the embedding dict if necessary
|
@@ -351,7 +357,7 @@ def get_raster_inference_with_embedding_from_dict(
|
|
351
357
|
models_instance: SegmentAnythingONNX instance model
|
352
358
|
model_name: model name string
|
353
359
|
embedding_key: embedding id
|
354
|
-
embedding_dict: embedding dict
|
360
|
+
embedding_dict: embedding images dict
|
355
361
|
|
356
362
|
Returns:
|
357
363
|
raster prediction mask, prediction number
|
@@ -2,7 +2,6 @@
|
|
2
2
|
from typing import Mapping
|
3
3
|
|
4
4
|
from samgis_core import app_logger
|
5
|
-
from samgis_core.utilities.type_hints import dict_str, dict_str_any
|
6
5
|
|
7
6
|
|
8
7
|
def serialize(obj: any, include_none: bool = False):
|
@@ -74,11 +73,11 @@ def _serialize_list(ls: list, include_none: bool) -> list:
|
|
74
73
|
return [_serialize(elem, include_none) for elem in ls]
|
75
74
|
|
76
75
|
|
77
|
-
def _serialize_bytes(b: bytes) ->
|
76
|
+
def _serialize_bytes(b: bytes) -> dict[str, str]:
|
78
77
|
import base64
|
79
78
|
encoded = base64.b64encode(b)
|
80
79
|
return {"value": encoded.decode('ascii'), "type": "bytes"}
|
81
80
|
|
82
81
|
|
83
|
-
def _serialize_exception(e: Exception) ->
|
82
|
+
def _serialize_exception(e: Exception) -> dict[str, str]:
|
84
83
|
return {"msg": str(e), "type": str(type(e)), **e.__dict__}
|
@@ -1,22 +1,47 @@
|
|
1
1
|
"""custom type hints"""
|
2
2
|
from enum import Enum
|
3
|
-
from typing import TypedDict
|
3
|
+
from typing import TypedDict, NewType
|
4
4
|
|
5
5
|
from PIL.Image import Image
|
6
6
|
from numpy import ndarray
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
class DictStrInt(dict[str, int]): pass
|
10
|
+
|
11
|
+
|
12
|
+
class DictStr(dict[str]): pass
|
13
|
+
|
14
|
+
|
15
|
+
class DictStrAny(dict[str, any]): pass
|
16
|
+
|
17
|
+
|
18
|
+
class ListDict(list[dict]): pass
|
19
|
+
|
20
|
+
|
21
|
+
class ListFloat(list[float]): pass
|
22
|
+
|
23
|
+
|
24
|
+
class ListInt(list[int]): pass
|
25
|
+
|
26
|
+
|
27
|
+
class TupleInt(tuple[int]): pass
|
28
|
+
|
29
|
+
|
30
|
+
class TupleNdarrayInt(tuple[ndarray, int]): pass
|
31
|
+
|
32
|
+
|
33
|
+
class TupleNdarrayFloat(tuple[ndarray, float]): pass
|
34
|
+
|
35
|
+
|
36
|
+
class LlistFloat(ListFloat): pass
|
37
|
+
|
38
|
+
|
39
|
+
class TupleFloat(tuple[float]): pass
|
40
|
+
|
41
|
+
|
42
|
+
class TupleFloatAny(tuple[float, any]): pass
|
43
|
+
|
44
|
+
|
20
45
|
PIL_Image = Image
|
21
46
|
|
22
47
|
|
@@ -26,7 +51,7 @@ class StrEnum(str, Enum):
|
|
26
51
|
|
27
52
|
class EmbeddingImage(TypedDict):
|
28
53
|
image_embedding: ndarray
|
29
|
-
original_size:
|
54
|
+
original_size: TupleInt
|
30
55
|
transform_matrix: ndarray
|
31
56
|
|
32
57
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
samgis_core/__init__.py,sha256=1kFX8G22dxNz23J7uOYl-SMWOe4W1olssc-5zKAVwSc,351
|
2
2
|
samgis_core/__version__.py,sha256=x-8LeQkljky-ao1MyT98tSQE1xNvJp3LelqsAdCb9Og,94
|
3
3
|
samgis_core/prediction_api/__init__.py,sha256=_jUZhspS26ygiSzBJywfZ4fQf9X7oC8w6oxvhd9S2hQ,57
|
4
|
-
samgis_core/prediction_api/sam_onnx.py,sha256=
|
4
|
+
samgis_core/prediction_api/sam_onnx.py,sha256=YEX6UOFKcqPiuF_SCPAcK_gCmxoj4lvTLNNDul2htZ8,15320
|
5
5
|
samgis_core/utilities/__init__.py,sha256=nL9pzdB4SdEF8m5gCbtlVCtdGLg9JjPm-FNxKBsIBZA,32
|
6
6
|
samgis_core/utilities/constants.py,sha256=645W57jrUNbnujgUwCietfr-rECENDXLGmHeD2YoSwg,157
|
7
7
|
samgis_core/utilities/fastapi_logger.py,sha256=yt8Vj1viyE-Kry1_iy5p4saZvGEEmRfuTEMHYXgnjqk,650
|
8
|
-
samgis_core/utilities/serialize.py,sha256=
|
9
|
-
samgis_core/utilities/type_hints.py,sha256=
|
8
|
+
samgis_core/utilities/serialize.py,sha256=aIjhEoibBpV_gpgOg6LiVxZCWjOkYxlzcboDZLQctJE,2689
|
9
|
+
samgis_core/utilities/type_hints.py,sha256=iDkWiVB2B0W_GaRhdpypEra2FvQtwC5lNLVZr7a4yhU,845
|
10
10
|
samgis_core/utilities/utilities.py,sha256=fP3cnxIYULYoCBft54EAivUR_fMcCDz2Z9AMpAO0zZ0,2434
|
11
|
-
samgis_core-1.1.
|
12
|
-
samgis_core-1.1.
|
13
|
-
samgis_core-1.1.
|
11
|
+
samgis_core-1.1.2.dist-info/METADATA,sha256=KcYx7_-LSImFjrPf1EKBqpCPrE4Vxy2g6IqcHicUPjw,892
|
12
|
+
samgis_core-1.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
13
|
+
samgis_core-1.1.2.dist-info/RECORD,,
|
File without changes
|