inference-models 0.18.3__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.
- inference_models/__init__.py +36 -0
- inference_models/configuration.py +72 -0
- inference_models/constants.py +2 -0
- inference_models/entities.py +5 -0
- inference_models/errors.py +137 -0
- inference_models/logger.py +52 -0
- inference_models/model_pipelines/__init__.py +0 -0
- inference_models/model_pipelines/auto_loaders/__init__.py +0 -0
- inference_models/model_pipelines/auto_loaders/core.py +120 -0
- inference_models/model_pipelines/auto_loaders/pipelines_registry.py +36 -0
- inference_models/model_pipelines/face_and_gaze_detection/__init__.py +0 -0
- inference_models/model_pipelines/face_and_gaze_detection/mediapipe_l2cs.py +200 -0
- inference_models/models/__init__.py +0 -0
- inference_models/models/auto_loaders/__init__.py +0 -0
- inference_models/models/auto_loaders/access_manager.py +168 -0
- inference_models/models/auto_loaders/auto_negotiation.py +1329 -0
- inference_models/models/auto_loaders/auto_resolution_cache.py +129 -0
- inference_models/models/auto_loaders/constants.py +7 -0
- inference_models/models/auto_loaders/core.py +1341 -0
- inference_models/models/auto_loaders/dependency_models.py +52 -0
- inference_models/models/auto_loaders/entities.py +57 -0
- inference_models/models/auto_loaders/models_registry.py +497 -0
- inference_models/models/auto_loaders/presentation_utils.py +333 -0
- inference_models/models/auto_loaders/ranking.py +413 -0
- inference_models/models/auto_loaders/utils.py +31 -0
- inference_models/models/base/__init__.py +0 -0
- inference_models/models/base/classification.py +123 -0
- inference_models/models/base/depth_estimation.py +62 -0
- inference_models/models/base/documents_parsing.py +111 -0
- inference_models/models/base/embeddings.py +66 -0
- inference_models/models/base/instance_segmentation.py +87 -0
- inference_models/models/base/keypoints_detection.py +93 -0
- inference_models/models/base/object_detection.py +143 -0
- inference_models/models/base/semantic_segmentation.py +74 -0
- inference_models/models/base/types.py +5 -0
- inference_models/models/clip/__init__.py +0 -0
- inference_models/models/clip/clip_onnx.py +148 -0
- inference_models/models/clip/clip_pytorch.py +104 -0
- inference_models/models/clip/preprocessing.py +162 -0
- inference_models/models/common/__init__.py +0 -0
- inference_models/models/common/cuda.py +30 -0
- inference_models/models/common/model_packages.py +25 -0
- inference_models/models/common/onnx.py +379 -0
- inference_models/models/common/roboflow/__init__.py +0 -0
- inference_models/models/common/roboflow/model_packages.py +361 -0
- inference_models/models/common/roboflow/post_processing.py +436 -0
- inference_models/models/common/roboflow/pre_processing.py +1332 -0
- inference_models/models/common/torch.py +20 -0
- inference_models/models/common/trt.py +266 -0
- inference_models/models/deep_lab_v3_plus/__init__.py +0 -0
- inference_models/models/deep_lab_v3_plus/deep_lab_v3_plus_segmentation_onnx.py +282 -0
- inference_models/models/deep_lab_v3_plus/deep_lab_v3_plus_segmentation_torch.py +264 -0
- inference_models/models/deep_lab_v3_plus/deep_lab_v3_plus_segmentation_trt.py +313 -0
- inference_models/models/depth_anything_v2/__init__.py +0 -0
- inference_models/models/depth_anything_v2/depth_anything_v2_hf.py +77 -0
- inference_models/models/dinov3/__init__.py +0 -0
- inference_models/models/dinov3/dinov3_classification_onnx.py +348 -0
- inference_models/models/dinov3/dinov3_classification_torch.py +323 -0
- inference_models/models/doctr/__init__.py +0 -0
- inference_models/models/doctr/doctr_torch.py +304 -0
- inference_models/models/easy_ocr/__init__.py +0 -0
- inference_models/models/easy_ocr/easy_ocr_torch.py +222 -0
- inference_models/models/florence2/__init__.py +0 -0
- inference_models/models/florence2/florence2_hf.py +897 -0
- inference_models/models/grounding_dino/__init__.py +0 -0
- inference_models/models/grounding_dino/grounding_dino_torch.py +227 -0
- inference_models/models/l2cs/__init__.py +0 -0
- inference_models/models/l2cs/l2cs_onnx.py +216 -0
- inference_models/models/mediapipe_face_detection/__init__.py +0 -0
- inference_models/models/mediapipe_face_detection/face_detection.py +203 -0
- inference_models/models/moondream2/__init__.py +0 -0
- inference_models/models/moondream2/moondream2_hf.py +281 -0
- inference_models/models/owlv2/__init__.py +0 -0
- inference_models/models/owlv2/cache.py +182 -0
- inference_models/models/owlv2/entities.py +112 -0
- inference_models/models/owlv2/owlv2_hf.py +695 -0
- inference_models/models/owlv2/reference_dataset.py +291 -0
- inference_models/models/paligemma/__init__.py +0 -0
- inference_models/models/paligemma/paligemma_hf.py +209 -0
- inference_models/models/perception_encoder/__init__.py +0 -0
- inference_models/models/perception_encoder/perception_encoder_pytorch.py +197 -0
- inference_models/models/perception_encoder/vision_encoder/__init__.py +0 -0
- inference_models/models/perception_encoder/vision_encoder/config.py +160 -0
- inference_models/models/perception_encoder/vision_encoder/pe.py +742 -0
- inference_models/models/perception_encoder/vision_encoder/rope.py +344 -0
- inference_models/models/perception_encoder/vision_encoder/tokenizer.py +342 -0
- inference_models/models/perception_encoder/vision_encoder/transforms.py +33 -0
- inference_models/models/qwen25vl/__init__.py +1 -0
- inference_models/models/qwen25vl/qwen25vl_hf.py +285 -0
- inference_models/models/resnet/__init__.py +0 -0
- inference_models/models/resnet/resnet_classification_onnx.py +330 -0
- inference_models/models/resnet/resnet_classification_torch.py +305 -0
- inference_models/models/resnet/resnet_classification_trt.py +369 -0
- inference_models/models/rfdetr/__init__.py +0 -0
- inference_models/models/rfdetr/backbone_builder.py +101 -0
- inference_models/models/rfdetr/class_remapping.py +41 -0
- inference_models/models/rfdetr/common.py +115 -0
- inference_models/models/rfdetr/default_labels.py +108 -0
- inference_models/models/rfdetr/dinov2_with_windowed_attn.py +1330 -0
- inference_models/models/rfdetr/misc.py +26 -0
- inference_models/models/rfdetr/ms_deform_attn.py +180 -0
- inference_models/models/rfdetr/ms_deform_attn_func.py +60 -0
- inference_models/models/rfdetr/position_encoding.py +166 -0
- inference_models/models/rfdetr/post_processor.py +83 -0
- inference_models/models/rfdetr/projector.py +373 -0
- inference_models/models/rfdetr/rfdetr_backbone_pytorch.py +394 -0
- inference_models/models/rfdetr/rfdetr_base_pytorch.py +807 -0
- inference_models/models/rfdetr/rfdetr_instance_segmentation_onnx.py +206 -0
- inference_models/models/rfdetr/rfdetr_instance_segmentation_pytorch.py +373 -0
- inference_models/models/rfdetr/rfdetr_instance_segmentation_trt.py +227 -0
- inference_models/models/rfdetr/rfdetr_object_detection_onnx.py +244 -0
- inference_models/models/rfdetr/rfdetr_object_detection_pytorch.py +470 -0
- inference_models/models/rfdetr/rfdetr_object_detection_trt.py +270 -0
- inference_models/models/rfdetr/segmentation_head.py +273 -0
- inference_models/models/rfdetr/transformer.py +767 -0
- inference_models/models/roboflow_instant/__init__.py +0 -0
- inference_models/models/roboflow_instant/roboflow_instant_hf.py +141 -0
- inference_models/models/sam/__init__.py +0 -0
- inference_models/models/sam/cache.py +147 -0
- inference_models/models/sam/entities.py +25 -0
- inference_models/models/sam/sam_torch.py +675 -0
- inference_models/models/sam2/__init__.py +0 -0
- inference_models/models/sam2/cache.py +162 -0
- inference_models/models/sam2/entities.py +43 -0
- inference_models/models/sam2/sam2_torch.py +905 -0
- inference_models/models/sam2_rt/__init__.py +0 -0
- inference_models/models/sam2_rt/sam2_pytorch.py +119 -0
- inference_models/models/smolvlm/__init__.py +0 -0
- inference_models/models/smolvlm/smolvlm_hf.py +245 -0
- inference_models/models/trocr/__init__.py +0 -0
- inference_models/models/trocr/trocr_hf.py +53 -0
- inference_models/models/vit/__init__.py +0 -0
- inference_models/models/vit/vit_classification_huggingface.py +319 -0
- inference_models/models/vit/vit_classification_onnx.py +326 -0
- inference_models/models/vit/vit_classification_trt.py +365 -0
- inference_models/models/yolact/__init__.py +1 -0
- inference_models/models/yolact/yolact_instance_segmentation_onnx.py +336 -0
- inference_models/models/yolact/yolact_instance_segmentation_trt.py +361 -0
- inference_models/models/yolo_world/__init__.py +1 -0
- inference_models/models/yolonas/__init__.py +0 -0
- inference_models/models/yolonas/nms.py +44 -0
- inference_models/models/yolonas/yolonas_object_detection_onnx.py +204 -0
- inference_models/models/yolonas/yolonas_object_detection_trt.py +230 -0
- inference_models/models/yolov10/__init__.py +0 -0
- inference_models/models/yolov10/yolov10_object_detection_onnx.py +187 -0
- inference_models/models/yolov10/yolov10_object_detection_trt.py +215 -0
- inference_models/models/yolov11/__init__.py +0 -0
- inference_models/models/yolov11/yolov11_onnx.py +28 -0
- inference_models/models/yolov11/yolov11_torch_script.py +25 -0
- inference_models/models/yolov11/yolov11_trt.py +21 -0
- inference_models/models/yolov12/__init__.py +0 -0
- inference_models/models/yolov12/yolov12_onnx.py +7 -0
- inference_models/models/yolov12/yolov12_torch_script.py +7 -0
- inference_models/models/yolov12/yolov12_trt.py +7 -0
- inference_models/models/yolov5/__init__.py +0 -0
- inference_models/models/yolov5/nms.py +99 -0
- inference_models/models/yolov5/yolov5_instance_segmentation_onnx.py +225 -0
- inference_models/models/yolov5/yolov5_instance_segmentation_trt.py +255 -0
- inference_models/models/yolov5/yolov5_object_detection_onnx.py +192 -0
- inference_models/models/yolov5/yolov5_object_detection_trt.py +218 -0
- inference_models/models/yolov7/__init__.py +0 -0
- inference_models/models/yolov7/yolov7_instance_segmentation_onnx.py +226 -0
- inference_models/models/yolov7/yolov7_instance_segmentation_trt.py +253 -0
- inference_models/models/yolov8/__init__.py +0 -0
- inference_models/models/yolov8/yolov8_classification_onnx.py +181 -0
- inference_models/models/yolov8/yolov8_instance_segmentation_onnx.py +239 -0
- inference_models/models/yolov8/yolov8_instance_segmentation_torch_script.py +201 -0
- inference_models/models/yolov8/yolov8_instance_segmentation_trt.py +268 -0
- inference_models/models/yolov8/yolov8_key_points_detection_onnx.py +263 -0
- inference_models/models/yolov8/yolov8_key_points_detection_torch_script.py +218 -0
- inference_models/models/yolov8/yolov8_key_points_detection_trt.py +287 -0
- inference_models/models/yolov8/yolov8_object_detection_onnx.py +213 -0
- inference_models/models/yolov8/yolov8_object_detection_torch_script.py +166 -0
- inference_models/models/yolov8/yolov8_object_detection_trt.py +231 -0
- inference_models/models/yolov9/__init__.py +0 -0
- inference_models/models/yolov9/yolov9_onnx.py +7 -0
- inference_models/models/yolov9/yolov9_torch_script.py +7 -0
- inference_models/models/yolov9/yolov9_trt.py +7 -0
- inference_models/runtime_introspection/__init__.py +0 -0
- inference_models/runtime_introspection/core.py +410 -0
- inference_models/utils/__init__.py +0 -0
- inference_models/utils/download.py +608 -0
- inference_models/utils/environment.py +28 -0
- inference_models/utils/file_system.py +51 -0
- inference_models/utils/hashing.py +7 -0
- inference_models/utils/imports.py +48 -0
- inference_models/utils/onnx_introspection.py +17 -0
- inference_models/weights_providers/__init__.py +0 -0
- inference_models/weights_providers/core.py +20 -0
- inference_models/weights_providers/entities.py +159 -0
- inference_models/weights_providers/roboflow.py +601 -0
- inference_models-0.18.3.dist-info/METADATA +466 -0
- inference_models-0.18.3.dist-info/RECORD +195 -0
- inference_models-0.18.3.dist-info/WHEEL +5 -0
- inference_models-0.18.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from collections import OrderedDict, defaultdict
|
|
3
|
+
from threading import Lock
|
|
4
|
+
from typing import DefaultDict, List, Optional
|
|
5
|
+
|
|
6
|
+
import torch
|
|
7
|
+
|
|
8
|
+
from inference_models.errors import EnvironmentConfigurationError
|
|
9
|
+
from inference_models.models.sam2.entities import (
|
|
10
|
+
SAM2ImageEmbeddings,
|
|
11
|
+
SAM2MaskCacheEntry,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Sam2ImageEmbeddingsCache(ABC):
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def retrieve_embeddings(self, key: str) -> Optional[SAM2ImageEmbeddings]:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def save_embeddings(self, key: str, embeddings: SAM2ImageEmbeddings) -> None:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Sam2ImageEmbeddingsCacheNullObject(Sam2ImageEmbeddingsCache):
|
|
27
|
+
|
|
28
|
+
def retrieve_embeddings(self, key: str) -> Optional[SAM2ImageEmbeddings]:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
def save_embeddings(self, key: str, embeddings: SAM2ImageEmbeddings) -> None:
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Sam2ImageEmbeddingsInMemoryCache(Sam2ImageEmbeddingsCache):
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def init(
|
|
39
|
+
cls, size_limit: Optional[int], send_to_cpu: bool = True
|
|
40
|
+
) -> "Sam2ImageEmbeddingsInMemoryCache":
|
|
41
|
+
return cls(
|
|
42
|
+
state=OrderedDict(),
|
|
43
|
+
size_limit=size_limit,
|
|
44
|
+
send_to_cpu=send_to_cpu,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
state: OrderedDict,
|
|
50
|
+
size_limit: Optional[int],
|
|
51
|
+
send_to_cpu: bool = True,
|
|
52
|
+
):
|
|
53
|
+
self._state = state
|
|
54
|
+
self._size_limit = size_limit
|
|
55
|
+
self._send_to_cpu = send_to_cpu
|
|
56
|
+
self._state_lock = Lock()
|
|
57
|
+
|
|
58
|
+
def retrieve_embeddings(self, key: str) -> Optional[SAM2ImageEmbeddings]:
|
|
59
|
+
return self._state.get(key)
|
|
60
|
+
|
|
61
|
+
def save_embeddings(self, key: str, embeddings: SAM2ImageEmbeddings) -> None:
|
|
62
|
+
with self._state_lock:
|
|
63
|
+
if key in self._state:
|
|
64
|
+
return None
|
|
65
|
+
self._ensure_cache_has_capacity()
|
|
66
|
+
if self._send_to_cpu:
|
|
67
|
+
embeddings = embeddings.to(device=torch.device("cpu"))
|
|
68
|
+
self._state[key] = embeddings
|
|
69
|
+
|
|
70
|
+
def _ensure_cache_has_capacity(self) -> None:
|
|
71
|
+
if self._size_limit < 1:
|
|
72
|
+
raise EnvironmentConfigurationError(
|
|
73
|
+
message=f"In memory cache size for SAM2 embeddings was set to invalid value. "
|
|
74
|
+
f"If you are running inference locally - adjust settings of your deployment. If you see this "
|
|
75
|
+
f"error running on Roboflow platform - contact us to get help.",
|
|
76
|
+
help_url="https://todo",
|
|
77
|
+
)
|
|
78
|
+
if self._size_limit is None or self._size_limit < 1:
|
|
79
|
+
return None
|
|
80
|
+
while len(self._state) > self._size_limit:
|
|
81
|
+
_ = self._state.popitem(last=False)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class Sam2LowResolutionMasksCache(ABC):
|
|
85
|
+
|
|
86
|
+
@abstractmethod
|
|
87
|
+
def retrieve_all_masks_for_image(self, key: str) -> List[SAM2MaskCacheEntry]:
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def save_mask(self, key: str, mask: SAM2MaskCacheEntry) -> None:
|
|
92
|
+
pass
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Sam2LowResolutionMasksCacheNullObject(Sam2LowResolutionMasksCache):
|
|
96
|
+
|
|
97
|
+
def retrieve_all_masks_for_image(self, key: str) -> List[SAM2MaskCacheEntry]:
|
|
98
|
+
return []
|
|
99
|
+
|
|
100
|
+
def save_mask(self, key: str, mask: SAM2MaskCacheEntry) -> None:
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Sam2LowResolutionMasksInMemoryCache(Sam2LowResolutionMasksCache):
|
|
105
|
+
|
|
106
|
+
@classmethod
|
|
107
|
+
def init(
|
|
108
|
+
cls, size_limit: Optional[int], send_to_cpu: bool = True
|
|
109
|
+
) -> "Sam2LowResolutionMasksInMemoryCache":
|
|
110
|
+
return cls(
|
|
111
|
+
ordering_state=OrderedDict(),
|
|
112
|
+
cache_state=defaultdict(list),
|
|
113
|
+
size_limit=size_limit,
|
|
114
|
+
send_to_cpu=send_to_cpu,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def __init__(
|
|
118
|
+
self,
|
|
119
|
+
ordering_state: OrderedDict,
|
|
120
|
+
cache_state: DefaultDict[str, List[SAM2MaskCacheEntry]],
|
|
121
|
+
size_limit: Optional[int],
|
|
122
|
+
send_to_cpu: bool = True,
|
|
123
|
+
):
|
|
124
|
+
self._ordering_state = ordering_state
|
|
125
|
+
self._cache_state = cache_state
|
|
126
|
+
self._size_limit = size_limit
|
|
127
|
+
self._send_to_cpu = send_to_cpu
|
|
128
|
+
self._state_lock = Lock()
|
|
129
|
+
|
|
130
|
+
def retrieve_all_masks_for_image(self, key: str) -> List[SAM2MaskCacheEntry]:
|
|
131
|
+
return self._cache_state.get(key, [])
|
|
132
|
+
|
|
133
|
+
def save_mask(self, key: str, mask: SAM2MaskCacheEntry) -> None:
|
|
134
|
+
with self._state_lock:
|
|
135
|
+
if (key, mask.prompt_hash) in self._ordering_state:
|
|
136
|
+
return None
|
|
137
|
+
self._ensure_cache_has_capacity()
|
|
138
|
+
if self._send_to_cpu:
|
|
139
|
+
mask = mask.to(device=torch.device("cpu"))
|
|
140
|
+
self._ordering_state[(key, mask.prompt_hash)] = True
|
|
141
|
+
self._cache_state[key].append(mask)
|
|
142
|
+
|
|
143
|
+
def _ensure_cache_has_capacity(self) -> None:
|
|
144
|
+
if self._size_limit < 1:
|
|
145
|
+
raise EnvironmentConfigurationError(
|
|
146
|
+
message=f"In memory cache size for SAM embeddings was set to invalid value. "
|
|
147
|
+
f"If you are running inference locally - adjust settings of your deployment. If you see this "
|
|
148
|
+
f"error running on Roboflow platform - contact us to get help.",
|
|
149
|
+
help_url="https://todo",
|
|
150
|
+
)
|
|
151
|
+
if self._size_limit is None or self._size_limit < 1:
|
|
152
|
+
return None
|
|
153
|
+
while len(self._ordering_state) > self._size_limit:
|
|
154
|
+
image_key, prompt_hash = self._ordering_state.popitem(last=False)
|
|
155
|
+
entries_for_image = self._cache_state[image_key]
|
|
156
|
+
to_remove_idx = None
|
|
157
|
+
for i, element in enumerate(entries_for_image):
|
|
158
|
+
if element.prompt_hash == prompt_hash:
|
|
159
|
+
to_remove_idx = i
|
|
160
|
+
break
|
|
161
|
+
if to_remove_idx is not None:
|
|
162
|
+
del entries_for_image[to_remove_idx]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import List, Tuple
|
|
3
|
+
|
|
4
|
+
import torch
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class SAM2ImageEmbeddings:
|
|
9
|
+
image_hash: str
|
|
10
|
+
image_size_hw: Tuple[int, int]
|
|
11
|
+
embeddings: torch.Tensor
|
|
12
|
+
high_resolution_features: List[torch.Tensor]
|
|
13
|
+
|
|
14
|
+
def to(self, device: torch.device) -> "SAM2ImageEmbeddings":
|
|
15
|
+
return SAM2ImageEmbeddings(
|
|
16
|
+
image_hash=self.image_hash,
|
|
17
|
+
image_size_hw=self.image_size_hw,
|
|
18
|
+
embeddings=self.embeddings.to(device=device),
|
|
19
|
+
high_resolution_features=[
|
|
20
|
+
f.to(device=device) for f in self.high_resolution_features
|
|
21
|
+
],
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class SAM2Prediction:
|
|
27
|
+
masks: torch.Tensor
|
|
28
|
+
scores: torch.Tensor
|
|
29
|
+
logits: torch.Tensor
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class SAM2MaskCacheEntry:
|
|
34
|
+
prompt_hash: str
|
|
35
|
+
serialized_prompt: List[dict]
|
|
36
|
+
mask: torch.Tensor
|
|
37
|
+
|
|
38
|
+
def to(self, device: torch.device) -> "SAM2MaskCacheEntry":
|
|
39
|
+
return SAM2MaskCacheEntry(
|
|
40
|
+
prompt_hash=self.prompt_hash,
|
|
41
|
+
serialized_prompt=self.serialized_prompt,
|
|
42
|
+
mask=self.mask.to(device=device),
|
|
43
|
+
)
|