inference API Reference¶
core/active_learning¶
Active learning loop: sampling strategies, data collection middleware, and configuration.
inference.core.active_learning.accounting
¶
Functions¶
get_images_in_labeling_jobs_of_specific_batch
¶
get_images_in_labeling_jobs_of_specific_batch(
all_labeling_jobs, batch_id
)
Get the number of images in labeling jobs of a specific batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_labeling_jobs
|
List[dict]
|
All labeling jobs. |
required |
batch_id
|
str
|
ID of the batch. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of images in labeling jobs of the batch. |
Source code in inference/core/active_learning/accounting.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
get_matching_labeling_batch
¶
get_matching_labeling_batch(
all_labeling_batches, batch_name
)
Get the matching labeling batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_labeling_batches
|
List[dict]
|
All labeling batches. |
required |
batch_name
|
str
|
Name of the batch. |
required |
Returns:
| Type | Description |
|---|---|
Optional[dict]
|
The matching labeling batch if found, None otherwise. |
Source code in inference/core/active_learning/accounting.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
image_can_be_submitted_to_batch
¶
image_can_be_submitted_to_batch(
batch_name,
workspace_id,
dataset_id,
max_batch_images,
api_key,
)
Check if an image can be submitted to a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_name
|
str
|
Name of the batch. |
required |
workspace_id
|
WorkspaceID
|
ID of the workspace. |
required |
dataset_id
|
DatasetID
|
ID of the dataset. |
required |
max_batch_images
|
Optional[int]
|
Maximum number of images allowed in the batch. |
required |
api_key
|
str
|
API key to use for the request. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the image can be submitted to the batch, False otherwise. |
Source code in inference/core/active_learning/accounting.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
inference.core.active_learning.configuration
¶
Classes¶
Functions¶
predictions_incompatible_with_dataset
¶
predictions_incompatible_with_dataset(
model_type, dataset_type
)
The incompatibility occurs when we mix classification with detection - as detection-based predictions are partially compatible (for instance - for key-points detection we may register bboxes from object detection and manually provide key-points annotations)
Source code in inference/core/active_learning/configuration.py
203 204 205 206 207 208 209 210 211 212 213 214 | |
core/cache¶
Caching backends (in-memory, Redis) used for model artefacts and inference results.
inference.core.cache.base
¶
Classes¶
BaseCache
¶
BaseCache is an abstract base class that defines the interface for a cache.
Source code in inference/core/cache/base.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Functions¶
get
¶
get(key)
Gets the value associated with the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve the value. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
14 15 16 17 18 19 20 21 22 23 24 | |
get_numpy
¶
get_numpy(key)
Retrieves a numpy array from the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the value to retrieve. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
126 127 128 129 130 131 132 133 134 135 136 | |
set
¶
set(key, value, expire=None)
Sets a value for a given key with an optional expire time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to store the value. |
required |
value
|
str
|
The value to store. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
set_numpy
¶
set_numpy(key, value, expire=None)
Caches a numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to store the value. |
required |
value
|
Any
|
The value to store. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
zadd
¶
zadd(key, value, score, expire=None)
Adds a member with the specified score to the sorted set stored at key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
value
|
str
|
The value to add to the sorted set. |
required |
score
|
float
|
The score associated with the value. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
zrangebyscore
¶
zrangebyscore(
key, min=-1, max=float("inf"), withscores=False
)
Retrieves a range of members from a sorted set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
start
|
int
|
The starting index of the range. Defaults to -1. |
required |
stop
|
int
|
The ending index of the range. Defaults to float("inf"). |
required |
withscores
|
bool
|
Whether to return the scores along with the values. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
zremrangebyscore
¶
zremrangebyscore(key, start=-1, stop=float('inf'))
Removes all members in a sorted set within the given scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
start
|
int
|
The minimum score of the range. Defaults to -1. |
-1
|
stop
|
int
|
The maximum score of the range. Defaults to float("inf"). |
float('inf')
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by subclasses. |
Source code in inference/core/cache/base.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
inference.core.cache.memory
¶
Classes¶
MemoryCache
¶
Bases: BaseCache
MemoryCache is an in-memory cache that implements the BaseCache interface.
Attributes:
| Name | Type | Description |
|---|---|---|
cache |
dict
|
A dictionary to store the cache values. |
expires |
dict
|
A dictionary to store the expiration times of the cache values. |
zexpires |
dict
|
A dictionary to store the expiration times of the sorted set values. |
_expire_thread |
Thread
|
A thread that runs the _expire method. |
Source code in inference/core/cache/memory.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
Functions¶
__init__
¶
__init__()
Initializes a new instance of the MemoryCache class.
Source code in inference/core/cache/memory.py
21 22 23 24 25 26 27 28 29 30 31 | |
get
¶
get(key)
Gets the value associated with the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve the value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The value associated with the key, or None if the key does not exist or is expired. |
Source code in inference/core/cache/memory.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
set
¶
set(key, value, expire=None)
Sets a value for a given key with an optional expire time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to store the value. |
required |
value
|
str
|
The value to store. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Source code in inference/core/cache/memory.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
zadd
¶
zadd(key, value, score, expire=None)
Adds a member with the specified score to the sorted set stored at key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
value
|
str
|
The value to add to the sorted set. |
required |
score
|
float
|
The score associated with the value. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Source code in inference/core/cache/memory.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
zrangebyscore
¶
zrangebyscore(
key, min=-1, max=float("inf"), withscores=False
)
Retrieves a range of members from a sorted set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
start
|
int
|
The starting score of the range. Defaults to -1. |
required |
stop
|
int
|
The ending score of the range. Defaults to float("inf"). |
required |
withscores
|
bool
|
Whether to return the scores along with the values. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of values (or value-score pairs if withscores is True) in the specified score range. |
Source code in inference/core/cache/memory.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
zremrangebyscore
¶
zremrangebyscore(key, min=-1, max=float('inf'))
Removes all members in a sorted set within the given scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
start
|
int
|
The minimum score of the range. Defaults to -1. |
required |
stop
|
int
|
The maximum score of the range. Defaults to float("inf"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The number of members removed from the sorted set. |
Source code in inference/core/cache/memory.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
inference.core.cache.model_artifacts
¶
Functions¶
clear_cache
¶
clear_cache(model_id=None, delete_from_disk=True)
Clear the cache for a specific model or the entire cache directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
Optional[str]
|
The model ID to clear cache for. If None, clears entire cache. Defaults to None. |
None
|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to False. |
True
|
Source code in inference/core/cache/model_artifacts.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
inference.core.cache.redis
¶
Classes¶
RedisCache
¶
Bases: BaseCache
MemoryCache is an in-memory cache that implements the BaseCache interface.
Attributes:
| Name | Type | Description |
|---|---|---|
cache |
dict
|
A dictionary to store the cache values. |
expires |
dict
|
A dictionary to store the expiration times of the cache values. |
zexpires |
dict
|
A dictionary to store the expiration times of the sorted set values. |
_expire_thread |
Thread
|
A thread that runs the _expire method. |
Source code in inference/core/cache/redis.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
Functions¶
__init__
¶
__init__(
host="localhost",
port=6379,
db=0,
ssl=False,
timeout=2.0,
)
Initializes a new instance of the MemoryCache class.
Source code in inference/core/cache/redis.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get
¶
get(key)
Gets the value associated with the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to retrieve the value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The value associated with the key, or None if the key does not exist or is expired. |
Source code in inference/core/cache/redis.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
set
¶
set(key, value, expire=None)
Sets a value for a given key with an optional expire time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to store the value. |
required |
value
|
str
|
The value to store. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Source code in inference/core/cache/redis.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
zadd
¶
zadd(key, value, score, expire=None)
Adds a member with the specified score to the sorted set stored at key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
value
|
str
|
The value to add to the sorted set. |
required |
score
|
float
|
The score associated with the value. |
required |
expire
|
float
|
The time, in seconds, after which the key will expire. Defaults to None. |
None
|
Source code in inference/core/cache/redis.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
zrangebyscore
¶
zrangebyscore(
key, min=-1, max=float("inf"), withscores=False
)
Retrieves a range of members from a sorted set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
start
|
int
|
The starting score of the range. Defaults to -1. |
required |
stop
|
int
|
The ending score of the range. Defaults to float("inf"). |
required |
withscores
|
bool
|
Whether to return the scores along with the values. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of values (or value-score pairs if withscores is True) in the specified score range. |
Source code in inference/core/cache/redis.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
zremrangebyscore
¶
zremrangebyscore(key, min=-1, max=float('inf'))
Removes all members in a sorted set within the given scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the sorted set. |
required |
start
|
int
|
The minimum score of the range. Defaults to -1. |
required |
stop
|
int
|
The maximum score of the range. Defaults to float("inf"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
The number of members removed from the sorted set. |
Source code in inference/core/cache/redis.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
core/devices¶
Hardware device detection and selection helpers.
inference.core.devices.utils
¶
Functions¶
get_cpu_id
¶
get_cpu_id()
Fetches the CPU ID based on the operating system.
Attempts to get the CPU ID for Windows, Linux, and MacOS. In case of any error or an unsupported OS, returns None.
Returns:
| Type | Description |
|---|---|
|
Optional[str]: CPU ID string if available, None otherwise. |
Source code in inference/core/devices/utils.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
get_device_hostname
¶
get_device_hostname()
Fetches the device's hostname.
Returns:
| Name | Type | Description |
|---|---|---|
str |
The device's hostname. |
Source code in inference/core/devices/utils.py
107 108 109 110 111 112 113 | |
get_gpu_id
¶
get_gpu_id()
Fetches the GPU ID if a GPU is present.
Tries to import and use the pynvml (delivered by nvidia-ml-py) module to retrieve the GPU information.
Returns:
| Type | Description |
|---|---|
|
Optional[int]: GPU ID if available, None otherwise. |
Source code in inference/core/devices/utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
get_inference_server_id
¶
get_inference_server_id()
Fetches a unique device ID.
Tries to get the GPU ID first, then falls back to CPU ID. If the application is running inside Docker, the Docker container ID is appended to the hostname.
Returns:
| Name | Type | Description |
|---|---|---|
str |
A unique string representing the device. If unable to determine, returns "UNKNOWN". |
Source code in inference/core/devices/utils.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
get_jetson_id
¶
get_jetson_id()
Fetches the Jetson device's serial number.
Attempts to read the serial number from the device tree. In case of any error, returns None.
Returns:
| Type | Description |
|---|---|
|
Optional[str]: Jetson device serial number if available, None otherwise. |
Source code in inference/core/devices/utils.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
is_running_in_docker
¶
is_running_in_docker()
Checks if the current process is running inside a Docker container.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if running inside a Docker container, False otherwise. |
Source code in inference/core/devices/utils.py
10 11 12 13 14 15 16 | |
core/entities/requests¶
inference.core.entities.requests.clip
¶
Classes¶
ClipCompareRequest
¶
Bases: ClipInferenceRequest
Request for CLIP comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
subject |
Union[InferenceRequestImage, str]
|
The type of image data provided, one of 'url' or 'base64'. |
subject_type |
str
|
The type of subject, one of 'image' or 'text'. |
prompt |
Union[List[InferenceRequestImage], InferenceRequestImage, str, List[str], Dict[str, Union[InferenceRequestImage, str]]]
|
The prompt for comparison. |
prompt_type |
str
|
The type of prompt, one of 'image' or 'text'. |
Source code in inference/core/entities/requests/clip.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
ClipImageEmbeddingRequest
¶
Bases: ClipInferenceRequest
Request for CLIP image embedding.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Union[List[InferenceRequestImage], InferenceRequestImage]
|
Image(s) to be embedded. |
Source code in inference/core/entities/requests/clip.py
38 39 40 41 42 43 44 45 | |
ClipInferenceRequest
¶
Bases: BaseRequest
Request for CLIP inference.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
clip_version_id |
Optional[str]
|
The version ID of CLIP to be used for this request. |
Source code in inference/core/entities/requests/clip.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
ClipTextEmbeddingRequest
¶
Bases: ClipInferenceRequest
Request for CLIP text embedding.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
Union[List[str], str]
|
A string or list of strings. |
Source code in inference/core/entities/requests/clip.py
48 49 50 51 52 53 54 55 56 57 58 | |
inference.core.entities.requests.doctr
¶
Classes¶
DoctrOCRInferenceRequest
¶
Bases: BaseRequest
DocTR inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
Source code in inference/core/entities/requests/doctr.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
inference.core.entities.requests.dynamic_class_base
¶
Classes¶
DynamicClassBaseInferenceRequest
¶
Bases: CVInferenceRequest
Request for zero-shot object detection models (with dynamic class lists).
Attributes:
| Name | Type | Description |
|---|---|---|
text |
List[str]
|
A list of strings. |
Source code in inference/core/entities/requests/dynamic_class_base.py
8 9 10 11 12 13 14 15 16 17 18 19 | |
inference.core.entities.requests.easy_ocr
¶
Classes¶
EasyOCRInferenceRequest
¶
Bases: BaseRequest
EasyOCR inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
Source code in inference/core/entities/requests/easy_ocr.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
inference.core.entities.requests.gaze
¶
Classes¶
GazeDetectionInferenceRequest
¶
Bases: BaseRequest
Request for gaze detection inference.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
gaze_version_id |
Optional[str]
|
The version ID of Gaze to be used for this request. |
do_run_face_detection |
Optional[bool]
|
If true, face detection will be applied; if false, face detection will be ignored and the whole input image will be used for gaze detection. |
image |
Union[List[InferenceRequestImage], InferenceRequestImage]
|
Image(s) for inference. |
Source code in inference/core/entities/requests/gaze.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
inference.core.entities.requests.groundingdino
¶
Classes¶
GroundingDINOInferenceRequest
¶
Bases: DynamicClassBaseInferenceRequest
Request for Grounding DINO zero-shot predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
List[str]
|
A list of strings. |
Source code in inference/core/entities/requests/groundingdino.py
9 10 11 12 13 14 15 16 17 18 19 | |
inference.core.entities.requests.inference
¶
Classes¶
BaseRequest
¶
Bases: BaseModel
Base request for inference.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str_
|
A unique request identifier. |
api_key |
Optional[str]
|
Roboflow API Key that will be passed to the model during initialization for artifact retrieval. |
start |
Optional[float]
|
start time of request |
disable_model_monitoring |
Optional[bool]
|
If true, disables model monitoring for this request. |
Source code in inference/core/entities/requests/inference.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
CVInferenceRequest
¶
Bases: InferenceRequest
Computer Vision inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Union[List[InferenceRequestImage], InferenceRequestImage]
|
Image(s) for inference. |
disable_preproc_auto_orient |
Optional[bool]
|
If true, the auto orient preprocessing step is disabled for this call. Default is False. |
disable_preproc_contrast |
Optional[bool]
|
If true, the auto contrast preprocessing step is disabled for this call. Default is False. |
disable_preproc_grayscale |
Optional[bool]
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
disable_preproc_static_crop |
Optional[bool]
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
Source code in inference/core/entities/requests/inference.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
ClassificationInferenceRequest
¶
Bases: CVInferenceRequest
Classification inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
confidence |
Optional[float]
|
The confidence threshold used to filter out predictions. |
visualization_stroke_width |
Optional[int]
|
The stroke width used when visualizing predictions. |
visualize_predictions |
Optional[bool]
|
If true, the predictions will be drawn on the original image and returned as a base64 string. |
Source code in inference/core/entities/requests/inference.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
DepthEstimationRequest
¶
Bases: InferenceRequest
Request for depth estimation.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Union[List[InferenceRequestImage], InferenceRequestImage]
|
Image(s) to be estimated. |
model_id |
str
|
The model ID to use for depth estimation. |
depth_version_id |
Optional[str]
|
The version ID of the depth estimation model. |
Source code in inference/core/entities/requests/inference.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
InferenceRequest
¶
Bases: BaseRequest
Base request for inference.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
A unique model identifier. |
model_type |
Optional[str]
|
The type of the model, usually referring to what task the model performs. |
Source code in inference/core/entities/requests/inference.py
35 36 37 38 39 40 41 42 43 44 | |
InferenceRequestImage
¶
Bases: BaseModel
Image data for inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
The type of image data provided, one of 'url', 'base64', or 'numpy'. |
value |
Optional[Any]
|
Image data corresponding to the image type. |
Source code in inference/core/entities/requests/inference.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
InstanceSegmentationInferenceRequest
¶
Bases: ObjectDetectionInferenceRequest
Instance Segmentation inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
mask_decode_mode |
Optional[str]
|
The mode used to decode instance segmentation masks, one of 'accurate', 'fast', 'tradeoff'. |
tradeoff_factor |
Optional[float]
|
The amount to tradeoff between 0='fast' and 1='accurate'. |
Source code in inference/core/entities/requests/inference.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
ObjectDetectionInferenceRequest
¶
Bases: CVInferenceRequest
Object Detection inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
class_agnostic_nms |
Optional[bool]
|
If true, NMS is applied to all detections at once, if false, NMS is applied per class. |
class_filter |
Optional[List[str]]
|
If provided, only predictions for the listed classes will be returned. |
confidence |
Optional[float]
|
The confidence threshold used to filter out predictions. |
fix_batch_size |
Optional[bool]
|
If true, the batch size will be fixed to the maximum batch size configured for this server. |
iou_threshold |
Optional[float]
|
The IoU threshold that must be met for a box pair to be considered duplicate during NMS. |
max_detections |
Optional[int]
|
The maximum number of detections that will be returned. |
max_candidates |
Optional[int]
|
The maximum number of candidate detections passed to NMS. |
visualization_labels |
Optional[bool]
|
If true, labels will be rendered on prediction visualizations. |
visualization_stroke_width |
Optional[int]
|
The stroke width used when visualizing predictions. |
visualize_predictions |
Optional[bool]
|
If true, the predictions will be drawn on the original image and returned as a base64 string. |
Source code in inference/core/entities/requests/inference.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
SemanticSegmentationInferenceRequest
¶
Bases: CVInferenceRequest
Semantic Segmentation inference request.
Source code in inference/core/entities/requests/inference.py
227 228 229 230 231 232 | |
Functions¶
request_from_type
¶
request_from_type(model_type, request_dict)
Uses original request id
Source code in inference/core/entities/requests/inference.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
inference.core.entities.requests.moondream2
¶
Classes¶
Moondream2InferenceRequest
¶
Bases: DynamicClassBaseInferenceRequest
Request for Moondream 2 zero-shot predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
List[str]
|
A list of strings. |
Source code in inference/core/entities/requests/moondream2.py
6 7 8 9 10 11 12 13 | |
inference.core.entities.requests.owlv2
¶
Classes¶
OwlV2InferenceRequest
¶
Bases: BaseRequest
Request for gaze detection inference.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
owlv2_version_id |
Optional[str]
|
The version ID of Gaze to be used for this request. |
image |
Union[List[InferenceRequestImage], InferenceRequestImage]
|
Image(s) for inference. |
training_data |
List[TrainingImage]
|
Training data to ground the model on |
confidence |
float
|
Confidence threshold to filter predictions by |
Source code in inference/core/entities/requests/owlv2.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
inference.core.entities.requests.perception_encoder
¶
Classes¶
PerceptionEncoderCompareRequest
¶
Bases: PerceptionEncoderInferenceRequest
Request for PERCEPTION_ENCODER comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
subject |
Union[InferenceRequestImage, str]
|
The type of image data provided, one of 'url' or 'base64'. |
subject_type |
str
|
The type of subject, one of 'image' or 'text'. |
prompt |
Union[List[InferenceRequestImage], InferenceRequestImage, str, List[str], Dict[str, Union[InferenceRequestImage, str]]]
|
The prompt for comparison. |
prompt_type |
str
|
The type of prompt, one of 'image' or 'text'. |
Source code in inference/core/entities/requests/perception_encoder.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
PerceptionEncoderImageEmbeddingRequest
¶
Bases: PerceptionEncoderInferenceRequest
Request for PERCEPTION_ENCODER image embedding.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Union[List[InferenceRequestImage], InferenceRequestImage]
|
Image(s) to be embedded. |
Source code in inference/core/entities/requests/perception_encoder.py
38 39 40 41 42 43 44 45 | |
PerceptionEncoderInferenceRequest
¶
Bases: BaseRequest
Request for PERCEPTION_ENCODER inference.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
clip_version_id |
Optional[str]
|
The version ID of PERCEPTION_ENCODER to be used for this request. |
Source code in inference/core/entities/requests/perception_encoder.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
PerceptionEncoderTextEmbeddingRequest
¶
Bases: PerceptionEncoderInferenceRequest
Request for PERCEPTION_ENCODER text embedding.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
Union[List[str], str]
|
A string or list of strings. |
Source code in inference/core/entities/requests/perception_encoder.py
48 49 50 51 52 53 54 55 56 57 58 | |
inference.core.entities.requests.sam
¶
Classes¶
SamEmbeddingRequest
¶
Bases: SamInferenceRequest
SAM embedding request.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Optional[InferenceRequestImage]
|
The image to be embedded. |
image_id |
Optional[str]
|
The ID of the image to be embedded used to cache the embedding. |
format |
Optional[str]
|
The format of the response. Must be one of json or binary. |
Source code in inference/core/entities/requests/sam.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
SamInferenceRequest
¶
Bases: BaseRequest
SAM inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
sam_version_id |
Optional[str]
|
The version ID of SAM to be used for this request. |
Source code in inference/core/entities/requests/sam.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
SamSegmentationRequest
¶
Bases: SamInferenceRequest
SAM segmentation request.
Attributes:
| Name | Type | Description |
|---|---|---|
embeddings |
Optional[Union[List[List[List[List[float]]]], Any]]
|
The embeddings to be decoded. |
embeddings_format |
Optional[str]
|
The format of the embeddings. |
format |
Optional[str]
|
The format of the response. |
image |
Optional[InferenceRequestImage]
|
The image to be segmented. |
image_id |
Optional[str]
|
The ID of the image to be segmented used to retrieve cached embeddings. |
has_mask_input |
Optional[bool]
|
Whether or not the request includes a mask input. |
mask_input |
Optional[Union[List[List[List[float]]], Any]]
|
The set of output masks. |
mask_input_format |
Optional[str]
|
The format of the mask input. |
orig_im_size |
Optional[List[int]]
|
The original size of the image used to generate the embeddings. |
point_coords |
Optional[List[List[float]]]
|
The coordinates of the interactive points used during decoding. |
point_labels |
Optional[List[float]]
|
The labels of the interactive points used during decoding. |
use_mask_input_cache |
Optional[bool]
|
Whether or not to use the mask input cache. |
Source code in inference/core/entities/requests/sam.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
inference.core.entities.requests.sam2
¶
Classes¶
Sam2EmbeddingRequest
¶
Bases: Sam2InferenceRequest
SAM embedding request.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Optional[InferenceRequestImage]
|
The image to be embedded. |
image_id |
Optional[str]
|
The ID of the image to be embedded used to cache the embedding. |
format |
Optional[str]
|
The format of the response. Must be one of json or binary. |
Source code in inference/core/entities/requests/sam2.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
Sam2InferenceRequest
¶
Bases: BaseRequest
SAM2 inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
sam2_version_id |
Optional[str]
|
The version ID of SAM2 to be used for this request. |
Source code in inference/core/entities/requests/sam2.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
Sam2SegmentationRequest
¶
Bases: Sam2InferenceRequest
SAM segmentation request.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
Optional[str]
|
The format of the response. |
image |
InferenceRequestImage
|
The image to be segmented. |
image_id |
Optional[str]
|
The ID of the image to be segmented used to retrieve cached embeddings. |
point_coords |
Optional[List[List[float]]]
|
The coordinates of the interactive points used during decoding. |
point_labels |
Optional[List[float]]
|
The labels of the interactive points used during decoding. |
Source code in inference/core/entities/requests/sam2.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
inference.core.entities.requests.sam3
¶
Classes¶
Sam3InferenceRequest
¶
Bases: BaseRequest
SAM3 inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
Optional[str]
|
The model ID to be used, typically |
Source code in inference/core/entities/requests/sam3.py
76 77 78 79 80 81 82 83 84 85 86 | |
Sam3Prompt
¶
Bases: BaseModel
Unified prompt that can contain text and/or geometry.
Absolute pixel coordinates are used for boxes. Labels accept 0/1 or booleans.
Source code in inference/core/entities/requests/sam3.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
inference.core.entities.requests.sam3_3d
¶
Classes¶
Sam3_3D_Objects_InferenceRequest
¶
Bases: BaseRequest
SAM3D inference request for 3D object generation.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
image |
InferenceRequestImage
|
The input image to be used for 3D generation. |
mask_input |
Any
|
Mask(s) in any supported format - polygon, binary mask, or RLE. |
Source code in inference/core/entities/requests/sam3_3d.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
inference.core.entities.requests.server_state
¶
Classes¶
AddModelRequest
¶
Bases: BaseModel
Request to add a model to the inference server.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
A unique model identifier. |
model_type |
Optional[str]
|
The type of the model, usually referring to what task the model performs. |
api_key |
Optional[str]
|
Roboflow API Key that will be passed to the model during initialization for artifact retrieval. |
Source code in inference/core/entities/requests/server_state.py
8 9 10 11 12 13 14 15 16 17 18 19 20 | |
ClearModelRequest
¶
Bases: BaseModel
Request to clear a model from the inference server.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
A unique model identifier. |
Source code in inference/core/entities/requests/server_state.py
23 24 25 26 27 28 29 30 31 | |
inference.core.entities.requests.trocr
¶
Classes¶
TrOCRInferenceRequest
¶
Bases: BaseRequest
TrOCR inference request.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Roboflow API Key. |
Source code in inference/core/entities/requests/trocr.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
inference.core.entities.requests.yolo_world
¶
Classes¶
YOLOWorldInferenceRequest
¶
Bases: DynamicClassBaseInferenceRequest
Request for Grounding DINO zero-shot predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
List[str]
|
A list of strings. |
Source code in inference/core/entities/requests/yolo_world.py
9 10 11 12 13 14 15 16 17 | |
core/entities/responses¶
inference.core.entities.responses.clip
¶
Classes¶
ClipCompareResponse
¶
Bases: InferenceResponse
Response for CLIP comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
similarity |
Union[List[float], Dict[str, float]]
|
Similarity scores. |
time |
float
|
The time in seconds it took to produce the similarity scores including preprocessing. |
Source code in inference/core/entities/responses/clip.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
ClipEmbeddingResponse
¶
Bases: InferenceResponse
Response for CLIP embedding.
Attributes:
| Name | Type | Description |
|---|---|---|
embeddings |
List[List[float]]
|
A list of embeddings, each embedding is a list of floats. |
time |
float
|
The time in seconds it took to produce the embeddings including preprocessing. |
Source code in inference/core/entities/responses/clip.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
inference.core.entities.responses.gaze
¶
Classes¶
GazeDetectionInferenceResponse
¶
Bases: BaseModel
Response for gaze detection inference.
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
List[GazeDetectionPrediction]
|
List of gaze detection predictions. |
time |
float
|
The processing time (second). |
Source code in inference/core/entities/responses/gaze.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
GazeDetectionPrediction
¶
Bases: BaseModel
Gaze Detection prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
face |
FaceDetectionPrediction
|
The face prediction. |
yaw |
float
|
Yaw (radian) of the detected face. |
pitch |
float
|
Pitch (radian) of the detected face. |
Source code in inference/core/entities/responses/gaze.py
8 9 10 11 12 13 14 15 16 17 18 19 20 | |
inference.core.entities.responses.inference
¶
Classes¶
ClassificationInferenceResponse
¶
Bases: CvInferenceResponse, WithVisualizationResponse
Classification inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
List[ClassificationPrediction]
|
List of classification predictions. |
top |
str
|
The top predicted class label. |
confidence |
float
|
The confidence of the top predicted class label. |
Source code in inference/core/entities/responses/inference.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
ClassificationPrediction
¶
Bases: BaseModel
Classification prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
class_name |
str
|
The predicted class label. |
class_id |
int
|
Numeric ID associated with the class label. |
confidence |
float
|
The class label confidence as a fraction between 0 and 1. |
Source code in inference/core/entities/responses/inference.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
CvInferenceResponse
¶
Bases: InferenceResponse
Computer Vision inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Union[List[InferenceResponseImage], InferenceResponseImage]
|
Image(s) used in inference. |
Source code in inference/core/entities/responses/inference.py
194 195 196 197 198 199 200 201 | |
DepthEstimationResponse
¶
Bases: BaseModel
Response for depth estimation inference.
Attributes:
| Name | Type | Description |
|---|---|---|
normalized_depth |
List[List[float]]
|
The normalized depth map as a 2D array of floats between 0 and 1. |
image |
Optional[str]
|
Base64 encoded visualization of the depth map if visualize_predictions is True. |
time |
float
|
The processing time in seconds. |
visualization |
Optional[str]
|
Base64 encoded visualization of the depth map if visualize_predictions is True. |
Source code in inference/core/entities/responses/inference.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
FaceDetectionPrediction
¶
Bases: ObjectDetectionPrediction
Face Detection prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
class_name |
str
|
fixed value "face". |
landmarks |
Union[List[Point], List[Point3D]]
|
The detected face landmarks. |
Source code in inference/core/entities/responses/inference.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
InferenceResponse
¶
Bases: BaseModel
Base inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
inference_id |
Optional[str]
|
Unique identifier of inference |
frame_id |
Optional[int]
|
The frame id of the image used in inference if the input was a video. |
time |
Optional[float]
|
The time in seconds it took to produce the predictions including image preprocessing. |
Source code in inference/core/entities/responses/inference.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
InferenceResponseImage
¶
Bases: BaseModel
Inference response image information.
Attributes:
| Name | Type | Description |
|---|---|---|
width |
int
|
The original width of the image used in inference. |
height |
int
|
The original height of the image used in inference. |
Source code in inference/core/entities/responses/inference.py
157 158 159 160 161 162 163 164 165 166 167 168 | |
InstanceSegmentationInferenceResponse
¶
Bases: CvInferenceResponse, WithVisualizationResponse
Instance Segmentation inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
List[InstanceSegmentationPrediction]
|
List of instance segmentation predictions. |
Source code in inference/core/entities/responses/inference.py
251 252 253 254 255 256 257 258 259 260 | |
MultiLabelClassificationInferenceResponse
¶
Bases: CvInferenceResponse, WithVisualizationResponse
Multi-label Classification inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
Dict[str, MultiLabelClassificationPrediction]
|
Dictionary of multi-label classification predictions. |
predicted_classes |
List[str]
|
The list of predicted classes. |
Source code in inference/core/entities/responses/inference.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
MultiLabelClassificationPrediction
¶
Bases: BaseModel
Multi-label Classification prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
confidence |
float
|
The class label confidence as a fraction between 0 and 1. |
Source code in inference/core/entities/responses/inference.py
144 145 146 147 148 149 150 151 152 153 154 | |
ObjectDetectionInferenceResponse
¶
Bases: CvInferenceResponse, WithVisualizationResponse
Object Detection inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
List[ObjectDetectionPrediction]
|
List of object detection predictions. |
Source code in inference/core/entities/responses/inference.py
223 224 225 226 227 228 229 230 | |
ObjectDetectionPrediction
¶
Bases: BaseModel
Object Detection prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
float
|
The center x-axis pixel coordinate of the prediction. |
y |
float
|
The center y-axis pixel coordinate of the prediction. |
width |
float
|
The width of the prediction bounding box in number of pixels. |
height |
float
|
The height of the prediction bounding box in number of pixels. |
confidence |
float
|
The detection confidence as a fraction between 0 and 1. |
class_name |
str
|
The predicted class label. |
class_confidence |
Union[float, None]
|
The class label confidence as a fraction between 0 and 1. |
class_id |
int
|
The class id of the prediction |
Source code in inference/core/entities/responses/inference.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
Point
¶
Bases: BaseModel
Point coordinates.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
float
|
The x-axis pixel coordinate of the point. |
y |
float
|
The y-axis pixel coordinate of the point. |
Source code in inference/core/entities/responses/inference.py
53 54 55 56 57 58 59 60 61 62 | |
Point3D
¶
Bases: Point
3D Point coordinates.
Attributes:
| Name | Type | Description |
|---|---|---|
z |
float
|
The z-axis pixel coordinate of the point. |
Source code in inference/core/entities/responses/inference.py
65 66 67 68 69 70 71 72 | |
SemanticSegmentationInferenceResponse
¶
Bases: CvInferenceResponse, WithVisualizationResponse
Semantic Segmentation inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
SemanticSegmentationPrediction
|
Semantic segmentation predictions. |
Source code in inference/core/entities/responses/inference.py
263 264 265 266 267 268 269 270 271 272 | |
WithVisualizationResponse
¶
Bases: BaseModel
Response with visualization.
Attributes:
| Name | Type | Description |
|---|---|---|
visualization |
Optional[Any]
|
Base64 encoded string containing prediction visualization image data. |
Source code in inference/core/entities/responses/inference.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
inference.core.entities.responses.notebooks
¶
Classes¶
NotebookStartResponse
¶
Bases: BaseModel
Response model for notebook start request
Source code in inference/core/entities/responses/notebooks.py
4 5 6 7 8 | |
inference.core.entities.responses.ocr
¶
Classes¶
OCRInferenceResponse
¶
Bases: BaseModel
OCR Inference response.
Attributes:
| Name | Type | Description |
|---|---|---|
result |
str
|
The combined OCR recognition result. |
predictions |
List[ObjectDetectionPrediction]
|
List of objects detected by OCR |
time |
float
|
The time in seconds it took to produce the inference including preprocessing |
Source code in inference/core/entities/responses/ocr.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
inference.core.entities.responses.perception_encoder
¶
Classes¶
PerceptionEncoderCompareResponse
¶
Bases: InferenceResponse
Response for PERCEPTION_ENCODER comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
similarity |
Union[List[float], Dict[str, float]]
|
Similarity scores. |
time |
float
|
The time in seconds it took to produce the similarity scores including preprocessing. |
Source code in inference/core/entities/responses/perception_encoder.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
PerceptionEncoderEmbeddingResponse
¶
Bases: InferenceResponse
Response for PERCEPTION_ENCODER embedding.
Attributes:
| Name | Type | Description |
|---|---|---|
embeddings |
List[List[float]]
|
A list of embeddings, each embedding is a list of floats. |
time |
float
|
The time in seconds it took to produce the embeddings including preprocessing. |
Source code in inference/core/entities/responses/perception_encoder.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
inference.core.entities.responses.sam
¶
Classes¶
SamEmbeddingResponse
¶
Bases: BaseModel
SAM embedding response.
Attributes:
| Name | Type | Description |
|---|---|---|
embeddings |
Union[List[List[List[List[float]]]], Any]
|
The SAM embedding. |
time |
float
|
The time in seconds it took to produce the embeddings including preprocessing. |
Source code in inference/core/entities/responses/sam.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
SamSegmentationResponse
¶
Bases: BaseModel
SAM segmentation response.
Attributes:
| Name | Type | Description |
|---|---|---|
masks |
Union[List[List[List[int]]], Any]
|
The set of output masks. |
low_res_masks |
Union[List[List[List[int]]], Any]
|
The set of output low-resolution masks. |
time |
float
|
The time in seconds it took to produce the segmentation including preprocessing. |
Source code in inference/core/entities/responses/sam.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
inference.core.entities.responses.sam2
¶
Classes¶
Sam2EmbeddingResponse
¶
Bases: BaseModel
SAM embedding response.
Attributes:
| Name | Type | Description |
|---|---|---|
embeddings |
Union[List[List[List[List[float]]]], Any]
|
The SAM embedding. |
time |
float
|
The time in seconds it took to produce the embeddings including preprocessing. |
Source code in inference/core/entities/responses/sam2.py
6 7 8 9 10 11 12 13 14 15 16 17 | |
Sam2SegmentationPrediction
¶
Bases: BaseModel
SAM segmentation prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
masks |
Union[List[List[List[int]]], Dict[str, Any], Any]
|
Mask data - either polygon coordinates or RLE encoding. |
confidence |
float
|
Masks confidences. |
format |
Optional[str]
|
Format of the mask data: 'polygon' or 'rle'. |
Source code in inference/core/entities/responses/sam2.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
inference.core.entities.responses.sam3_3d
¶
Classes¶
Sam3_3D_Object_Item
¶
Bases: BaseModel
Individual 3D object output with mesh, gaussian, and transformation metadata.
Source code in inference/core/entities/responses/sam3_3d.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
inference.core.entities.responses.server_state
¶
Classes¶
ServerVersionInfo
¶
Bases: BaseModel
Server version information.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Server name. |
version |
str
|
Server version. |
uuid |
str
|
Server UUID. |
Source code in inference/core/entities/responses/server_state.py
8 9 10 11 12 13 14 15 16 17 18 19 | |
core¶
Core framework internals: environment config, data entities, and shared utilities.
inference.core.exceptions
¶
Classes¶
ContentTypeInvalid
¶
Bases: Exception
Raised when the content type is invalid.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
4 5 6 7 8 9 | |
ContentTypeMissing
¶
Bases: Exception
Raised when the content type is missing.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
12 13 14 15 16 17 | |
EngineIgnitionFailure
¶
Bases: Exception
Raised when the engine fails to ignite.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
20 21 22 23 24 25 | |
InferenceModelNotFound
¶
Bases: Exception
Raised when the inference model is not found.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
28 29 30 31 32 33 | |
InvalidEnvironmentVariableError
¶
Bases: Exception
Raised when an environment variable is invalid.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
36 37 38 39 40 41 | |
InvalidMaskDecodeArgument
¶
Bases: Exception
Raised when an invalid argument is provided for mask decoding.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
44 45 46 47 48 49 | |
InvalidNumpyInput
¶
Bases: InputImageLoadError
Raised when the input is an invalid NumPy array.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
94 95 96 97 98 99 | |
MissingApiKeyError
¶
Bases: Exception
Raised when the API key is missing.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
52 53 54 55 56 57 | |
MissingServiceSecretError
¶
Bases: Exception
Raised when the service secret is missing.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
60 61 62 63 64 65 | |
OnnxProviderNotAvailable
¶
Bases: Exception
Raised when the ONNX provider is not available.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
68 69 70 71 72 73 | |
WorkspaceLoadError
¶
Bases: Exception
Raised when there is an error loading the workspace.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Optional message describing the error. |
Source code in inference/core/exceptions.py
76 77 78 79 80 81 | |
inference.core.nms
¶
Functions¶
non_max_suppression_fast
¶
non_max_suppression_fast(boxes, overlapThresh)
Applies non-maximum suppression to bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boxes
|
ndarray
|
Array of bounding boxes with confidence scores. |
required |
overlapThresh
|
float
|
Overlap threshold for suppression. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of bounding boxes after non-maximum suppression. |
Source code in inference/core/nms.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
w_np_non_max_suppression
¶
w_np_non_max_suppression(
prediction,
conf_thresh=0.25,
iou_thresh=0.45,
class_agnostic=False,
max_detections=300,
max_candidate_detections=3000,
timeout_seconds=None,
num_masks=0,
box_format="xywh",
)
Applies non-maximum suppression to predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction
|
ndarray
|
Array of predictions. Format for single prediction is [bbox x 4, max_class_confidence, (confidence) x num_of_classes, additional_element x num_masks] |
required |
conf_thresh
|
float
|
Confidence threshold. Defaults to 0.25. |
0.25
|
iou_thresh
|
float
|
IOU threshold. Defaults to 0.45. |
0.45
|
class_agnostic
|
bool
|
Whether to ignore class labels. Defaults to False. |
False
|
max_detections
|
int
|
Maximum number of detections. Defaults to 300. |
300
|
max_candidate_detections
|
int
|
Maximum number of candidate detections. Defaults to 3000. |
3000
|
timeout_seconds
|
Optional[int]
|
Timeout in seconds. Defaults to None. |
None
|
num_masks
|
int
|
Number of masks. Defaults to 0. |
0
|
box_format
|
str
|
Format of bounding boxes. Either 'xywh' or 'xyxy'. Defaults to 'xywh'. |
'xywh'
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List of filtered predictions after non-maximum suppression. Format of a single result is: [bbox x 4, max_class_confidence, max_class_confidence, id_of_class_with_max_confidence, additional_element x num_masks] |
Source code in inference/core/nms.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
inference.core.roboflow_api
¶
Classes¶
Functions¶
post_to_roboflow_api
¶
post_to_roboflow_api(
endpoint,
api_key,
payload=None,
params=None,
http_errors_handlers=None,
)
Generic function to make a POST request to the Roboflow API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
API endpoint path |
required |
api_key
|
Optional[str]
|
Roboflow API key |
required |
payload
|
Optional[dict]
|
JSON payload |
None
|
params
|
Optional[List[Tuple[str, str]]]
|
Additional URL parameters |
None
|
http_errors_handlers
|
Optional[Dict[int, Callable[[Union[HTTPError]], None]]]
|
Optional custom HTTP error handlers by status code |
None
|
Source code in inference/core/roboflow_api.py
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 | |
inference.core.usage
¶
Functions¶
trackUsage
¶
trackUsage(endpoint, actor, n=1)
Tracks the usage of an endpoint by an actor.
This function increments the usage count for a given endpoint by an actor. It also handles initialization if the count does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint being accessed. |
required |
actor
|
str
|
The actor accessing the endpoint. |
required |
n
|
int
|
The number of times the endpoint was accessed. Defaults to 1. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
This function does not return anything but updates the memcache client. |
Source code in inference/core/usage.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
core/interfaces¶
High-level inference interfaces: camera, HTTP, and stream processing.
inference.core.interfaces.base
¶
Classes¶
BaseInterface
¶
Base interface class which accepts a model manager on initialization
Source code in inference/core/interfaces/base.py
4 5 6 7 8 | |
core/interfaces/camera¶
inference.core.interfaces.camera.camera
¶
Classes¶
WebcamStream
¶
Class to handle webcam streaming using a separate thread.
Attributes:
| Name | Type | Description |
|---|---|---|
stream_id |
int
|
The ID of the webcam stream. |
frame_id |
int
|
A counter for the current frame. |
vcap |
VideoCapture
|
OpenCV video capture object. |
width |
int
|
The width of the video frame. |
height |
int
|
The height of the video frame. |
fps_input_stream |
int
|
Frames per second of the input stream. |
grabbed |
bool
|
A flag indicating if a frame was successfully grabbed. |
frame |
array
|
The current frame as a NumPy array. |
pil_image |
Image
|
The current frame as a PIL image. |
stopped |
bool
|
A flag indicating if the stream is stopped. |
t |
Thread
|
The thread used to update the stream. |
Source code in inference/core/interfaces/camera/camera.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
Functions¶
__init__
¶
__init__(stream_id=0, enforce_fps=False)
Initialize the webcam stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_id
|
int
|
The ID of the webcam stream. Defaults to 0. |
0
|
Source code in inference/core/interfaces/camera/camera.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
read_opencv
¶
read_opencv()
Read the current frame using OpenCV.
Returns:
| Type | Description |
|---|---|
|
array, int: The current frame as a NumPy array, and the frame ID. |
Source code in inference/core/interfaces/camera/camera.py
127 128 129 130 131 132 133 | |
start
¶
start()
Start the thread for reading frames.
Source code in inference/core/interfaces/camera/camera.py
75 76 77 78 | |
stop
¶
stop()
Stop the webcam stream.
Source code in inference/core/interfaces/camera/camera.py
135 136 137 | |
update
¶
update()
Update the frame by reading from the webcam.
Source code in inference/core/interfaces/camera/camera.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
inference.core.interfaces.camera.entities
¶
Classes¶
StatusUpdate
dataclass
¶
Represents a status update event in the system.
Attributes:
| Name | Type | Description |
|---|---|---|
timestamp |
datetime
|
The timestamp when the status update was created. |
severity |
UpdateSeverity
|
The severity level of the update. |
event_type |
str
|
A string representing the type of the event. |
payload |
dict
|
A dictionary containing data relevant to the update. |
context |
str
|
A string providing additional context about the update. |
Source code in inference/core/interfaces/camera/entities.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
UpdateSeverity
¶
Bases: Enum
Enumeration for defining different levels of update severity.
Attributes:
| Name | Type | Description |
|---|---|---|
DEBUG |
int
|
A debugging severity level. |
INFO |
int
|
An informational severity level. |
WARNING |
int
|
A warning severity level. |
ERROR |
int
|
An error severity level. |
Source code in inference/core/interfaces/camera/entities.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
VideoFrame
dataclass
¶
Represents a single frame of video data.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
ndarray
|
The image data of the frame as a NumPy array. |
frame_id |
FrameID
|
A unique identifier for the frame. |
frame_timestamp |
FrameTimestamp
|
The timestamp when the frame was captured. |
source_id |
int
|
The index of the video_reference element which was passed to InferencePipeline for this frame (useful when multiple streams are passed to InferencePipeline). |
fps |
Optional[float]
|
declared FPS of source (if possible to be acquired) |
measured_fps |
Optional[float]
|
measured FPS of live stream |
comes_from_video_file |
Optional[bool]
|
flag to determine if frame comes from video file |
Source code in inference/core/interfaces/camera/entities.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
inference.core.interfaces.camera.utils
¶
Classes¶
RateLimiter
¶
Implements rate upper-bound rate limiting by ensuring estimate_next_tick_delay() to be at min 1 / desired_fps, not letting the client obeying outcomes to exceed assumed rate.
Source code in inference/core/interfaces/camera/utils.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
VideoSourcesManager
¶
This class should be treated as internal building block of stream multiplexer - not for external use.
Source code in inference/core/interfaces/camera/utils.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
Functions¶
get_video_frames_generator
¶
get_video_frames_generator(
video, max_fps=None, limiter_strategy=None
)
Util function to create a frames generator from VideoSource with possibility to
limit FPS of consumed frames and dictate what to do if frames are produced to fast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Union[VideoSource, str, int]
|
Either instance of VideoSource or video reference accepted by VideoSource.init(...) |
required |
max_fps
|
Optional[Union[float, int]]
|
value of maximum FPS rate of generated frames - can be used to limit generation frequency |
None
|
limiter_strategy
|
Optional[FPSLimiterStrategy]
|
strategy used to deal with frames decoding exceeding
limit of |
None
|
Example
from inference.core.interfaces.camera.utils import get_video_frames_generator
for frame in get_video_frames_generator(
video="./some.mp4",
max_fps=50,
):
pass
Source code in inference/core/interfaces/camera/utils.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
multiplex_videos
¶
multiplex_videos(
videos,
max_fps=None,
limiter_strategy=None,
batch_collection_timeout=None,
force_stream_reconnection=True,
should_stop=never_stop,
on_reconnection_error=log_error,
)
Function that is supposed to provide a generator over frames from multiple video sources. It is capable to
initialise VideoSource from references to video files or streams and grab frames from all the sources -
each running individual decoding on separate thread. In each cycle it attempts to grab frames from all sources
(and wait at max batch_collection_timeout for whole batch to be collected). If frame from specific source
cannot be collected in that time - it is simply not included in returned list. If after batch collection list of
frames is empty - new collection start immediately. Collection does not account for
sources that lost connectivity (example: streams that went offline). If that does not happen and stream has
large latency - without reasonable batch_collection_timeout it will slow down processing - so please
set it up in PROD solutions. In case of video streams (not video files) - given that
force_stream_reconnection=True function will attempt to re-connect to disconnected source using background thread,
not impairing batch frames collection and that source is not going to block frames retrieval even if infinite
batch_collection_timeout=None is set. Similarly, when processing files - video file that is shorter than other
passed into processing will not block the whole flow after End Of Stream (EOS).
All sources must be accessible on start - if that's not the case - logic function raises SourceConnectionError
and closes all video sources it opened on it own. Disconnections at later stages are handled by re-connection
mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
videos
|
List[Union[VideoSource, str, int]]
|
List with references to video sources. Elements can be
pre-initialised |
required |
max_fps
|
Optional[Union[float, int]]
|
Upper-bound of processing speed - to be used when one wants at max
|
None
|
limiter_strategy
|
Optional[FPSLimiterStrategy]
|
strategy used to deal with frames decoding exceeding
limit of |
None
|
batch_collection_timeout
|
Optional[float]
|
maximum await time to get batch of predictions from all sources.
|
None
|
force_stream_reconnection
|
bool
|
Flag to decide on reconnection to streams (files are never re-connected) |
True
|
should_stop
|
Callable[[], bool]
|
external stop signal that is periodically checked - to denote that video consumption stopped - make the function to return True |
never_stop
|
on_reconnection_error
|
Callable[[Optional[int], SourceConnectionError], None]
|
Function that will be called whenever source cannot re-connect after disconnection. First parameter is source_id, second is connection error instance. |
log_error
|
Returns Generator[List[VideoFrame], None, None]: allowing to iterate through frames from multiple video sources.
Raises:
| Type | Description |
|---|---|
SourceConnectionError
|
when one or more source is not reachable at start of generation |
Example
from inference.core.interfaces.camera.utils import multiplex_videos
for frames in multiplex_videos(videos=["./some.mp4", "./other.mp4"]):
for frame in frames:
pass # do something with frame
Source code in inference/core/interfaces/camera/utils.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
inference.core.interfaces.camera.video_source
¶
Classes¶
VideoConsumer
¶
This class should be consumed as part of internal implementation. It provides abstraction around stream consumption strategies.
It must always be given the same video source for consecutive invocations, otherwise the internal state does not make sense.
Source code in inference/core/interfaces/camera/video_source.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
VideoSource
¶
Source code in inference/core/interfaces/camera/video_source.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
Functions¶
__next__
¶
__next__()
Method allowing to use VideoSource convenient to read frames
Returns: VideoFrame
Example
source = VideoSource.init(video_reference="./some.mp4")
source.start()
for frame in source:
pass
Source code in inference/core/interfaces/camera/video_source.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
frame_ready
¶
frame_ready()
Method to check if decoded frame is ready for consumer
Returns: boolean flag indicating frame readiness
Source code in inference/core/interfaces/camera/video_source.py
537 538 539 540 541 542 543 | |
get_state
¶
get_state()
Method to get current state of the VideoSource
Returns: StreamState
Source code in inference/core/interfaces/camera/video_source.py
529 530 531 532 533 534 535 | |
init
classmethod
¶
init(
video_reference,
buffer_size=DEFAULT_BUFFER_SIZE,
status_update_handlers=None,
buffer_filling_strategy=None,
buffer_consumption_strategy=None,
adaptive_mode_stream_pace_tolerance=DEFAULT_ADAPTIVE_MODE_STREAM_PACE_TOLERANCE,
adaptive_mode_reader_pace_tolerance=DEFAULT_ADAPTIVE_MODE_READER_PACE_TOLERANCE,
minimum_adaptive_mode_samples=DEFAULT_MINIMUM_ADAPTIVE_MODE_SAMPLES,
maximum_adaptive_frames_dropped_in_row=DEFAULT_MAXIMUM_ADAPTIVE_FRAMES_DROPPED_IN_ROW,
video_source_properties=None,
source_id=None,
desired_fps=None,
)
This class is meant to represent abstraction over video sources - both video files and
on-line streams that are possible to be consumed and used by other components of inference
library.
Before digging into details of the class behaviour, it is advised to familiarise with the following concepts and implementation assumptions:
- Video file can be accessed from local (or remote) storage by the consumer in a pace dictated by its processing capabilities. If processing is faster than the frame rate of video, operations may be executed in a time shorter than the time of video playback. In the opposite case - consumer may freely decode and process frames in its own pace, without risk for failures due to temporal dependencies of processing - this is classical offline processing example.
- Video streams, on the other hand, usually need to be consumed in a pace near to their frame-rate - in other words - this is on-line processing example. Consumer being faster than incoming stream frames cannot utilise its resources to the full extent as not-yet-delivered data would be needed. Slow consumer, however, may not be able to process everything on time and to keep up with the pace of stream - some frames would need to be dropped. Otherwise - over time, consumer could go out of sync with the stream causing decoding failures or unpredictable behavior.
To fit those two types of video sources, VideoSource introduces the concept of buffered decoding of
video stream (like at the YouTube - player buffers some frames that are soon to be displayed).
The way on how buffer is filled and consumed dictates the behavior of VideoSource.
Starting from BufferFillingStrategy - we have 3 basic options:
* WAIT: in case of slow video consumption, when buffer is full - VideoSource will wait for
the empty spot in buffer before next frame will be processed - this is suitable in cases when
we want to ensure EACH FRAME of the video to be processed
* DROP_OLDEST: when buffer is full, the frame that sits there for the longest time will be dropped -
this is suitable for cases when we want to process the most recent frames possible
* DROP_LATEST: when buffer is full, the newly decoded frame is dropped - useful in cases when
it is expected to have processing performance drops, but we would like to consume portions of
video that are locally smooth - but this is probably the least common use-case.
On top of that - there are two ADAPTIVE strategies: ADAPTIVE_DROP_OLDEST and ADAPTIVE_DROP_LATEST, which are equivalent to DROP_OLDEST and DROP_LATEST with adaptive decoding feature enabled. The notion of that mode will be described later.
Naturally, decoded frames must also be consumed. VideoSource provides a handy interface for reading
a video source frames by a SINGLE consumer. Consumption strategy can also be dictated via
BufferConsumptionStrategy:
* LAZY - consume all the frames from decoding buffer one-by-one
* EAGER - at each readout - take all frames already buffered, drop all of them apart from the most recent
In consequence - there are various combinations of BufferFillingStrategy and BufferConsumptionStrategy.
The most popular would be:
* BufferFillingStrategy.WAIT and BufferConsumptionStrategy.LAZY - to always decode and process each and
every frame of the source (useful while processing video files - and default behaviour enforced by
inference if there is no explicit configuration)
* BufferFillingStrategy.DROP_OLDEST and BufferConsumptionStrategy.EAGER - to always process the most
recent frames of source (useful while processing video streams when low latency [real-time experience]
is required - ADAPTIVE version of this is default for streams)
ADAPTIVE strategies were introduced to handle corner-cases, when consumer hardware is not capable to consume
video stream and process frames at the same time (for instance - Nvidia Jetson devices running processing
against hi-res streams with high FPS ratio). It acts with buffer in nearly the same way as DROP_OLDEST
and DROP_LATEST strategies, but there are two more conditions that may influence frame drop:
* announced rate of source - which in fact dictate the pace of frames grabbing from incoming stream that
MUST be met by consumer to avoid strange decoding issues causing decoder to fail - if the pace of frame grabbing
deviates too much - decoding will be postponed, and frames dropped to grab next ones sooner
* consumption rate - in resource constraints environment, not only decoding is problematic from the performance
perspective - but also heavy processing. If consumer is not quick enough - allocating more useful resources
for decoding frames that may never be processed is a waste. That's why - if decoding happens more frequently
than consumption of frame - ADAPTIVE mode causes decoding to be done in a slower pace and more frames are just
grabbed and dropped on the floor.
ADAPTIVE mode increases latency slightly, but may be the only way to operate in some cases.
Behaviour of adaptive mode, including the maximum acceptable deviations of frames grabbing pace from source,
reader pace and maximum number of consecutive frames dropped in ADAPTIVE mode are configurable by clients,
with reasonable defaults being set.
VideoSource emits events regarding its activity - which can be intercepted by custom handlers. Take
into account that they are always executed in context of thread invoking them (and should be fast to complete,
otherwise may block the flow of stream consumption). All errors raised will be emitted as logger warnings only.
VideoSource implementation is naturally multithreading, with different thread decoding video and different
one consuming it and manipulating source state. Implementation of user interface is thread-safe, although
stream it is meant to be consumed by a single thread only.
ENV variables involved: * VIDEO_SOURCE_BUFFER_SIZE - default: 64 * VIDEO_SOURCE_ADAPTIVE_MODE_STREAM_PACE_TOLERANCE - default: 0.1 * VIDEO_SOURCE_ADAPTIVE_MODE_READER_PACE_TOLERANCE - default: 5.0 * VIDEO_SOURCE_MINIMUM_ADAPTIVE_MODE_SAMPLES - default: 10 * VIDEO_SOURCE_MAXIMUM_ADAPTIVE_FRAMES_DROPPED_IN_ROW - default: 16
As an inference user, please use .init() method instead of constructor to instantiate objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_reference
|
Union[str, int]
|
Either str with file or stream reference, or int representing device ID |
required |
buffer_size
|
int
|
size of decoding buffer |
DEFAULT_BUFFER_SIZE
|
status_update_handlers
|
Optional[List[Callable[[StatusUpdate], None]]]
|
List of handlers for status updates |
None
|
buffer_filling_strategy
|
Optional[BufferFillingStrategy]
|
Settings for buffer filling strategy - if not given - automatic choice regarding source type will be applied |
None
|
buffer_consumption_strategy
|
Optional[BufferConsumptionStrategy]
|
Settings for buffer consumption strategy, if not given - automatic choice regarding source type will be applied |
None
|
adaptive_mode_stream_pace_tolerance
|
float
|
Maximum deviation between frames grabbing pace and stream pace that will not trigger adaptive mode frame drop |
DEFAULT_ADAPTIVE_MODE_STREAM_PACE_TOLERANCE
|
adaptive_mode_reader_pace_tolerance
|
float
|
Maximum deviation between decoding pace and stream consumption pace that will not trigger adaptive mode frame drop |
DEFAULT_ADAPTIVE_MODE_READER_PACE_TOLERANCE
|
minimum_adaptive_mode_samples
|
int
|
Minimal number of frames to be used to establish actual pace of processing, before adaptive mode can drop any frame |
DEFAULT_MINIMUM_ADAPTIVE_MODE_SAMPLES
|
maximum_adaptive_frames_dropped_in_row
|
int
|
Maximum number of frames dropped in row due to application of adaptive strategy |
DEFAULT_MAXIMUM_ADAPTIVE_FRAMES_DROPPED_IN_ROW
|
video_source_properties
|
Optional[dict[str, float]]
|
Optional dictionary with video source properties corresponding to OpenCV VideoCapture properties cv2.CAP_PROP_* to set values for the video source. |
None
|
source_id
|
Optional[int]
|
Optional identifier of video source - mainly useful to recognise specific source when multiple ones are in use. Identifier will be added to emitted frames and updates. It is advised to keep it unique within all sources in use. |
None
|
Source code in inference/core/interfaces/camera/video_source.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
mute
¶
mute()
Method to be used to mute source consumption. Muting is an equivalent of pause for stream - where frames grabbing is not put on hold, just new frames decoding and buffering is not allowed - causing intermediate frames to be dropped. May be also used against files, although arguably less useful. Eligible to be used in states: [RUNNING] End state: * MUTED
Thread safe - only one transition of states possible at the time.
Source code in inference/core/interfaces/camera/video_source.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
pause
¶
pause()
Method to be used to pause source consumption. During pause - no new frames are consumed. Used on on-line streams for too long may cause stream disconnection. Eligible to be used in states: [RUNNING] End state: * PAUSED
Thread safe - only one transition of states possible at the time.
Source code in inference/core/interfaces/camera/video_source.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
read_frame
¶
read_frame(timeout=None)
Method to be used by the consumer to get decoded source frame.
Source code in inference/core/interfaces/camera/video_source.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
restart
¶
restart(
wait_on_frames_consumption=True,
purge_frames_buffer=False,
)
Method to restart source consumption. Eligible to be used in states: [MUTED, RUNNING, PAUSED, ENDED, ERROR]. End state: * INITIALISING - that should change into RUNNING once first frame is ready to be grabbed * ERROR - if it was not possible to connect with source
Thread safe - only one transition of states possible at the time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait_on_frames_consumption
|
bool
|
Flag telling if all frames from buffer must be consumed before completion of this operation. |
True
|
Source code in inference/core/interfaces/camera/video_source.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
resume
¶
resume()
Method to recover from pause or mute into running state. [PAUSED, MUTED] End state: * RUNNING
Thread safe - only one transition of states possible at the time.
Source code in inference/core/interfaces/camera/video_source.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
start
¶
start()
Method to be used to start source consumption. Eligible to be used in states: [NOT_STARTED, ENDED, (RESTARTING - which is internal state only)] End state: * INITIALISING - that should change into RUNNING once first frame is ready to be grabbed * ERROR - if it was not possible to connect with source
Thread safe - only one transition of states possible at the time.
Source code in inference/core/interfaces/camera/video_source.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
terminate
¶
terminate(
wait_on_frames_consumption=True,
purge_frames_buffer=False,
)
Method to be used to terminate source consumption. Eligible to be used in states: [MUTED, RUNNING, PAUSED, ENDED, ERROR, (RESTARTING - which is internal state only)] End state: * ENDED - indicating success of the process * ERROR - if error with processing occurred
Must be used to properly dispose resources at the end.
Thread safe - only one transition of states possible at the time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait_on_frames_consumption
|
bool
|
Flag telling if all frames from buffer must be consumed before completion of this operation. |
True
|
Source code in inference/core/interfaces/camera/video_source.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
Functions¶
get_from_queue
¶
get_from_queue(
queue,
timeout=None,
on_successful_read=lambda: None,
purge=False,
)
Function is supposed to take element from the queue waiting on the first element to appear using timeout
parameter. One may ask to go to the very last element of the queue and return it - then purge should be set
to True. No additional wait on new elements to appear happen and the purge stops once queue is free returning last
element consumed.
queue.task_done() and on_successful_read(...) will be called on each received element.
Source code in inference/core/interfaces/camera/video_source.py
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 | |
core/interfaces/http/builder¶
inference.core.interfaces.http.builder.routes
¶
Functions¶
builder_browse
async
¶
builder_browse()
Loads the main builder UI (editor.html). Injects the CSRF token and BUILDER_ORIGIN so the client can parse them on page load.
Source code in inference/core/interfaces/http/builder/routes.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
builder_edit
async
¶
builder_edit(workflow_id)
Loads a specific workflow for editing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The ID of the workflow to be edited. |
required |
Source code in inference/core/interfaces/http/builder/routes.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
builder_maybe_redirect
async
¶
builder_maybe_redirect(workflow_id)
If the workflow_id.json file exists, redirect to /build/edit/{workflow_id}. Otherwise, redirect back to /build.
Source code in inference/core/interfaces/http/builder/routes.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
builder_redirect
async
¶
builder_redirect()
If user hits /build/ with trailing slash, redirect to /build
Source code in inference/core/interfaces/http/builder/routes.py
70 71 72 73 74 75 | |
create_or_overwrite_workflow
async
¶
create_or_overwrite_workflow(
workflow_id, request_body=Body(...)
)
Create or overwrite a workflow's JSON file on disk. Protected by CSRF token check.
Source code in inference/core/interfaces/http/builder/routes.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
delete_workflow
async
¶
delete_workflow(workflow_id)
Delete a workflow's JSON file from disk. Protected by CSRF token check.
Source code in inference/core/interfaces/http/builder/routes.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
get_all_workflows
async
¶
get_all_workflows()
Returns JSON info about all .json files in {MODEL_CACHE_DIR}/workflow/local. Protected by CSRF token check.
Source code in inference/core/interfaces/http/builder/routes.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
get_workflow
async
¶
get_workflow(workflow_id)
Return JSON for workflow_id.json, or 404 if missing.
Source code in inference/core/interfaces/http/builder/routes.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
core/interfaces/http¶
inference.core.interfaces.http.error_handlers
¶
Classes¶
Functions¶
with_route_exceptions
¶
with_route_exceptions(route)
A decorator that wraps a FastAPI route to handle specific exceptions. If an exception is caught, it returns a JSON response with the error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route
|
Callable
|
The FastAPI route to be wrapped. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
The wrapped route. |
Source code in inference/core/interfaces/http/error_handlers.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
with_route_exceptions_async
¶
with_route_exceptions_async(route)
A decorator that wraps a FastAPI route to handle specific exceptions. If an exception is caught, it returns a JSON response with the error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route
|
Callable
|
The FastAPI route to be wrapped. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
The wrapped route. |
Source code in inference/core/interfaces/http/error_handlers.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 | |
inference.core.interfaces.http.http_api
¶
Classes¶
HttpInterface
¶
Bases: BaseInterface
Roboflow defined HTTP interface for a general-purpose inference server.
This class sets up the FastAPI application and adds necessary middleware, as well as initializes the model manager and model registry for the inference server.
Attributes:
| Name | Type | Description |
|---|---|---|
app |
FastAPI
|
The FastAPI application instance. |
model_manager |
ModelManager
|
The manager for handling different models. |
Source code in inference/core/interfaces/http/http_api.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 | |
Functions¶
__init__
¶
__init__(model_manager, root_path=None)
Initializes the HttpInterface with given model manager and model registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_manager
|
ModelManager
|
The manager for handling different models. |
required |
root_path
|
Optional[str]
|
The root path for the FastAPI application. |
None
|
Description
Deploy Roboflow trained models to nearly any compute environment!
Source code in inference/core/interfaces/http/http_api.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 | |
Functions¶
load_gaze_model
¶
load_gaze_model(inference_request, api_key=None)
Loads the gaze detection model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
GazeDetectionInferenceRequest
|
The inference request. |
required |
api_key
|
Optional[str], default None
|
The Roboflow API key. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The model ID. |
Source code in inference/core/interfaces/http/http_api.py
3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 | |
core/interfaces/http/middlewares¶
inference.core.interfaces.http.middlewares.cors
¶
Classes¶
PathAwareCORSMiddleware
¶
Bases: CORSMiddleware
Extends Starlette's CORSMiddleware to allow specifying a regex of paths that this middleware should apply to. If 'match_paths' is given, only requests matching that regex will have CORS headers applied.
Also supports Private Network Access (PNA) for local development, allowing requests from public websites to localhost.
Source code in inference/core/interfaces/http/middlewares/cors.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
Functions¶
__call__
async
¶
__call__(scope, receive, send)
Only apply the CORS logic if the path matches self.match_paths_regex (when provided). Otherwise, just call the wrapped 'app'.
Source code in inference/core/interfaces/http/middlewares/cors.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
core/interfaces/stream¶
inference.core.interfaces.stream.sinks
¶
Classes¶
UDPSink
¶
Source code in inference/core/interfaces/stream/sinks.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
Functions¶
init
classmethod
¶
init(ip_address, port)
Creates InferencePipeline predictions sink capable of sending model predictions over network
using UDP socket.
As an inference user, please use .init() method instead of constructor to instantiate objects.
Args:
ip_address (str): IP address to send predictions
port (int): Port to send predictions
Returns: Initialised object of UDPSink class.
Source code in inference/core/interfaces/stream/sinks.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
send_predictions
¶
send_predictions(predictions, video_frame)
Method to send predictions via UDP socket. Useful in combination with InferencePipeline as
a sink for predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
Union[dict, List[Optional[dict]]]
|
Roboflow predictions, the function support single prediction
processing and batch processing since version |
required |
video_frame
|
Union[VideoFrame, List[Optional[VideoFrame]]]
|
frame of video with its basic metadata emitted
by |
required |
Side effects: Sends serialised predictions and video_frame metadata via the UDP socket as
JSON string. It adds key named "inference_metadata" into predictions dict (mutating its
state). "inference_metadata" contain id of the frame, frame grabbing timestamp and message
emission time in datetime iso format.
Example
import cv2
from inference.core.interfaces.stream.inference_pipeline import InferencePipeline
from inference.core.interfaces.stream.sinks import UDPSink
udp_sink = UDPSink.init(ip_address="127.0.0.1", port=9090)
pipeline = InferencePipeline.init(
model_id="your-model/3",
video_reference="./some_file.mp4",
on_prediction=udp_sink.send_predictions,
)
pipeline.start()
pipeline.join()
UDPSink used in this way will emit predictions to receiver automatically.
Source code in inference/core/interfaces/stream/sinks.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
VideoFileSink
¶
Source code in inference/core/interfaces/stream/sinks.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
Functions¶
init
classmethod
¶
init(
video_file_name,
annotator=None,
display_size=(1280, 720),
fps_monitor=DEFAULT_FPS_MONITOR,
display_statistics=False,
output_fps=25,
quiet=False,
video_frame_size=(1280, 720),
)
Creates InferencePipeline predictions sink capable of saving model predictions into video file.
It works both for pipelines with single input video and multiple ones.
As an inference user, please use .init() method instead of constructor to instantiate objects.
Args:
video_file_name (str): name of the video file to save predictions
annotator (Union[BaseAnnotator, List[BaseAnnotator]]): instance of class inheriting from supervision BaseAnnotator
or list of such instances. If nothing is passed chain of sv.BoxAnnotator() and sv.LabelAnnotator() is used.
display_size (Tuple[int, int]): tuple in format (width, height) to resize visualisation output. Should
be set to the same value as display_size for InferencePipeline with single video source, otherwise
it represents the size of single visualisation tile (whole tiles mosaic will be scaled to
video_frame_size)
fps_monitor (Optional[sv.FPSMonitor]): FPS monitor used to monitor throughput
display_statistics (bool): Flag to decide if throughput and latency can be displayed in the result image,
if enabled, throughput will only be presented if fps_monitor is not None
output_fps (int): desired FPS of output file
quiet (bool): Flag to decide whether to log progress
video_frame_size (Tuple[int, int]): The size of frame in target video file.
Attributes:
| Name | Type | Description |
|---|---|---|
on_prediction |
Callable[[dict, VideoFrame], None]
|
callable to be used as a sink for predictions |
Example
import cv2
from inference import InferencePipeline
from inference.core.interfaces.stream.sinks import VideoFileSink
video_sink = VideoFileSink.init(video_file_name="output.avi")
pipeline = InferencePipeline.init(
model_id="your-model/3",
video_reference="./some_file.mp4",
on_prediction=video_sink.on_prediction,
)
pipeline.start()
pipeline.join()
video_sink.release()
VideoFileSink used in this way will save predictions to video file automatically.
Source code in inference/core/interfaces/stream/sinks.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
release
¶
release()
Releases VideoWriter object.
Source code in inference/core/interfaces/stream/sinks.py
505 506 507 508 509 510 | |
Functions¶
active_learning_sink
¶
active_learning_sink(
predictions,
video_frame,
active_learning_middleware,
model_type,
disable_preproc_auto_orient=False,
)
Function to serve as Active Learning sink for InferencePipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
Union[dict, List[Optional[dict]]]
|
Roboflow predictions, the function support single prediction
processing and batch processing since version |
required |
video_frame
|
Union[VideoFrame, List[Optional[VideoFrame]]]
|
frame of video with its basic metadata emitted
by |
required |
active_learning_middleware
|
ActiveLearningMiddleware
|
instance of middleware to register data. |
required |
model_type
|
str
|
Type of Roboflow model in use |
required |
disable_preproc_auto_orient
|
bool
|
Flag to denote how image is preprocessed which is important in Active Learning. |
False
|
Side effects: Can register data and predictions in Roboflow backend if that's the evaluation of sampling engine.
Source code in inference/core/interfaces/stream/sinks.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
multi_sink
¶
multi_sink(predictions, video_frame, sinks)
Helper util useful to combine multiple sinks together, while using InferencePipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_frame
|
VideoFrame
|
frame of video with its basic metadata emitted by |
required |
predictions
|
dict
|
Roboflow object detection predictions with Bounding Boxes |
required |
sinks
|
List[Callable[[VideoFrame, dict], None]]
|
list of sinks to be used. Each will be executed one-by-one in the order pointed in input list, all errors will be caught and reported via logger, without re-raising. |
required |
Side effects: Uses all sinks in context if (video_frame, predictions) input.
Example
from functools import partial
import cv2
from inference import InferencePipeline
from inference.core.interfaces.stream.sinks import UDPSink, render_boxes
udp_sink = UDPSink(ip_address="127.0.0.1", port=9090)
on_prediction = partial(multi_sink, sinks=[udp_sink.send_predictions, render_boxes])
pipeline = InferencePipeline.init(
model_id="your-model/3",
video_reference="./some_file.mp4",
on_prediction=on_prediction,
)
pipeline.start()
pipeline.join()
As a result, predictions will both be sent via UDP socket and displayed in the screen.
Source code in inference/core/interfaces/stream/sinks.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
render_boxes
¶
render_boxes(
predictions,
video_frame,
annotator=None,
display_size=(1280, 720),
fps_monitor=DEFAULT_FPS_MONITOR,
display_statistics=False,
on_frame_rendered=display_image,
)
Helper tool to render object detection predictions on top of video frame. It is designed
to be used with InferencePipeline, as sink for predictions. By default, it uses
standard sv.BoxAnnotator() chained with sv.LabelAnnotator()
to draw bounding boxes and resizes prediction to 1280x720 (keeping aspect ratio and adding black padding).
One may configure default behaviour, for instance to display latency and throughput statistics.
In batch mode it will display tiles of frames and overlay predictions.
This sink is only partially compatible with stubs and classification models (it will not fail, although predictions will not be displayed).
Since version 0.9.18, when multi-source InferencePipeline was introduced - it support batch input, without
changes to old functionality when single (predictions, video_frame) is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
Union[dict, List[Optional[dict]]]
|
Roboflow predictions, the function support single prediction
processing and batch processing since version |
required |
video_frame
|
Union[VideoFrame, List[Optional[VideoFrame]]]
|
frame of video with its basic metadata emitted
by |
required |
annotator
|
Union[BaseAnnotator, List[BaseAnnotator]]
|
instance of class inheriting from supervision BaseAnnotator
or list of such instances. If nothing is passed chain of |
None
|
display_size
|
Tuple[int, int]
|
tuple in format (width, height) to resize visualisation output |
(1280, 720)
|
fps_monitor
|
Optional[FPSMonitor]
|
FPS monitor used to monitor throughput |
DEFAULT_FPS_MONITOR
|
display_statistics
|
bool
|
Flag to decide if throughput and latency can be displayed in the result image,
if enabled, throughput will only be presented if |
False
|
on_frame_rendered
|
Callable[[Union[ImageWithSourceID, List[ImageWithSourceID]]], None]
|
callback to be called once frame is rendered - by default, function will display OpenCV window. It expects optional integer identifier with np.ndarray or list of those elements. Identifier is supposed to refer to either source_id (for sequential input) or position in the batch (from 0 to batch_size-1). |
display_image
|
Side effects: on_frame_rendered() is called against the tuple (stream_id, np.ndarray) produced from video frame and predictions.
Example
from functools import partial
import cv2
from inference import InferencePipeline
from inference.core.interfaces.stream.sinks import render_boxes
output_size = (640, 480)
video_sink = cv2.VideoWriter("output.avi", cv2.VideoWriter_fourcc(*"MJPG"), 25.0, output_size)
on_prediction = partial(
render_boxes,
display_size=output_size,
on_frame_rendered=lambda frame_data: video_sink.write(frame_data[1])
)
pipeline = InferencePipeline.init(
model_id="your-model/3",
video_reference="./some_file.mp4",
on_prediction=on_prediction,
)
pipeline.start()
pipeline.join()
video_sink.release()
In this example, render_boxes() is used as a sink for InferencePipeline predictions - making frames with
predictions displayed to be saved into video file. Please note that this is oversimplified example of usage
which will not be robust against multiple streams - better implementation available in VideoFileSink class.
Source code in inference/core/interfaces/stream/sinks.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
inference.core.interfaces.stream.stream
¶
Classes¶
Stream
¶
Bases: BaseInterface
Roboflow defined stream interface for a general-purpose inference server.
Attributes:
| Name | Type | Description |
|---|---|---|
model_manager |
ModelManager
|
The manager that handles model inference tasks. |
model_registry |
RoboflowModelRegistry
|
The registry to fetch model instances. |
api_key |
str
|
The API key for accessing models. |
class_agnostic_nms |
bool
|
Flag for class-agnostic non-maximum suppression. |
confidence |
float
|
Confidence threshold for inference. |
iou_threshold |
float
|
The intersection-over-union threshold for detection. |
json_response |
bool
|
Flag to toggle JSON response format. |
max_candidates |
float
|
The maximum number of candidates for detection. |
max_detections |
float
|
The maximum number of detections. |
model |
str | Callable
|
The model to be used. |
stream_id |
str
|
The ID of the stream to be used. |
use_bytetrack |
bool
|
Flag to use bytetrack, |
Methods:
| Name | Description |
|---|---|
init_infer |
Initialize the inference with a test frame. |
preprocess_thread |
Preprocess incoming frames for inference. |
inference_request_thread |
Manage the inference requests. |
run_thread |
Run the preprocessing and inference threads. |
Source code in inference/core/interfaces/stream/stream.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
Functions¶
__init__
¶
__init__(
api_key=API_KEY,
class_agnostic_nms=CLASS_AGNOSTIC_NMS,
confidence=CONFIDENCE,
enforce_fps=ENFORCE_FPS,
iou_threshold=IOU_THRESHOLD,
max_candidates=MAX_CANDIDATES,
max_detections=MAX_DETECTIONS,
model=MODEL_ID,
source=STREAM_ID,
use_bytetrack=ENABLE_BYTE_TRACK,
use_main_thread=False,
output_channel_order="RGB",
on_prediction=None,
on_start=None,
on_stop=None,
)
Initialize the stream with the given parameters. Prints the server settings and initializes the inference with a test frame.
Source code in inference/core/interfaces/stream/stream.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
inference_request_thread
¶
inference_request_thread()
Manage the inference requests.
Processes preprocessed frames for inference, post-processes the predictions, and sends the results to registered callbacks.
Source code in inference/core/interfaces/stream/stream.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
init_infer
¶
init_infer()
Initialize the inference with a test frame.
Creates a test frame and runs it through the entire inference process to ensure everything is working.
Source code in inference/core/interfaces/stream/stream.py
196 197 198 199 200 201 202 203 204 205 | |
preprocess_thread
¶
preprocess_thread()
Preprocess incoming frames for inference.
Reads frames from the webcam stream, converts them into the proper format, and preprocesses them for inference.
Source code in inference/core/interfaces/stream/stream.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
run_thread
¶
run_thread()
Run the preprocessing and inference threads.
Starts the preprocessing and inference threads, and handles graceful shutdown on KeyboardInterrupt.
Source code in inference/core/interfaces/stream/stream.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
Functions¶
inference.core.interfaces.stream.watchdog
¶
This module contains component intended to use in combination with InferencePipeline to ensure
observability. Please consider them internal details of implementation.
Classes¶
BasePipelineWatchDog
¶
Bases: PipelineWatchDog
Implementation to be used from single inference thread, as it keeps state assumed to represent status of consecutive stage of prediction process in latency monitor.
Source code in inference/core/interfaces/stream/watchdog.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
core/interfaces/udp¶
inference.core.interfaces.udp.udp_stream
¶
Classes¶
UdpStream
¶
Bases: BaseInterface
Roboflow defined UDP interface for a general-purpose inference server.
Attributes:
| Name | Type | Description |
|---|---|---|
model_manager |
ModelManager
|
The manager that handles model inference tasks. |
model_registry |
RoboflowModelRegistry
|
The registry to fetch model instances. |
api_key |
str
|
The API key for accessing models. |
class_agnostic_nms |
bool
|
Flag for class-agnostic non-maximum suppression. |
confidence |
float
|
Confidence threshold for inference. |
ip_broadcast_addr |
str
|
The IP address to broadcast to. |
ip_broadcast_port |
int
|
The port to broadcast on. |
iou_threshold |
float
|
The intersection-over-union threshold for detection. |
max_candidates |
float
|
The maximum number of candidates for detection. |
max_detections |
float
|
The maximum number of detections. |
model_id |
str
|
The ID of the model to be used. |
stream_id |
str
|
The ID of the stream to be used. |
use_bytetrack |
bool
|
Flag to use bytetrack, |
Methods:
| Name | Description |
|---|---|
init_infer |
Initialize the inference with a test frame. |
preprocess_thread |
Preprocess incoming frames for inference. |
inference_request_thread |
Manage the inference requests. |
run_thread |
Run the preprocessing and inference threads. |
Source code in inference/core/interfaces/udp/udp_stream.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
Functions¶
__init__
¶
__init__(
api_key=API_KEY,
class_agnostic_nms=CLASS_AGNOSTIC_NMS,
confidence=CONFIDENCE,
enforce_fps=ENFORCE_FPS,
ip_broadcast_addr=IP_BROADCAST_ADDR,
ip_broadcast_port=IP_BROADCAST_PORT,
iou_threshold=IOU_THRESHOLD,
max_candidates=MAX_CANDIDATES,
max_detections=MAX_DETECTIONS,
model_id=MODEL_ID,
stream_id=STREAM_ID,
use_bytetrack=ENABLE_BYTE_TRACK,
)
Initialize the UDP stream with the given parameters. Prints the server settings and initializes the inference with a test frame.
Source code in inference/core/interfaces/udp/udp_stream.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
inference_request_thread
¶
inference_request_thread()
Manage the inference requests.
Processes preprocessed frames for inference, post-processes the predictions, and sends the results as a UDP broadcast.
Source code in inference/core/interfaces/udp/udp_stream.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
init_infer
¶
init_infer()
Initialize the inference with a test frame.
Creates a test frame and runs it through the entire inference process to ensure everything is working.
Source code in inference/core/interfaces/udp/udp_stream.py
161 162 163 164 165 166 167 168 169 170 | |
preprocess_thread
¶
preprocess_thread()
Preprocess incoming frames for inference.
Reads frames from the webcam stream, converts them into the proper format, and preprocesses them for inference.
Source code in inference/core/interfaces/udp/udp_stream.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
run_thread
¶
run_thread()
Run the preprocessing and inference threads.
Starts the preprocessing and inference threads, and handles graceful shutdown on KeyboardInterrupt.
Source code in inference/core/interfaces/udp/udp_stream.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
Functions¶
core/interfaces/webrtc_worker¶
inference.core.interfaces.webrtc_worker.entities
¶
Classes¶
VideoFileUploadState
¶
Bases: str, Enum
State of video file upload.
Source code in inference/core/interfaces/webrtc_worker/entities.py
106 107 108 109 110 111 112 113 | |
WebRTCOutput
¶
Bases: BaseModel
Output sent via WebRTC data channel.
serialized_output_data contains a dictionary with workflow outputs: - If data_output is None or []: no data sent (only metadata) - If data_output is ["*"]: all workflow outputs (excluding images, unless explicitly named) - If data_output is ["field1", "field2"]: only those fields (including images if explicitly named)
Source code in inference/core/interfaces/webrtc_worker/entities.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
inference.core.interfaces.webrtc_worker.serializers
¶
Classes¶
Functions¶
compress_image_for_webrtc
¶
compress_image_for_webrtc(image)
Serialize image with low JPEG quality for efficient WebRTC transmission.
Source code in inference/core/interfaces/webrtc_worker/serializers.py
12 13 14 15 16 17 18 19 20 21 | |
serialize_for_webrtc
¶
serialize_for_webrtc(value)
Serialize for WebRTC, compressing images with low JPEG quality.
Source code in inference/core/interfaces/webrtc_worker/serializers.py
24 25 26 27 28 29 30 31 32 | |
inference.core.interfaces.webrtc_worker.utils
¶
Classes¶
Functions¶
detect_image_output
¶
detect_image_output(workflow_output)
Detect the first available image output field in workflow output.
Source code in inference/core/interfaces/webrtc_worker/utils.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
get_cv2_rotation_code
¶
get_cv2_rotation_code(rotation)
Get OpenCV rotation code to correct a given rotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation
|
int
|
Rotation angle in degrees from metadata |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
cv2 rotation constant or None if no correction needed |
Source code in inference/core/interfaces/webrtc_worker/utils.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
get_video_fps
¶
get_video_fps(filepath)
Detect video FPS from container metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the video file |
required |
Returns:
| Type | Description |
|---|---|
Optional[float]
|
FPS as float, or None if detection fails |
Source code in inference/core/interfaces/webrtc_worker/utils.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
get_video_rotation
¶
get_video_rotation(filepath)
Detect video rotation from metadata (displaymatrix or rotate tag).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the video file |
required |
Returns:
| Type | Description |
|---|---|
int
|
Rotation in degrees (-90, 0, 90, 180, 270) or 0 if not found. |
int
|
Negative values indicate counter-clockwise rotation. |
Source code in inference/core/interfaces/webrtc_worker/utils.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
parse_video_file_chunk
¶
parse_video_file_chunk(message)
Parse video file chunk message.
Returns: (chunk_index, total_chunks, payload)
Source code in inference/core/interfaces/webrtc_worker/utils.py
196 197 198 199 200 201 202 203 204 | |
rotate_video_frame
¶
rotate_video_frame(frame, rotation_code)
Apply rotation to a video frame using OpenCV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
VideoFrame
|
Input VideoFrame |
required |
rotation_code
|
int
|
cv2 rotation constant (ROTATE_90_CLOCKWISE, etc.) |
required |
Returns:
| Type | Description |
|---|---|
VideoFrame
|
Rotated VideoFrame |
Source code in inference/core/interfaces/webrtc_worker/utils.py
382 383 384 385 386 387 388 389 390 391 392 393 394 | |
inference.core.interfaces.webrtc_worker.webrtc
¶
Classes¶
VideoFrameProcessor
¶
Base class for processing video frames through workflow.
Can be used independently for data-only processing (no video track output) or as a base for VideoTransformTrackWithLoop when video output is needed.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
Functions¶
process_frames_data_only
async
¶
process_frames_data_only()
Process frames for data extraction only, without video track output.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
record_ack
¶
record_ack(ack)
Record cumulative ACK from the client.
ACK semantics: client has fully handled all frames <= ack. Backwards compatible: pacing is disabled until we receive the first ACK.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
serialize_outputs_sync
staticmethod
¶
serialize_outputs_sync(
fields_to_send, workflow_output, data_output_mode
)
Serialize workflow outputs for WebRTC transmission.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
VideoTransformTrackWithLoop
¶
Bases: VideoStreamTrack, VideoFrameProcessor
Video track that processes frames through workflow and sends video back.
Inherits from both VideoStreamTrack (for WebRTC video track functionality) and VideoFrameProcessor (for workflow processing logic).
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
Functions¶
create_chunked_binary_message
¶
create_chunked_binary_message(
frame_id, chunk_index, total_chunks, payload
)
Create a binary message with standard 12-byte header.
Format: [frame_id: 4][chunk_index: 4][total_chunks: 4][payload: N] All integers are uint32 little-endian.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
83 84 85 86 87 88 89 90 91 92 | |
send_chunked_data
async
¶
send_chunked_data(
data_channel,
frame_id,
payload_bytes,
chunk_size=CHUNK_SIZE,
heartbeat_callback=None,
buffer_timeout=120.0,
)
Send payload via data channel with chunking and backpressure.
We chunk large payloads because WebRTC data channels have message size limits. We apply backpressure (wait for buffer to drain) to avoid overwhelming the network and causing ICE connection failures.
Heads up: buffer_timeout needs to be higher than WEBRTC_DATA_CHANNEL_BUFFER_DRAINING_DELAY! Otherwise we will timeout ourselves.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
wait_for_buffer_drain
async
¶
wait_for_buffer_drain(
data_channel,
timeout=30.0,
heartbeat_callback=None,
low_threshold=None,
)
Wait for data channel buffer to drain below threshold, with timeout.
We use a low threshold (1/4 of limit) instead of just below the limit to avoid hysteresis - constantly triggering this wait after sending just a few chunks.
And we wait WEBRTC_DATA_CHANNEL_BUFFER_DRAINING_DELAY to avoid starving the event loop.
Source code in inference/core/interfaces/webrtc_worker/webrtc.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
core/interfaces/webrtc_worker/sources¶
inference.core.interfaces.webrtc_worker.sources.file
¶
Video file source for WebRTC - handles uploaded video files.
Classes¶
ThreadedVideoFileTrack
¶
Bases: MediaStreamTrack
Video track that decodes frames from a file in a background thread.
Uses a dedicated thread with a queue to avoid deadlocks with the event loop.
Source code in inference/core/interfaces/webrtc_worker/sources/file.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
VideoFileUploadHandler
¶
Handles video file uploads via data channel.
Protocol: [chunk_index:u32][total_chunks:u32][payload] Auto-completes when all chunks received.
Source code in inference/core/interfaces/webrtc_worker/sources/file.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
Functions¶
cleanup
async
¶
cleanup()
Clean up temp file.
Source code in inference/core/interfaces/webrtc_worker/sources/file.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
handle_chunk
¶
handle_chunk(chunk_index, total_chunks, data)
Handle a chunk. Auto-completes when all chunks received.
Source code in inference/core/interfaces/webrtc_worker/sources/file.py
128 129 130 131 132 133 134 135 136 137 138 139 140 | |
try_start_processing
¶
try_start_processing()
Check if upload complete and transition to PROCESSING. Returns path or None.
Source code in inference/core/interfaces/webrtc_worker/sources/file.py
154 155 156 157 158 159 | |
core/logging¶
inference.core.logging.memory_handler
¶
In-memory logging handler for dashboard log viewing.
This module provides a custom logging handler that stores log records in memory for retrieval via the /logs API endpoint. It's designed to be used when ENABLE_IN_MEMORY_LOGS environment variable is set to 'true'.
Classes¶
MemoryLogHandler
¶
Bases: Handler
Custom log handler that stores log records in memory for dashboard access
Source code in inference/core/logging/memory_handler.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Functions¶
get_recent_logs
¶
get_recent_logs(limit=100, level=None, since=None)
Get recent log entries from memory
Source code in inference/core/logging/memory_handler.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
setup_memory_logging
¶
setup_memory_logging()
Set up memory logging handler for the current logger hierarchy
Source code in inference/core/logging/memory_handler.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
core/managers¶
Model lifecycle managers: loading, unloading, registry, and resolution.
inference.core.managers.base
¶
Classes¶
ModelManager
¶
Model managers keep track of a dictionary of Model objects and is responsible for passing requests to the right model using the infer method.
Source code in inference/core/managers/base.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
Functions¶
__contains__
¶
__contains__(model_id)
Checks if the model is contained in the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether the model is in the manager. |
Source code in inference/core/managers/base.py
487 488 489 490 491 492 493 494 495 496 | |
__getitem__
¶
__getitem__(key)
Retrieve a model from the manager by key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
The model corresponding to the key. |
Source code in inference/core/managers/base.py
498 499 500 501 502 503 504 505 506 507 | |
__len__
¶
__len__()
Retrieve the number of models in the manager.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of models in the manager. |
Source code in inference/core/managers/base.py
509 510 511 512 513 514 515 | |
add_model
¶
add_model(
model_id,
api_key,
model_id_alias=None,
endpoint_type=ModelEndpointType.ORT,
countinference=None,
service_secret=None,
)
Adds a new model to the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
model
|
Model
|
The model instance. |
required |
endpoint_type
|
ModelEndpointType
|
The endpoint type to use for the model. |
ORT
|
Source code in inference/core/managers/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
check_for_model
¶
check_for_model(model_id)
Checks whether the model with the given ID is in the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Raises:
| Type | Description |
|---|---|
InferenceModelNotFound
|
If the model is not found in the manager. |
Source code in inference/core/managers/base.py
159 160 161 162 163 164 165 166 167 168 169 | |
clear
¶
clear()
Removes all models from the manager.
Source code in inference/core/managers/base.py
473 474 475 476 477 | |
get_class_names
¶
get_class_names(model_id)
Retrieves the class names for a given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Type | Description |
|---|---|
|
List[str]: The class names of the model. |
Source code in inference/core/managers/base.py
424 425 426 427 428 429 430 431 432 433 434 | |
get_task_type
¶
get_task_type(model_id, api_key=None)
Retrieves the task type for a given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The task type of the model. |
Source code in inference/core/managers/base.py
436 437 438 439 440 441 442 443 444 445 446 | |
infer_from_request
async
¶
infer_from_request(model_id, request, **kwargs)
Runs inference on the specified model with the given request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The response from the inference. |
Source code in inference/core/managers/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
infer_from_request_sync
¶
infer_from_request_sync(model_id, request, **kwargs)
Runs inference on the specified model with the given request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The response from the inference. |
Source code in inference/core/managers/base.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
init_pingback
¶
init_pingback()
Initializes pingback mechanism.
Source code in inference/core/managers/base.py
54 55 56 57 58 59 60 | |
keys
¶
keys()
Retrieve the keys (model identifiers) from the manager.
Returns:
| Type | Description |
|---|---|
|
List[str]: The keys of the models in the manager. |
Source code in inference/core/managers/base.py
517 518 519 520 521 522 523 | |
make_response
¶
make_response(model_id, predictions, *args, **kwargs)
Creates a response object from the model's predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
predictions
|
List[List[float]]
|
The model's predictions. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The created response object. |
Source code in inference/core/managers/base.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
models
¶
models()
Retrieve the models dictionary from the manager.
Returns:
| Type | Description |
|---|---|
Dict[str, Model]
|
Dict[str, Model]: The keys of the models in the manager. |
Source code in inference/core/managers/base.py
525 526 527 528 529 530 531 | |
postprocess
¶
postprocess(
model_id,
predictions,
preprocess_return_metadata,
*args,
**kwargs
)
Processes the model's predictions after inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
predictions
|
ndarray
|
The model's predictions. |
required |
Returns:
| Type | Description |
|---|---|
List[List[float]]
|
List[List[float]]: The post-processed predictions. |
Source code in inference/core/managers/base.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
predict
¶
predict(model_id, *args, **kwargs)
Runs prediction on the specified model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ...]
|
np.ndarray: The predictions from the model. |
Source code in inference/core/managers/base.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
preprocess
¶
preprocess(model_id, request)
Preprocesses the request before inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, PreprocessReturnMetadata]
|
Tuple[np.ndarray, List[Tuple[int, int]]]: The preprocessed data. |
Source code in inference/core/managers/base.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
remove
¶
remove(model_id, delete_from_disk=True)
Removes a model from the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Source code in inference/core/managers/base.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
inference.core.managers.metrics
¶
Functions¶
get_container_stats
¶
get_container_stats(docker_socket_path)
Gets the container stats. Returns: dict: A dictionary containing the container stats.
Source code in inference/core/managers/metrics.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
get_model_metrics
¶
get_model_metrics(
inference_server_id, model_id, min=-1, max=float("inf")
)
Gets the metrics for a given model between a specified time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id
|
str
|
The identifier of the device. |
required |
model_id
|
str
|
The identifier of the model. |
required |
start
|
float
|
The starting timestamp of the time range. Defaults to -1. |
required |
stop
|
float
|
The ending timestamp of the time range. Defaults to float("inf"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the metrics of the model: - num_inferences (int): The number of inferences made. - avg_inference_time (float): The average inference time. - num_errors (int): The number of errors occurred. |
Source code in inference/core/managers/metrics.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_system_info
¶
get_system_info()
Collects system information such as platform, architecture, hostname, IP address, MAC address, and processor details.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing detailed system information. |
Source code in inference/core/managers/metrics.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
inference.core.managers.model_load_collector
¶
Classes¶
ModelLoadCollector
¶
Thread-safe collector for model cold start events during a request.
A single instance is shared across all threads handling a single request. Each entry stores a model_id alongside the load time.
Mirrors the design of RemoteProcessingTimeCollector from inference_sdk.
Source code in inference/core/managers/model_load_collector.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
Functions¶
summarize
¶
summarize(max_detail_bytes=4096)
Return (total_load_time, entries_json_or_none).
Returns the total model load time and a JSON string of individual entries. If the JSON exceeds max_detail_bytes, the detail string is omitted (None).
Source code in inference/core/managers/model_load_collector.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
RequestModelIds
¶
Thread-safe set of model IDs used during a request.
Source code in inference/core/managers/model_load_collector.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
inference.core.managers.pingback
¶
Classes¶
PingbackInfo
¶
Class responsible for managing pingback information for Roboflow.
This class initializes a scheduler to periodically post data to Roboflow, containing information about the models, container, and device.
Attributes:
| Name | Type | Description |
|---|---|---|
scheduler |
BackgroundScheduler
|
A scheduler for running jobs in the background. |
model_manager |
ModelManager
|
Reference to the model manager object. |
process_startup_time |
str
|
Unix timestamp indicating when the process started. |
METRICS_URL |
str
|
URL to send the pingback data to. |
system_info |
dict
|
Information about the system. |
window_start_timestamp |
str
|
Unix timestamp indicating the start of the current window. |
Source code in inference/core/managers/pingback.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Functions¶
__init__
¶
__init__(manager)
Initializes PingbackInfo with the given manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager
|
ModelManager
|
Reference to the model manager object. |
required |
Source code in inference/core/managers/pingback.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
post_data
¶
post_data(model_manager)
Posts data to Roboflow about the models, container, device, and other relevant metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_manager
|
ModelManager
|
Reference to the model manager object. |
required |
The data is collected and reset for the next window, and a POST request is made to the pingback URL.
Source code in inference/core/managers/pingback.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
start
¶
start()
Starts the scheduler to periodically post data to Roboflow.
If METRICS_ENABLED is False, a warning is logged, and the method returns without starting the scheduler.
Source code in inference/core/managers/pingback.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
stop
¶
stop()
Stops the scheduler.
Source code in inference/core/managers/pingback.py
99 100 101 | |
Functions¶
inference.core.managers.prometheus
¶
Classes¶
CustomCollector
¶
Bases: Collector
Source code in inference/core/managers/prometheus.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
InferenceInstrumentator
¶
Class responsible for managing the Prometheus metrics for the inference server.
This class inititalizes the Prometheus Instrumentator and exposes the metrics endpoint.
Source code in inference/core/managers/prometheus.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
Functions¶
core/managers/decorators¶
inference.core.managers.decorators.base
¶
Classes¶
ModelManagerDecorator
¶
Bases: ModelManager
Basic decorator, it acts like a ModelManager and contains a ModelManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_manager
|
ModelManager
|
Instance of a ModelManager. |
required |
Methods:
| Name | Description |
|---|---|
add_model |
Adds a model to the manager. |
infer |
Processes a complete inference request. |
infer_only |
Performs only the inference part of a request. |
preprocess |
Processes the preprocessing part of a request. |
get_task_type |
Gets the task type associated with a model. |
get_class_names |
Gets the class names for a given model. |
remove |
Removes a model from the manager. |
__len__ |
Returns the number of models in the manager. |
__getitem__ |
Retrieves a model by its ID. |
__contains__ |
Checks if a model exists in the manager. |
keys |
Returns the keys (model IDs) from the manager. |
Source code in inference/core/managers/decorators/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
Functions¶
__contains__
¶
__contains__(model_id)
Checks if a model exists in the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the model exists, False otherwise. |
Source code in inference/core/managers/decorators/base.py
188 189 190 191 192 193 194 195 196 197 | |
__getitem__
¶
__getitem__(key)
Retrieves a model by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
The model instance. |
Source code in inference/core/managers/decorators/base.py
177 178 179 180 181 182 183 184 185 186 | |
__init__
¶
__init__(model_manager)
Initializes the decorator with an instance of a ModelManager.
Source code in inference/core/managers/decorators/base.py
42 43 44 | |
__len__
¶
__len__()
Returns the number of models in the manager.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of models. |
Source code in inference/core/managers/decorators/base.py
169 170 171 172 173 174 175 | |
add_model
¶
add_model(
model_id,
api_key,
model_id_alias=None,
endpoint_type=ModelEndpointType.ORT,
countinference=None,
service_secret=None,
)
Adds a model to the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
model
|
Model
|
The model instance. |
required |
endpoint_type
|
ModelEndpointType
|
The endpoint type to use for the model. |
ORT
|
Source code in inference/core/managers/decorators/base.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
get_class_names
¶
get_class_names(model_id)
Gets the class names for a given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
The identifier of the model. |
required |
Returns:
| Type | Description |
|---|---|
|
List of class names. |
Source code in inference/core/managers/decorators/base.py
147 148 149 150 151 152 153 154 155 156 | |
get_task_type
¶
get_task_type(model_id, api_key=None)
Gets the task type associated with a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The task type. |
Source code in inference/core/managers/decorators/base.py
134 135 136 137 138 139 140 141 142 143 144 145 | |
infer_from_request
async
¶
infer_from_request(model_id, request, **kwargs)
Processes a complete inference request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The response from the inference. |
Source code in inference/core/managers/decorators/base.py
80 81 82 83 84 85 86 87 88 89 90 91 92 | |
infer_from_request_sync
¶
infer_from_request_sync(model_id, request, **kwargs)
Processes a complete inference request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The response from the inference. |
Source code in inference/core/managers/decorators/base.py
94 95 96 97 98 99 100 101 102 103 104 105 106 | |
infer_only
¶
infer_only(
model_id, request, img_in, img_dims, batch_size=None
)
Performs only the inference part of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
The request to process. |
required | |
img_in
|
Input image. |
required | |
img_dims
|
Image dimensions. |
required | |
batch_size
|
int
|
Batch size. |
None
|
Returns:
| Type | Description |
|---|---|
|
Response from the inference-only operation. |
Source code in inference/core/managers/decorators/base.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
keys
¶
keys()
Returns the keys (model IDs) from the manager.
Returns:
| Type | Description |
|---|---|
|
List of keys (model IDs). |
Source code in inference/core/managers/decorators/base.py
199 200 201 202 203 204 205 | |
preprocess
¶
preprocess(model_id, request)
Processes the preprocessing part of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to preprocess. |
required |
Source code in inference/core/managers/decorators/base.py
125 126 127 128 129 130 131 132 | |
remove
¶
remove(model_id, delete_from_disk=True)
Removes a model from the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
The removed model. |
Source code in inference/core/managers/decorators/base.py
158 159 160 161 162 163 164 165 166 167 | |
inference.core.managers.decorators.locked_load
¶
Classes¶
LockedLoadModelManagerDecorator
¶
Bases: ModelManagerDecorator
Must acquire lock to load model
Source code in inference/core/managers/decorators/locked_load.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
inference.core.managers.decorators.logger
¶
Classes¶
WithLogger
¶
Bases: ModelManagerDecorator
Logger Decorator, it logs what's going on inside the manager.
Source code in inference/core/managers/decorators/logger.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
Functions¶
add_model
¶
add_model(
model_id,
api_key,
model_id_alias=None,
endpoint_type=ModelEndpointType.ORT,
countinference=None,
service_secret=None,
)
Adds a model to the manager and logs the action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
model
|
Model
|
The model instance. |
required |
Returns:
| Type | Description |
|---|---|
|
The result of the add_model method from the superclass. |
Source code in inference/core/managers/decorators/logger.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
infer_from_request
async
¶
infer_from_request(model_id, request, **kwargs)
Processes a complete inference request and logs both the request and response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The response from the inference. |
Source code in inference/core/managers/decorators/logger.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
infer_from_request_sync
¶
infer_from_request_sync(model_id, request, **kwargs)
Processes a complete inference request and logs both the request and response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model. |
required |
request
|
InferenceRequest
|
The request to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
InferenceResponse
|
The response from the inference. |
Source code in inference/core/managers/decorators/logger.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
remove
¶
remove(model_id, delete_from_disk=True)
Removes a model from the manager and logs the action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier of the model to remove. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
The removed model. |
Source code in inference/core/managers/decorators/logger.py
76 77 78 79 80 81 82 83 84 85 86 87 | |
core/models¶
Base model classes and common prediction logic shared across model types.
inference.core.models.base
¶
Classes¶
BaseInference
¶
General inference class.
This class provides a basic interface for inference tasks.
Source code in inference/core/models/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
Functions¶
infer
¶
infer(image, **kwargs)
Runs inference on given data. - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Source code in inference/core/models/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
infer_from_request
¶
infer_from_request(request)
Runs inference on a request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
InferenceRequest
|
The request object. |
required |
Returns:
| Type | Description |
|---|---|
Union[InferenceResponse, List[InferenceResponse]]
|
Union[CVInferenceResponse, List[CVInferenceResponse]]: The response object(s). |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by a subclass. |
Source code in inference/core/models/base.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
make_response
¶
make_response(*args, **kwargs)
Constructs an object detection response.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by a subclass. |
Source code in inference/core/models/base.py
66 67 68 69 70 71 72 73 74 | |
Model
¶
Bases: BaseInference
Base Inference Model (Inherits from BaseInference to define the needed methods)
This class provides the foundational methods for inference and logging, and can be extended by specific models.
Methods:
| Name | Description |
|---|---|
log |
Print the given message. |
clear_cache |
Clears any cache if necessary. |
Source code in inference/core/models/base.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
Functions¶
clear_cache
¶
clear_cache(delete_from_disk=True)
Clears any cache if necessary. This method should be implemented in derived classes as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/base.py
95 96 97 98 99 100 101 | |
infer_from_request
¶
infer_from_request(request)
Perform inference based on the details provided in the request, and return the associated responses. The function can handle both single and multiple image inference requests. Optionally, it also provides a visualization of the predictions if requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
InferenceRequest
|
The request object containing details for inference, such as the image or images to process, any classes to filter by, and whether or not to visualize the predictions. |
required |
Returns:
| Type | Description |
|---|---|
Union[List[InferenceResponse], InferenceResponse]
|
Union[List[InferenceResponse], InferenceResponse]: A list of response objects if the request contains |
Union[List[InferenceResponse], InferenceResponse]
|
multiple images, or a single response object if the request contains one image. Each response object |
Union[List[InferenceResponse], InferenceResponse]
|
contains details about the segmented instances, the time taken for inference, and optionally, a visualization. |
Examples:
>>> request = InferenceRequest(image=my_image, visualize_predictions=True)
>>> response = infer_from_request(request)
>>> print(response.time) # Prints the time taken for inference
0.125
>>> print(response.visualization) # Accesses the visualization of the prediction if available
Notes
- The processing time for each response is included within the response itself.
- If
visualize_predictionsis set to True in the request, a visualization of the prediction is also included in the response.
Source code in inference/core/models/base.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
log
¶
log(m)
Prints the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
str
|
The message to print. |
required |
Source code in inference/core/models/base.py
87 88 89 90 91 92 93 | |
make_response
¶
make_response(*args, **kwargs)
Makes an inference response from the given arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
InferenceResponse |
Union[InferenceResponse, List[InferenceResponse]]
|
The inference response. |
Source code in inference/core/models/base.py
150 151 152 153 154 155 156 157 158 159 160 161 162 | |
inference.core.models.classification_base
¶
Classes¶
ClassificationBaseOnnxRoboflowInferenceModel
¶
Bases: OnnxRoboflowInferenceModel
Base class for ONNX models for Roboflow classification inference.
Attributes:
| Name | Type | Description |
|---|---|---|
multiclass |
bool
|
Whether the classification is multi-class or not. |
Methods:
| Name | Description |
|---|---|
get_infer_bucket_file_list |
Get the list of required files for inference. |
softmax |
Compute softmax values for a given set of scores. |
infer |
ClassificationInferenceRequest) -> Union[List[Union[ClassificationInferenceResponse, MultiLabelClassificationInferenceResponse]], Union[ClassificationInferenceResponse, MultiLabelClassificationInferenceResponse]]: Perform inference on a given request and return the response. |
draw_predictions |
Draw prediction visuals on an image. |
Source code in inference/core/models/classification_base.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
Functions¶
__init__
¶
__init__(*args, **kwargs)
Initialize the model, setting whether it is multiclass or not.
Source code in inference/core/models/classification_base.py
45 46 47 48 | |
draw_predictions
¶
draw_predictions(inference_request, inference_response)
Draw prediction visuals on an image.
This method overlays the predictions on the input image, including drawing rectangles and text to visualize the predicted classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
The request object containing the image and parameters. |
required | |
inference_response
|
The response object containing the predictions and other details. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The bytes of the visualized image in JPEG format. |
Source code in inference/core/models/classification_base.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["environment.json"]. |
Source code in inference/core/models/classification_base.py
123 124 125 126 127 128 129 | |
infer
¶
infer(
image,
disable_preproc_auto_orient=False,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
return_image_dims=False,
**kwargs
)
Perform inference on the provided image(s) and return the predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to be processed. - can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc. |
required |
disable_preproc_auto_orient
|
bool
|
If true, the auto orient preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_contrast
|
bool
|
If true, the auto contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
return_image_dims
|
bool
|
If set to True, the function will also return the dimensions of the image. Defaults to False. |
False
|
**kwargs
|
Additional parameters to customize the inference process. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Union[List[np.array], np.array, Tuple[List[np.array], List[Tuple[int, int]]], Tuple[np.array, Tuple[int, int]]]: |
|
|
If |
|
|
If |
|
|
If |
|
|
If |
Notes
- The input image(s) will be preprocessed (normalized and reshaped) before inference.
- This function uses an ONNX session to perform inference on the input image(s).
Source code in inference/core/models/classification_base.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
infer_from_request
¶
infer_from_request(request)
Handle an inference request to produce an appropriate response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationInferenceRequest
|
The request object encapsulating the image(s) and relevant parameters. |
required |
Returns:
| Type | Description |
|---|---|
Union[List[InferenceResponse], InferenceResponse]
|
Union[List[InferenceResponse], InferenceResponse]: The response object(s) containing the predictions, visualization, and other pertinent details. If a list of images was provided, a list of responses is returned. Otherwise, a single response is returned. |
Notes
- Starts a timer at the beginning to calculate inference time.
- Processes the image(s) through the
infermethod. - Generates the appropriate response object(s) using
make_response. - Calculates and sets the time taken for inference.
- If visualization is requested, the predictions are drawn on the image.
Source code in inference/core/models/classification_base.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
make_response
¶
make_response(
predictions, img_dims, confidence=0.5, **kwargs
)
Create response objects for the given predictions and image dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list
|
List of prediction arrays from the inference process. |
required |
img_dims
|
list
|
List of tuples indicating the dimensions (width, height) of each image. |
required |
confidence
|
float
|
Confidence threshold for filtering predictions. Defaults to 0.5. |
0.5
|
**kwargs
|
Additional parameters to influence the response creation process. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[ClassificationInferenceResponse, List[ClassificationInferenceResponse]]
|
Union[ClassificationInferenceResponse, List[ClassificationInferenceResponse]]: A response object or a list of response objects encapsulating the prediction details. |
Notes
- If the model is multiclass, a
MultiLabelClassificationInferenceResponseis generated for each image. - If the model is not multiclass, a
ClassificationInferenceResponseis generated for each image. - Predictions below the confidence threshold are filtered out.
Source code in inference/core/models/classification_base.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
softmax
staticmethod
¶
softmax(x)
Compute softmax values for each set of scores in x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
The input array containing the scores. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The softmax values for each set of scores. |
Source code in inference/core/models/classification_base.py
370 371 372 373 374 375 376 377 378 379 380 381 | |
inference.core.models.inference_models_adapters
¶
Classes¶
InferenceModelsClassificationAdapter
¶
Bases: Model
Source code in inference/core/models/inference_models_adapters.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
Functions¶
clear_cache
¶
clear_cache(delete_from_disk=True)
Clears any cache if necessary. TODO: Implement this to delete the cache from the experimental model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/inference_models_adapters.py
672 673 674 675 676 677 678 | |
infer_from_request
¶
infer_from_request(request)
Handle an inference request to produce an appropriate response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationInferenceRequest
|
The request object encapsulating the image(s) and relevant parameters. |
required |
Returns:
| Type | Description |
|---|---|
Union[List[InferenceResponse], InferenceResponse]
|
Union[List[InferenceResponse], InferenceResponse]: The response object(s) containing the predictions, visualization, and other pertinent details. If a list of images was provided, a list of responses is returned. Otherwise, a single response is returned. |
Notes
- Starts a timer at the beginning to calculate inference time.
- Processes the image(s) through the
infermethod. - Generates the appropriate response object(s) using
make_response. - Calculates and sets the time taken for inference.
- If visualization is requested, the predictions are drawn on the image.
Source code in inference/core/models/inference_models_adapters.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
InferenceModelsInstanceSegmentationAdapter
¶
Bases: Model
Source code in inference/core/models/inference_models_adapters.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
Functions¶
clear_cache
¶
clear_cache(delete_from_disk=True)
Clears any cache if necessary. TODO: Implement this to delete the cache from the experimental model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/inference_models_adapters.py
350 351 352 353 354 355 356 | |
draw_predictions
¶
draw_predictions(inference_request, inference_response)
Draw predictions from an inference response onto the original image provided by an inference request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
ObjectDetectionInferenceRequest
|
The inference request containing the image on which to draw predictions |
required |
inference_response
|
ObjectDetectionInferenceResponse
|
The inference response containing predictions to be drawn |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
bytes
|
A base64 encoded image string |
Source code in inference/core/models/inference_models_adapters.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
InferenceModelsKeyPointsDetectionAdapter
¶
Bases: Model
Source code in inference/core/models/inference_models_adapters.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
Functions¶
clear_cache
¶
clear_cache(delete_from_disk=True)
Clears any cache if necessary. TODO: Implement this to delete the cache from the experimental model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/inference_models_adapters.py
528 529 530 531 532 533 534 | |
draw_predictions
¶
draw_predictions(inference_request, inference_response)
Draw predictions from an inference response onto the original image provided by an inference request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
ObjectDetectionInferenceRequest
|
The inference request containing the image on which to draw predictions |
required |
inference_response
|
ObjectDetectionInferenceResponse
|
The inference response containing predictions to be drawn |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
bytes
|
A base64 encoded image string |
Source code in inference/core/models/inference_models_adapters.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
InferenceModelsObjectDetectionAdapter
¶
Bases: Model
Source code in inference/core/models/inference_models_adapters.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
Functions¶
clear_cache
¶
clear_cache(delete_from_disk=True)
Clears any cache if necessary. TODO: Implement this to delete the cache from the experimental model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/inference_models_adapters.py
199 200 201 202 203 204 205 | |
draw_predictions
¶
draw_predictions(inference_request, inference_response)
Draw predictions from an inference response onto the original image provided by an inference request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
ObjectDetectionInferenceRequest
|
The inference request containing the image on which to draw predictions |
required |
inference_response
|
ObjectDetectionInferenceResponse
|
The inference response containing predictions to be drawn |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
bytes
|
A base64 encoded image string |
Source code in inference/core/models/inference_models_adapters.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
InferenceModelsSemanticSegmentationAdapter
¶
Bases: Model
Source code in inference/core/models/inference_models_adapters.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
Functions¶
clear_cache
¶
clear_cache(delete_from_disk=True)
Clears any cache if necessary. TODO: Implement this to delete the cache from the experimental model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/inference_models_adapters.py
965 966 967 968 969 970 971 | |
Functions¶
draw_predictions
¶
draw_predictions(
inference_request, inference_response, class_names
)
Draw prediction visuals on an image.
This method overlays the predictions on the input image, including drawing rectangles and text to visualize the predicted classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
The request object containing the image and parameters. |
required | |
inference_response
|
The response object containing the predictions and other details. |
required | |
class_names
|
List[str]
|
List of class names corresponding to the model's classes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The bytes of the visualized image in JPEG format. |
Source code in inference/core/models/inference_models_adapters.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | |
inference.core.models.instance_segmentation_base
¶
Classes¶
InstanceSegmentationBaseOnnxRoboflowInferenceModel
¶
Bases: OnnxRoboflowInferenceModel
Roboflow ONNX Instance Segmentation model.
This class implements an instance segmentation specific inference method for ONNX models provided by Roboflow.
Source code in inference/core/models/instance_segmentation_base.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
Functions¶
infer
¶
infer(
image,
class_agnostic_nms=False,
confidence=DEFAULT_CONFIDENCE,
disable_preproc_auto_orient=False,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
iou_threshold=DEFAULT_IOU_THRESH,
mask_decode_mode=DEFAULT_MASK_DECODE_MODE,
max_candidates=DEFAULT_MAX_CANDIDATES,
max_detections=DEFAUlT_MAX_DETECTIONS,
return_image_dims=False,
tradeoff_factor=DEFAULT_TRADEOFF_FACTOR,
**kwargs
)
Process an image or list of images for instance segmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
An image or a list of images for processing. - can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc. |
required |
class_agnostic_nms
|
bool
|
Whether to use class-agnostic non-maximum suppression. Defaults to False. |
False
|
confidence
|
float
|
Confidence threshold for predictions. Defaults to 0.4. |
DEFAULT_CONFIDENCE
|
iou_threshold
|
float
|
IoU threshold for non-maximum suppression. Defaults to 0.3. |
DEFAULT_IOU_THRESH
|
mask_decode_mode
|
str
|
Decoding mode for masks. Choices are "accurate", "tradeoff", and "fast". Defaults to "accurate". |
DEFAULT_MASK_DECODE_MODE
|
max_candidates
|
int
|
Maximum number of candidate detections. Defaults to 3000. |
DEFAULT_MAX_CANDIDATES
|
max_detections
|
int
|
Maximum number of detections after non-maximum suppression. Defaults to 300. |
DEFAUlT_MAX_DETECTIONS
|
return_image_dims
|
bool
|
Whether to return the dimensions of the processed images. Defaults to False. |
False
|
tradeoff_factor
|
float
|
Tradeoff factor used when |
DEFAULT_TRADEOFF_FACTOR
|
disable_preproc_auto_orient
|
bool
|
If true, the auto orient preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_contrast
|
bool
|
If true, the auto contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
**kwargs
|
Additional parameters to customize the inference process. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[PREDICTIONS_TYPE, Tuple[PREDICTIONS_TYPE, List[Tuple[int, int]]]]
|
Union[List[List[List[float]]], Tuple[List[List[List[float]]], List[Tuple[int, int]]]]: The list of predictions, with each prediction being a list of lists. Optionally, also returns the dimensions of the processed images. |
Raises:
| Type | Description |
|---|---|
InvalidMaskDecodeArgument
|
If an invalid |
Notes
- Processes input images and normalizes them.
- Makes predictions using the ONNX runtime.
- Applies non-maximum suppression to the predictions.
- Decodes the masks according to the specified mode.
Source code in inference/core/models/instance_segmentation_base.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
make_response
¶
make_response(
predictions, masks, img_dims, class_filter=[], **kwargs
)
Create instance segmentation inference response objects for the provided predictions and masks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[List[List[float]]]
|
List of prediction data, one for each image. |
required |
masks
|
List[List[List[float]]]
|
List of masks corresponding to the predictions. |
required |
img_dims
|
List[Tuple[int, int]]
|
List of image dimensions corresponding to the processed images. |
required |
class_filter
|
List[str]
|
List of class names to filter predictions by. Defaults to an empty list (no filtering). |
[]
|
Returns:
| Type | Description |
|---|---|
Union[InstanceSegmentationInferenceResponse, List[InstanceSegmentationInferenceResponse]]
|
Union[InstanceSegmentationInferenceResponse, List[InstanceSegmentationInferenceResponse]]: A single instance segmentation response or a list of instance segmentation responses based on the number of processed images. |
Notes
- For each image, constructs an
InstanceSegmentationInferenceResponseobject. - Each response contains a list of
InstanceSegmentationPredictionobjects.
Source code in inference/core/models/instance_segmentation_base.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
predict
¶
predict(img_in, **kwargs)
Runs inference on the ONNX model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
The preprocessed image(s) to run inference on. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: The ONNX model predictions and the ONNX model protos. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by a subclass. |
Source code in inference/core/models/instance_segmentation_base.py
277 278 279 280 281 282 283 284 285 286 287 288 289 | |
Functions¶
inference.core.models.keypoints_detection_base
¶
Classes¶
KeypointsDetectionBaseOnnxRoboflowInferenceModel
¶
Bases: ObjectDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX Object detection model. This class implements an object detection specific infer method.
Source code in inference/core/models/keypoints_detection_base.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
Functions¶
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Returns the list of files to be downloaded from the inference bucket for ONNX model.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of filenames specific to ONNX models. |
Source code in inference/core/models/keypoints_detection_base.py
38 39 40 41 42 43 44 | |
make_response
¶
make_response(
predictions,
img_dims,
class_filter=None,
*args,
**kwargs
)
Constructs object detection response objects based on predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[List[float]]
|
The list of predictions. |
required |
img_dims
|
List[Tuple[int, int]]
|
Dimensions of the images. |
required |
class_filter
|
Optional[List[str]]
|
A list of class names to filter, if provided. |
None
|
Returns:
| Type | Description |
|---|---|
List[KeypointsDetectionInferenceResponse]
|
List[KeypointsDetectionInferenceResponse]: A list of response objects containing keypoints detection predictions. |
Source code in inference/core/models/keypoints_detection_base.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
postprocess
¶
postprocess(
predictions,
preproc_return_metadata,
class_agnostic_nms=DEFAULT_CLASS_AGNOSTIC_NMS,
confidence=DEFAULT_CONFIDENCE,
iou_threshold=DEFAULT_IOU_THRESH,
max_candidates=DEFAULT_MAX_CANDIDATES,
max_detections=DEFAUlT_MAX_DETECTIONS,
return_image_dims=False,
**kwargs
)
Postprocesses the object detection predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
ndarray
|
Raw predictions from the model. |
required |
img_dims
|
List[Tuple[int, int]]
|
Dimensions of the images. |
required |
class_agnostic_nms
|
bool
|
Whether to apply class-agnostic non-max suppression. Default is False. |
DEFAULT_CLASS_AGNOSTIC_NMS
|
confidence
|
float
|
Confidence threshold for filtering detections. Default is 0.5. |
DEFAULT_CONFIDENCE
|
iou_threshold
|
float
|
IoU threshold for non-max suppression. Default is 0.5. |
DEFAULT_IOU_THRESH
|
max_candidates
|
int
|
Maximum number of candidate detections. Default is 3000. |
DEFAULT_MAX_CANDIDATES
|
max_detections
|
int
|
Maximum number of final detections. Default is 300. |
DEFAUlT_MAX_DETECTIONS
|
Returns:
| Type | Description |
|---|---|
List[KeypointsDetectionInferenceResponse]
|
List[KeypointsDetectionInferenceResponse]: The post-processed predictions. |
Source code in inference/core/models/keypoints_detection_base.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
Functions¶
inference.core.models.object_detection_base
¶
Classes¶
ObjectDetectionBaseOnnxRoboflowInferenceModel
¶
Bases: OnnxRoboflowInferenceModel
Roboflow ONNX Object detection model. This class implements an object detection specific infer method.
Source code in inference/core/models/object_detection_base.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
Functions¶
infer
¶
infer(
image,
class_agnostic_nms=DEFAULT_CLASS_AGNOSTIC_NMS,
confidence=DEFAULT_CONFIDENCE,
disable_preproc_auto_orient=False,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
iou_threshold=DEFAULT_IOU_THRESH,
fix_batch_size=False,
max_candidates=DEFAULT_MAX_CANDIDATES,
max_detections=DEFAUlT_MAX_DETECTIONS,
return_image_dims=False,
**kwargs
)
Runs object detection inference on one or multiple images and returns the detections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The input image or a list of images to process. - can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc. |
required |
class_agnostic_nms
|
bool
|
Whether to use class-agnostic non-maximum suppression. Defaults to False. |
DEFAULT_CLASS_AGNOSTIC_NMS
|
confidence
|
float
|
Confidence threshold for predictions. Defaults to 0.4. |
DEFAULT_CONFIDENCE
|
iou_threshold
|
float
|
IoU threshold for non-maximum suppression. Defaults to 0.3. |
DEFAULT_IOU_THRESH
|
fix_batch_size
|
bool
|
If True, fix the batch size for predictions. Useful when the model requires a fixed batch size. Defaults to False. |
False
|
max_candidates
|
int
|
Maximum number of candidate detections. Defaults to 3000. |
DEFAULT_MAX_CANDIDATES
|
max_detections
|
int
|
Maximum number of detections after non-maximum suppression. Defaults to 300. |
DEFAUlT_MAX_DETECTIONS
|
return_image_dims
|
bool
|
Whether to return the dimensions of the processed images along with the predictions. Defaults to False. |
False
|
disable_preproc_auto_orient
|
bool
|
If true, the auto orient preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_contrast
|
bool
|
If true, the auto contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
*args
|
Variable length argument list. |
required | |
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Union[List[ObjectDetectionInferenceResponse], ObjectDetectionInferenceResponse]: One or multiple object detection inference responses based on the number of processed images. Each response contains a list of predictions. If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If batching is not enabled for the model and more than one image is passed for processing. |
Source code in inference/core/models/object_detection_base.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
make_response
¶
make_response(
predictions,
img_dims,
class_filter=None,
*args,
**kwargs
)
Constructs object detection response objects based on predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[List[float]]
|
The list of predictions. |
required |
img_dims
|
List[Tuple[int, int]]
|
Dimensions of the images. |
required |
class_filter
|
Optional[List[str]]
|
A list of class names to filter, if provided. |
None
|
Returns:
| Type | Description |
|---|---|
List[ObjectDetectionInferenceResponse]
|
List[ObjectDetectionInferenceResponse]: A list of response objects containing object detection predictions. |
Source code in inference/core/models/object_detection_base.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
postprocess
¶
postprocess(
predictions,
preproc_return_metadata,
class_agnostic_nms=DEFAULT_CLASS_AGNOSTIC_NMS,
confidence=DEFAULT_CONFIDENCE,
iou_threshold=DEFAULT_IOU_THRESH,
max_candidates=DEFAULT_MAX_CANDIDATES,
max_detections=DEFAUlT_MAX_DETECTIONS,
return_image_dims=False,
**kwargs
)
Postprocesses the object detection predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
ndarray
|
Raw predictions from the model. |
required |
img_dims
|
List[Tuple[int, int]]
|
Dimensions of the images. |
required |
class_agnostic_nms
|
bool
|
Whether to apply class-agnostic non-max suppression. Default is False. |
DEFAULT_CLASS_AGNOSTIC_NMS
|
confidence
|
float
|
Confidence threshold for filtering detections. Default is 0.5. |
DEFAULT_CONFIDENCE
|
iou_threshold
|
float
|
IoU threshold for non-max suppression. Default is 0.5. |
DEFAULT_IOU_THRESH
|
max_candidates
|
int
|
Maximum number of candidate detections. Default is 3000. |
DEFAULT_MAX_CANDIDATES
|
max_detections
|
int
|
Maximum number of final detections. Default is 300. |
DEFAUlT_MAX_DETECTIONS
|
Returns:
| Type | Description |
|---|---|
List[ObjectDetectionInferenceResponse]
|
List[ObjectDetectionInferenceResponse]: The post-processed predictions. |
Source code in inference/core/models/object_detection_base.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
predict
¶
predict(img_in, **kwargs)
Runs inference on the ONNX model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
The preprocessed image(s) to run inference on. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: The ONNX model predictions. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented by a subclass. |
Source code in inference/core/models/object_detection_base.py
301 302 303 304 305 306 307 308 309 310 311 312 313 | |
preprocess
¶
preprocess(
image,
disable_preproc_auto_orient=False,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
fix_batch_size=False,
**kwargs
)
Preprocesses an object detection inference request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ObjectDetectionInferenceRequest
|
The request object containing images. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, PreprocessReturnMetadata]
|
Tuple[np.ndarray, List[Tuple[int, int]]]: Preprocessed image inputs and corresponding dimensions. |
Source code in inference/core/models/object_detection_base.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
Functions¶
inference.core.models.roboflow
¶
Classes¶
OnnxRoboflowCoreModel
¶
Bases: RoboflowCoreModel
Roboflow Inference Model that operates using an ONNX model file.
Source code in inference/core/models/roboflow.py
1058 1059 1060 1061 | |
OnnxRoboflowInferenceModel
¶
Bases: RoboflowInferenceModel
Roboflow Inference Model that operates using an ONNX model file.
Source code in inference/core/models/roboflow.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
Attributes¶
weights_file
property
¶
weights_file
Returns the file containing the ONNX model weights.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The file path to the weights file. |
Functions¶
__init__
¶
__init__(
model_id,
onnxruntime_execution_providers=get_onnxruntime_execution_providers(
ONNXRUNTIME_EXECUTION_PROVIDERS
),
*args,
**kwargs
)
Initializes the OnnxRoboflowInferenceModel instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier for the specific ONNX model. |
required |
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/core/models/roboflow.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Returns the list of files to be downloaded from the inference bucket for ONNX model.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of filenames specific to ONNX models. |
Source code in inference/core/models/roboflow.py
899 900 901 902 903 904 905 | |
infer
¶
infer(image, **kwargs)
Runs inference on given data. - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Source code in inference/core/models/roboflow.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
initialize_model
¶
initialize_model(**kwargs)
Initializes the ONNX model, setting up the inference session and other necessary properties.
Source code in inference/core/models/roboflow.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
RoboflowCoreModel
¶
Bases: RoboflowInferenceModel
Base Roboflow inference model (Inherits from CvModel since all Roboflow models are CV models currently).
Source code in inference/core/models/roboflow.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
Attributes¶
weights_file
property
¶
weights_file
Abstract property representing the file containing the model weights. For core models, all model artifacts are handled through get_infer_bucket_file_list method.
Functions¶
__init__
¶
__init__(model_id, api_key=None, **kwargs)
Initializes the RoboflowCoreModel instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier for the specific model. |
required |
api_key
|
[type]
|
The API key for authentication. Defaults to None. |
None
|
Source code in inference/core/models/roboflow.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
download_weights
¶
download_weights()
Downloads the model weights from the configured source.
This method includes handling for AWS access keys and error handling.
Source code in inference/core/models/roboflow.py
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
get_device_id
¶
get_device_id()
Returns the device ID associated with this model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The device ID. |
Source code in inference/core/models/roboflow.py
716 717 718 719 720 721 722 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Abstract method to get the list of files to be downloaded from the inference bucket.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented in subclasses. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of filenames. |
Source code in inference/core/models/roboflow.py
724 725 726 727 728 729 730 731 732 733 734 735 | |
preprocess_image
¶
preprocess_image(image)
Abstract method to preprocess an image.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method must be implemented in subclasses. |
Returns:
| Type | Description |
|---|---|
Image
|
Image.Image: The preprocessed PIL image. |
Source code in inference/core/models/roboflow.py
737 738 739 740 741 742 743 744 745 746 | |
RoboflowInferenceModel
¶
Bases: Model
Base Roboflow inference model.
Source code in inference/core/models/roboflow.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
Attributes¶
weights_file
property
¶
weights_file
Abstract property representing the file containing the model weights.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This property must be implemented in subclasses. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The file path to the weights file. |
Functions¶
__init__
¶
__init__(
model_id,
cache_dir_root=MODEL_CACHE_DIR,
api_key=None,
load_weights=True,
**kwargs
)
Initialize the RoboflowInferenceModel object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The unique identifier for the model. |
required |
cache_dir_root
|
str
|
The root directory for the cache. Defaults to MODEL_CACHE_DIR. |
MODEL_CACHE_DIR
|
api_key
|
str
|
API key for authentication. Defaults to None. |
None
|
Source code in inference/core/models/roboflow.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
cache_file
¶
cache_file(f)
Get the cache file path for a given file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
str
|
Filename. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Full path to the cached file. |
Source code in inference/core/models/roboflow.py
144 145 146 147 148 149 150 151 152 153 | |
clear_cache
¶
clear_cache(delete_from_disk=True)
Clear the cache directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delete_from_disk
|
bool
|
Whether to delete cached files from disk. Defaults to True. |
True
|
Source code in inference/core/models/roboflow.py
155 156 157 158 159 160 161 | |
draw_predictions
¶
draw_predictions(inference_request, inference_response)
Draw predictions from an inference response onto the original image provided by an inference request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
ObjectDetectionInferenceRequest
|
The inference request containing the image on which to draw predictions |
required |
inference_response
|
ObjectDetectionInferenceResponse
|
The inference response containing predictions to be drawn |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
bytes
|
A base64 encoded image string |
Source code in inference/core/models/roboflow.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
get_device_id
¶
get_device_id()
Get the device identifier on which the model is deployed.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Device identifier. |
Source code in inference/core/models/roboflow.py
187 188 189 190 191 192 193 194 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get a list of inference bucket files.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented. |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of inference bucket files. |
Source code in inference/core/models/roboflow.py
196 197 198 199 200 201 202 203 204 205 206 207 | |
get_model_artifacts
¶
get_model_artifacts(
countinference=None, service_secret=None, **kwargs
)
Fetch or load the model artifacts.
Downloads the model artifacts from S3 or the Roboflow API if they are not already cached.
Source code in inference/core/models/roboflow.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
initialize_model
¶
initialize_model(**kwargs)
Initialize the model.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented. |
Source code in inference/core/models/roboflow.py
481 482 483 484 485 486 487 | |
preproc_image
¶
preproc_image(
image,
disable_preproc_auto_orient=False,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
)
Preprocesses an inference request image by loading it, then applying any pre-processing specified by the Roboflow platform, then scaling it to the inference input dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Union[Any, InferenceRequestImage]
|
An object containing information necessary to load the image for inference. |
required |
disable_preproc_auto_orient
|
bool
|
If true, the auto orient preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_contrast
|
bool
|
If true, the contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, Tuple[int, int]]
|
Tuple[np.ndarray, Tuple[int, int]]: A tuple containing a numpy array of the preprocessed image pixel data and a tuple of the images original size. |
Source code in inference/core/models/roboflow.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
preprocess_image
¶
preprocess_image(
image,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
)
Preprocesses the given image using specified preprocessing steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The PIL image to preprocess. |
required |
disable_preproc_contrast
|
bool
|
If true, the contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, Tuple[int, int]]
|
Image.Image: The preprocessed PIL image. |
Source code in inference/core/models/roboflow.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | |
Functions¶
core/models/utils¶
inference.core.models.utils.keypoints
¶
Functions¶
superset_keypoints_count
¶
superset_keypoints_count(keypoints_metadata={})
Returns the number of keypoints in the superset.
Source code in inference/core/models/utils/keypoints.py
7 8 9 10 11 12 13 | |
core/registries¶
Model and block registries for dynamic lookup and plugin discovery.
inference.core.registries.base
¶
Classes¶
ModelRegistry
¶
An object which is able to return model classes based on given model IDs and model types.
Attributes:
| Name | Type | Description |
|---|---|---|
registry_dict |
dict
|
A dictionary mapping model types to model classes. |
Source code in inference/core/registries/base.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
Functions¶
__init__
¶
__init__(registry_dict)
Initializes the ModelRegistry with the given dictionary of registered models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry_dict
|
dict
|
A dictionary mapping model types to model classes. |
required |
Source code in inference/core/registries/base.py
14 15 16 17 18 19 20 | |
get_model
¶
get_model(model_type, model_id, **kwargs)
Returns the model class based on the given model type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
The type of the model to be retrieved. |
required |
model_id
|
str
|
The ID of the model to be retrieved (unused in the current implementation). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
The model class corresponding to the given model type. |
Raises:
| Type | Description |
|---|---|
ModelNotRecognisedError
|
If the model_type is not found in the registry_dict. |
Source code in inference/core/registries/base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
inference.core.registries.roboflow
¶
Classes¶
RoboflowModelRegistry
¶
Bases: ModelRegistry
A Roboflow-specific model registry which gets the model type using the model id, then returns a model class based on the model type.
Source code in inference/core/registries/roboflow.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
Functions¶
get_model
¶
get_model(
model_id,
api_key,
countinference=None,
service_secret=None,
)
Returns the model class based on the given model id and API key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The ID of the model to be retrieved. |
required |
api_key
|
str
|
The API key used to authenticate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
The model class corresponding to the given model ID and type. |
Raises:
| Type | Description |
|---|---|
ModelNotRecognisedError
|
If the model type is not supported or found. |
Source code in inference/core/registries/roboflow.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
Functions¶
get_model_type
¶
get_model_type(
model_id,
api_key=None,
countinference=None,
service_secret=None,
)
Retrieves the model type based on the given model ID and API key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The ID of the model. |
required |
api_key
|
str
|
The API key used to authenticate. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple[TaskType, ModelType]
|
The project task type and the model type. |
Raises:
| Type | Description |
|---|---|
WorkspaceLoadError
|
If the workspace could not be loaded or if the API key is invalid. |
DatasetLoadError
|
If the dataset could not be loaded due to invalid ID, workspace ID or version ID. |
MissingDefaultModelError
|
If default model is not configured and API does not provide this info |
MalformedRoboflowAPIResponseError
|
Roboflow API responds in invalid format. |
Source code in inference/core/registries/roboflow.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
core/utils¶
General-purpose utilities: image encoding, file I/O, hashing, URL handling, and more.
inference.core.utils.container
¶
Functions¶
is_docker_socket_mounted
¶
is_docker_socket_mounted(docker_socket_path)
Check if the given path is a mounted Docker socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docker_socket_path
|
str
|
The path to the socket file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the path is a Unix socket, False otherwise. |
Source code in inference/core/utils/container.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
inference.core.utils.environment
¶
Classes¶
Functions¶
safe_env_to_type
¶
safe_env_to_type(
variable_name, default_value=None, type_constructor=None
)
Converts env variable to specified type, but only if variable is set - otherwise default is returned.
If type_constructor is not given - value of type str will be returned.
Source code in inference/core/utils/environment.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
safe_split_value
¶
safe_split_value(value, delimiter=',')
Splits a separated environment variable into a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The environment variable value to be split. |
required |
delimiter
|
str
|
Delimiter to be used |
','
|
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
list or None: The split values as a list, or None if the input is None. |
Source code in inference/core/utils/environment.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
str2bool
¶
str2bool(value)
Converts an environment variable to a boolean value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str or bool
|
The environment variable value to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
The converted boolean value. |
Raises:
| Type | Description |
|---|---|
InvalidEnvironmentVariableError
|
If the value is not 'true', 'false', or a boolean. |
Source code in inference/core/utils/environment.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
inference.core.utils.file_system
¶
Classes¶
AtomicPath
¶
Context manager for atomic file writes.
Ensures that files are either written completely or not at all, preventing partial/corrupted files from power failures or crashes.
Usage
with AtomicPath(target_path, allow_override=False) as temp_path: # Write to temp_path with open(temp_path, 'w') as f: f.write(data)
File is atomically moved to target_path on successful exit¶
Source code in inference/core/utils/file_system.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
inference.core.utils.image_utils
¶
Classes¶
Functions¶
attempt_loading_image_from_string
¶
attempt_loading_image_from_string(
value, cv_imread_flags=cv2.IMREAD_COLOR
)
Attempt to load an image from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[str, bytes, bytearray, _IOBase]
|
The image data in string format. |
required |
cv_imread_flags
|
int
|
OpenCV flags used for image reading. |
IMREAD_COLOR
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, bool]
|
Tuple[np.ndarray, bool]: A tuple of the loaded image in numpy array format and a boolean flag indicating if the image is in BGR format. |
Source code in inference/core/utils/image_utils.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
choose_image_decoding_flags
¶
choose_image_decoding_flags(disable_preproc_auto_orient)
Choose the appropriate OpenCV image decoding flags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disable_preproc_auto_orient
|
bool
|
Flag to disable preprocessing auto-orientation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
OpenCV image decoding flags. |
Source code in inference/core/utils/image_utils.py
107 108 109 110 111 112 113 114 115 116 117 118 119 | |
convert_gray_image_to_bgr
¶
convert_gray_image_to_bgr(image)
Convert a grayscale image to BGR format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
The grayscale image. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The converted BGR image. |
Source code in inference/core/utils/image_utils.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
encode_image_to_jpeg_bytes
¶
encode_image_to_jpeg_bytes(image, jpeg_quality=90)
Encode a numpy image to JPEG format in bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
The numpy array representing a BGR image. |
required |
jpeg_quality
|
int
|
Quality of the JPEG image. |
90
|
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The JPEG encoded image. |
Source code in inference/core/utils/image_utils.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
extract_image_payload_and_type
¶
extract_image_payload_and_type(value)
Extract the image payload and type from the given value.
This function supports different types of image inputs (e.g., InferenceRequestImage, dict, etc.) and extracts the relevant data and image type for further processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The input value which can be an image or information to derive the image. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Any, Optional[ImageType]]
|
Tuple[Any, Optional[ImageType]]: A tuple containing the extracted image data and the corresponding image type. |
Source code in inference/core/utils/image_utils.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
load_image
¶
load_image(value, disable_preproc_auto_orient=False)
Loads an image based on the specified type and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Image value which could be an instance of InferenceRequestImage, a dict with 'type' and 'value' keys, or inferred based on the value's content. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, bool]
|
Image.Image: The loaded PIL image, converted to RGB. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the specified image type is not supported. |
InvalidNumpyInput
|
If the numpy input method is used and the input data is invalid. |
Source code in inference/core/utils/image_utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
load_image_base64
¶
load_image_base64(value, cv_imread_flags=cv2.IMREAD_COLOR)
Loads an image from a base64 encoded string using OpenCV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Base64 encoded string representing the image. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The loaded image as a numpy array. |
Source code in inference/core/utils/image_utils.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
load_image_from_buffer
¶
load_image_from_buffer(
value, cv_imread_flags=cv2.IMREAD_COLOR
)
Loads an image from a multipart-encoded input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Multipart-encoded input representing the image. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Image.Image: The loaded PIL image. |
Source code in inference/core/utils/image_utils.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
load_image_from_encoded_bytes
¶
load_image_from_encoded_bytes(
value, cv_imread_flags=cv2.IMREAD_COLOR
)
Load an image from encoded bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bytes
|
The byte sequence representing the image. |
required |
cv_imread_flags
|
int
|
OpenCV flags used for image reading. |
IMREAD_COLOR
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The loaded image as a numpy array. |
Source code in inference/core/utils/image_utils.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
load_image_from_numpy_str
¶
load_image_from_numpy_str(value)
Loads an image from a numpy array string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[bytes, str]
|
Base64 string or byte sequence representing the pickled numpy array of the image. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Image.Image: The loaded PIL image. |
Raises:
| Type | Description |
|---|---|
InvalidNumpyInput
|
If the numpy data is invalid. |
Source code in inference/core/utils/image_utils.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
load_image_from_url
¶
load_image_from_url(
value, cv_imread_flags=cv2.IMREAD_COLOR
)
Loads an image from a given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
URL of the image. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Image.Image: The loaded PIL image. |
Source code in inference/core/utils/image_utils.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
load_image_with_inferred_type
¶
load_image_with_inferred_type(
value, cv_imread_flags=cv2.IMREAD_COLOR
)
Load an image by inferring its type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The image data. |
required |
cv_imread_flags
|
int
|
Flags used for OpenCV's imread function. |
IMREAD_COLOR
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, bool]
|
Tuple[np.ndarray, bool]: Loaded image as a numpy array and a boolean indicating if the image is in BGR format. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the image type could not be inferred. |
Source code in inference/core/utils/image_utils.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
load_image_with_known_type
¶
load_image_with_known_type(
value, image_type, cv_imread_flags=cv2.IMREAD_COLOR
)
Load an image using the known image type.
Supports various image types (e.g., NUMPY, PILLOW, etc.) and loads them into a numpy array format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The image data. |
required |
image_type
|
ImageType
|
The type of the image. |
required |
cv_imread_flags
|
int
|
Flags used for OpenCV's imread function. |
IMREAD_COLOR
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, bool]
|
Tuple[np.ndarray, bool]: A tuple of the loaded image as a numpy array and a boolean indicating if the image is in BGR format. |
Source code in inference/core/utils/image_utils.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
np_image_to_base64
¶
np_image_to_base64(image)
Convert a numpy image to a base64 encoded byte string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
The numpy array representing an image. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The base64 encoded image. |
Source code in inference/core/utils/image_utils.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
validate_numpy_image
¶
validate_numpy_image(data)
Validate if the provided data is a valid numpy image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
The numpy array representing an image. |
required |
Raises:
| Type | Description |
|---|---|
InvalidNumpyInput
|
If the provided data is not a valid numpy image. |
Source code in inference/core/utils/image_utils.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
xyxy_to_xywh
¶
xyxy_to_xywh(xyxy)
Convert bounding box format from (xmin, ymin, xmax, ymax) to (xcenter, ycenter, width, height).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xyxy
|
List[int]
|
List containing the coordinates in (xmin, ymin, xmax, ymax) format. |
required |
Returns:
| Type | Description |
|---|---|
|
List[int]: List containing the converted coordinates in (xcenter, ycenter, width, height) format. |
Source code in inference/core/utils/image_utils.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
inference.core.utils.onnx
¶
Functions¶
get_onnxruntime_execution_providers
¶
get_onnxruntime_execution_providers(value)
Extracts the ONNX runtime execution providers from the given string.
The input string is expected to be a comma-separated list, possibly enclosed within square brackets and containing single quotes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string containing the list of ONNX runtime execution providers. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of strings representing each execution provider. |
Source code in inference/core/utils/onnx.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
inference.core.utils.postprocess
¶
Functions¶
cosine_similarity
¶
cosine_similarity(a, b)
Compute the cosine similarity between two vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Vector A. |
required |
b
|
ndarray
|
Vector B. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Union[number, ndarray]
|
Cosine similarity between vectors A and B. |
Source code in inference/core/utils/postprocess.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
crop_mask
¶
crop_mask(masks, boxes)
"Crop" predicted masks by zeroing out everything not in the predicted bbox. Vectorized by Chong (thanks Chong).
Source code in inference/core/utils/postprocess.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
get_static_crop_dimensions
¶
get_static_crop_dimensions(
orig_shape, preproc, disable_preproc_static_crop=False
)
Generates a transformation based on preprocessing configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orig_shape
|
tuple
|
The original shape of the object (e.g., image) - (height, width). |
required |
preproc
|
dict
|
Preprocessing configuration dictionary, containing information such as static cropping. |
required |
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple[Tuple[int, int], Tuple[int, int]]
|
A tuple containing the shift in the x and y directions, and the updated original shape after cropping. |
Source code in inference/core/utils/postprocess.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
mask2multipoly
¶
mask2multipoly(mask)
Find all contours in the mask and return them as a float32 array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
ndarray
|
A binary mask. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Contours represented as a float32 array. |
Source code in inference/core/utils/postprocess.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
mask2poly
¶
mask2poly(mask)
Find contours in the mask and return them as a float32 array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
ndarray
|
A binary mask. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Contours represented as a float32 array. |
Source code in inference/core/utils/postprocess.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
masks2multipoly
¶
masks2multipoly(masks)
Converts binary masks to polygonal segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
ndarray
|
A set of binary masks, where masks are multiplied by 255 and converted to uint8 type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List[ndarray]
|
A list of segments, where each segment is obtained by converting the corresponding mask. |
Source code in inference/core/utils/postprocess.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
masks2poly
¶
masks2poly(masks)
Converts binary masks to polygonal segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
masks
|
ndarray
|
A set of binary masks, where masks are multiplied by 255 and converted to uint8 type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
List[ndarray]
|
A list of segments, where each segment is obtained by converting the corresponding mask. |
Source code in inference/core/utils/postprocess.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
post_process_bboxes
¶
post_process_bboxes(
predictions,
infer_shape,
img_dims,
preproc,
disable_preproc_static_crop=False,
resize_method="Stretch to",
)
Postprocesses each patch of detections by scaling them to the original image coordinates and by shifting them based on a static crop preproc (if applied).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[List[List[float]]]
|
The predictions output from NMS, indices are: batch x prediction x [x1, y1, x2, y2, ...]. |
required |
infer_shape
|
Tuple[int, int]
|
The shape of the inference image. |
required |
img_dims
|
List[Tuple[int, int]]
|
The dimensions of the original image for each batch, indices are: batch x [height, width]. |
required |
preproc
|
dict
|
Preprocessing configuration dictionary. |
required |
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
resize_method
|
str
|
Resize method for image. Defaults to "Stretch to". |
'Stretch to'
|
Returns:
| Type | Description |
|---|---|
List[List[List[float]]]
|
List[List[List[float]]]: The scaled and shifted predictions, indices are: batch x prediction x [x1, y1, x2, y2, ...]. |
Source code in inference/core/utils/postprocess.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
post_process_keypoints
¶
post_process_keypoints(
predictions,
keypoints_start_index,
infer_shape,
img_dims,
preproc,
disable_preproc_static_crop=False,
resize_method="Stretch to",
)
Scales and shifts keypoints based on the given image shapes and preprocessing method.
This function performs polygon scaling and shifting based on the specified resizing method and pre-processing steps. The polygons are transformed according to the ratio and padding between two images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[List[List[float]]]
|
predictions from model |
required |
keypoints_start_index
|
int
|
offset in the 3rd dimension pointing where in the prediction start keypoints [(x, y, cfg), ...] for each keypoint class |
required |
img_dims list of
|
tuple of int
|
Shape of the source image (height, width). |
required |
infer_shape
|
tuple of int
|
Shape of the target image (height, width). |
required |
preproc
|
object
|
Preprocessing details used for generating the transformation. |
required |
resize_method
|
str
|
Resizing method, either "Stretch to", "Fit (black edges) in", "Fit (white edges) in", or "Fit (grey edges) in". Defaults to "Stretch to". |
'Stretch to'
|
disable_preproc_static_crop
|
bool
|
flag to disable static crop |
False
|
Source code in inference/core/utils/postprocess.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | |
post_process_polygons
¶
post_process_polygons(
origin_shape,
polys,
infer_shape,
preproc,
resize_method="Stretch to",
)
Scales and shifts polygons based on the given image shapes and preprocessing method.
This function performs polygon scaling and shifting based on the specified resizing method and pre-processing steps. The polygons are transformed according to the ratio and padding between two images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_shape
|
tuple of int
|
Shape of the source image (height, width). |
required |
infer_shape
|
tuple of int
|
Shape of the target image (height, width). |
required |
polys
|
list of list of tuple
|
List of polygons, where each polygon is represented by a list of (x, y) coordinates. |
required |
preproc
|
object
|
Preprocessing details used for generating the transformation. |
required |
resize_method
|
str
|
Resizing method, either "Stretch to", "Fit (black edges) in", "Fit (white edges) in", or "Fit (grey edges) in". Defaults to "Stretch to". |
'Stretch to'
|
Returns:
| Type | Description |
|---|---|
List[List[Tuple[float, float]]]
|
list of list of tuple: A list of shifted and scaled polygons. |
Source code in inference/core/utils/postprocess.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
process_mask_accurate
¶
process_mask_accurate(protos, masks_in, bboxes, shape)
Returns masks that are the size of the original image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protos
|
ndarray
|
Prototype masks. |
required |
masks_in
|
ndarray
|
Input masks. |
required |
bboxes
|
ndarray
|
Bounding boxes. |
required |
shape
|
tuple
|
Target shape. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Processed masks. |
Source code in inference/core/utils/postprocess.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
process_mask_fast
¶
process_mask_fast(protos, masks_in, bboxes, shape)
Returns masks in their original size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protos
|
ndarray
|
Prototype masks. |
required |
masks_in
|
ndarray
|
Input masks. |
required |
bboxes
|
ndarray
|
Bounding boxes. |
required |
shape
|
tuple
|
Target shape. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Processed masks. |
Source code in inference/core/utils/postprocess.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
process_mask_tradeoff
¶
process_mask_tradeoff(
protos, masks_in, bboxes, shape, tradeoff_factor
)
Returns masks that are the size of the original image with a tradeoff factor applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protos
|
ndarray
|
Prototype masks. |
required |
masks_in
|
ndarray
|
Input masks. |
required |
bboxes
|
ndarray
|
Bounding boxes. |
required |
shape
|
tuple
|
Target shape. |
required |
tradeoff_factor
|
float
|
Tradeoff factor for resizing masks. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Processed masks. |
Source code in inference/core/utils/postprocess.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
sigmoid
¶
sigmoid(x)
Computes the sigmoid function for the given input.
The sigmoid function is defined as: f(x) = 1 / (1 + exp(-x))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float or ndarray
|
Input value or array for which the sigmoid function is to be computed. |
required |
Returns:
| Type | Description |
|---|---|
Union[float, number, ndarray]
|
float or numpy.ndarray: The computed sigmoid value(s). |
Source code in inference/core/utils/postprocess.py
685 686 687 688 689 690 691 692 693 694 695 696 697 | |
inference.core.utils.preprocess
¶
Functions¶
letterbox_image
¶
letterbox_image(image, desired_size, color=(0, 0, 0))
Resize and pad image to fit the desired size, preserving its aspect ratio.
Parameters: - image: numpy array representing the image. - desired_size: tuple (width, height) representing the target dimensions. - color: tuple (B, G, R) representing the color to pad with.
Returns: - letterboxed image.
Source code in inference/core/utils/preprocess.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
prepare
¶
prepare(
image,
preproc,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
)
Prepares an image by applying a series of preprocessing steps defined in the preproc dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The input PIL image object. |
required |
preproc
|
dict
|
Dictionary containing preprocessing steps. Example: { "resize": {"enabled": true, "width": 416, "height": 416, "format": "Stretch to"}, "static-crop": {"y_min": 25, "x_max": 75, "y_max": 75, "enabled": true, "x_min": 25}, "auto-orient": {"enabled": true}, "grayscale": {"enabled": true}, "contrast": {"enabled": true, "type": "Adaptive Equalization"} } |
required |
disable_preproc_contrast
|
bool
|
If true, the contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
ndarray
|
PIL.Image.Image: The preprocessed image object. |
|
tuple |
Tuple[int, int]
|
The dimensions of the image. |
Note
The function uses global flags like DISABLE_PREPROC_AUTO_ORIENT, DISABLE_PREPROC_STATIC_CROP, etc.
to conditionally enable or disable certain preprocessing steps.
Source code in inference/core/utils/preprocess.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
resize_image_keeping_aspect_ratio
¶
resize_image_keeping_aspect_ratio(image, desired_size)
Resize reserving its aspect ratio.
Parameters: - image: numpy array representing the image. - desired_size: tuple (width, height) representing the target dimensions.
Source code in inference/core/utils/preprocess.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
inference.core.utils.torchscript_guard
¶
core/workflows/core_steps/analytics/detection_event_log¶
inference.core.workflows.core_steps.analytics.detection_event_log.v1
¶
Classes¶
DetectionEvent
dataclass
¶
Stores event data for a tracked detection.
Source code in inference/core/workflows/core_steps/analytics/detection_event_log/v1.py
36 37 38 39 40 41 42 43 44 45 46 47 | |
DetectionEventLogBlockV1
¶
Bases: WorkflowBlock
Block that tracks detection events over time.
Maintains a dictionary of tracked objects with: - First seen timestamp and frame - Last seen timestamp and frame - Class name - Frame count (number of frames the object has been seen)
Only logs objects that have been seen for at least frame_threshold frames. Runs cleanup every flush_interval frames, removing events not seen for stale_frames.
Source code in inference/core/workflows/core_steps/analytics/detection_event_log/v1.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
Functions¶
run
¶
run(
image,
detections,
frame_threshold,
flush_interval,
stale_frames,
fallback_fps=1.0,
reference_timestamp=None,
)
Process detections and update the event log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
WorkflowImageData
|
Workflow image data containing video metadata. |
required |
detections
|
Detections
|
Tracked detections with tracker_id from ByteTracker. |
required |
frame_threshold
|
int
|
Minimum frames an object must be seen before logging. |
required |
flush_interval
|
int
|
How often to run stale event cleanup. |
required |
stale_frames
|
int
|
Remove events not seen for this many frames. |
required |
fallback_fps
|
float
|
FPS to use when video metadata doesn't provide FPS. |
1.0
|
reference_timestamp
|
Optional[float]
|
Optional Unix timestamp when video started. When provided, absolute timestamps are included in output. |
None
|
Returns:
| Type | Description |
|---|---|
BlockResult
|
Dictionary containing event_log, detections, total_logged, and total_pending. |
Source code in inference/core/workflows/core_steps/analytics/detection_event_log/v1.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
core/workflows/core_steps/classical_cv/camera_focus¶
inference.core.workflows.core_steps.classical_cv.camera_focus.v1
¶
Classes¶
Functions¶
calculate_brenner_measure
¶
calculate_brenner_measure(
input_image,
text_color=(255, 255, 255),
text_thickness=2,
)
Brenner's focus measure.
Parameters¶
input_image : np.ndarray The input image in grayscale. text_color : Tuple[int, int, int], optional The color of the text displaying the Brenner value, in BGR format. Default is white (255, 255, 255). text_thickness : int, optional The thickness of the text displaying the Brenner value. Default is 2.
Returns¶
Tuple[np.ndarray, float] The Brenner image and the Brenner value.
Source code in inference/core/workflows/core_steps/classical_cv/camera_focus/v1.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
inference.core.workflows.core_steps.classical_cv.camera_focus.v2
¶
Classes¶
Functions¶
visualize_tenengrad_measure
¶
visualize_tenengrad_measure(
input_image,
underexposed_threshold=16,
overexposed_threshold=239,
show_zebra_warnings=True,
grid_overlay="3x3",
show_hud=True,
show_focus_peaking=True,
show_center_marker=True,
detections=None,
)
Tenengrad focus measure with visualization overlay.
Uses Sobel operators to compute gradient magnitudes as a focus metric. Higher values indicate sharper/more in-focus images.
Returns the input image unchanged if no visualizations are enabled.
Source code in inference/core/workflows/core_steps/classical_cv/camera_focus/v2.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
core/workflows/core_steps/classical_cv/contours¶
inference.core.workflows.core_steps.classical_cv.contours.v1
¶
Classes¶
Functions¶
find_and_draw_contours
¶
find_and_draw_contours(
image, color=(255, 0, 255), thickness=3
)
Finds and draws contours on the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input thresholded image. |
required |
color
|
tuple
|
Color of the contour lines in BGR. Defaults to purple (255, 0, 255). |
(255, 0, 255)
|
thickness
|
int
|
Thickness of the contour lines. Defaults to 3. |
3
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple[ndarray, int]
|
Image with contours drawn and number of contours. |
Source code in inference/core/workflows/core_steps/classical_cv/contours/v1.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
core/workflows/core_steps/classical_cv/distance_measurement¶
inference.core.workflows.core_steps.classical_cv.distance_measurement.v1
¶
Functions¶
has_overlap
¶
has_overlap(bbox1, bbox2)
Check if two bounding boxes overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox1
|
Tuple[int, int, int, int]
|
A tuple of (x_min, y_min, x_max, y_max) for the first bounding box. |
required |
bbox2
|
Tuple[int, int, int, int]
|
A tuple of (x_min, y_min, x_max, y_max) for the second bounding box. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the bounding boxes overlap, False otherwise. |
Source code in inference/core/workflows/core_steps/classical_cv/distance_measurement/v1.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
core/workflows/core_steps/classical_cv/image_blur¶
inference.core.workflows.core_steps.classical_cv.image_blur.v1
¶
Classes¶
Functions¶
apply_blur
¶
apply_blur(image, blur_type, ksize=5)
Applies the specified blur to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input image. |
required |
blur_type
|
str
|
Type of blur ('average', 'gaussian', 'median', 'bilateral'). |
required |
ksize
|
int
|
Kernel size for the blur. Defaults to 5. |
5
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Blurred image. |
Source code in inference/core/workflows/core_steps/classical_cv/image_blur/v1.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
core/workflows/core_steps/classical_cv/mask_area_measurement¶
inference.core.workflows.core_steps.classical_cv.mask_area_measurement.v1
¶
Functions¶
compute_detection_areas
¶
compute_detection_areas(detections)
Compute the area of all detections in square pixels.
For bounding-box-only detections, areas are computed in a single vectorized
operation. For detections with segmentation masks, the area is the count of
non-zero mask pixels (via cv2.countNonZero). This correctly handles masks
with holes — hole pixels are zero and are not counted. Falls back to the
bounding box area when the mask pixel count is zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Detections
|
A supervision Detections object. |
required |
Returns:
| Type | Description |
|---|---|
List[float]
|
List of areas in square pixels, one per detection. |
Source code in inference/core/workflows/core_steps/classical_cv/mask_area_measurement/v1.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
core/workflows/core_steps/classical_cv/motion_detection¶
inference.core.workflows.core_steps.classical_cv.motion_detection.v1
¶
Classes¶
Functions¶
clip_contours_to_contour
¶
clip_contours_to_contour(contours, clip_contour)
Clip OpenCV contours to another contour and return clipped OpenCV contours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contours
|
List[ndarray]
|
List of OpenCV contours, each as numpy array of shape (N, 1, 2) |
required |
clip_contour
|
ndarray
|
Clip contour as numpy array of shape (M, 2) with xy points |
required |
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List of clipped OpenCV contours as numpy arrays of shape (N, 1, 2). |
List[ndarray]
|
Only includes contours that overlap with the clip contour. |
Source code in inference/core/workflows/core_steps/classical_cv/motion_detection/v1.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
list_to_contour
¶
list_to_contour(list_of_tuples)
Convert a list of (x, y) tuples to an OpenCV contour format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_of_tuples
|
List[Tuple]
|
List of coordinate tuples [(x1, y1), (x2, y2), ...] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
NumPy array of shape (N, 1, 2) suitable for OpenCV operations |
Source code in inference/core/workflows/core_steps/classical_cv/motion_detection/v1.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
core/workflows/core_steps/classical_cv/pixel_color_count¶
inference.core.workflows.core_steps.classical_cv.pixel_color_count.v1
¶
Classes¶
Functions¶
count_specific_color_pixels
¶
count_specific_color_pixels(image, target_color, tolerance)
Counts the number of pixels that match the target color within the given tolerance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input image. |
required |
target_color
|
Union[str, tuple]
|
Target color in hex format (e.g., '#431112') or BGR tuple (e.g., (18, 17, 67)). |
required |
tolerance
|
int
|
Tolerance for color matching. Defaults to 10. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of pixels that match the target color. |
Source code in inference/core/workflows/core_steps/classical_cv/pixel_color_count/v1.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
core/workflows/core_steps/classical_cv/sift¶
inference.core.workflows.core_steps.classical_cv.sift.v1
¶
Classes¶
Functions¶
apply_sift
¶
apply_sift(image)
Applies SIFT to the image. Args: image: Input image. Returns: np.ndarray: Image with keypoints drawn. list: Keypoints detected. np.ndarray: Descriptors of the keypoints.
Source code in inference/core/workflows/core_steps/classical_cv/sift/v1.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
core/workflows/core_steps/classical_cv/sift_comparison¶
inference.core.workflows.core_steps.classical_cv.sift_comparison.v2
¶
Classes¶
Functions¶
apply_sift
¶
apply_sift(image, visualize=False)
Applies SIFT to the image. Args: image: Input image. visualize: Whether to visualize keypoints on the image. Returns: img_with_kp: Image with keypoints drawn (if visualize is True). kp: List of cv2.KeyPoint objects. keypoints_dicts: List of keypoints as dictionaries. des: Descriptors of the keypoints.
Source code in inference/core/workflows/core_steps/classical_cv/sift_comparison/v2.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
core/workflows/core_steps/classical_cv/size_measurement¶
inference.core.workflows.core_steps.classical_cv.size_measurement.v1
¶
Functions¶
compute_aligned_dimensions
¶
compute_aligned_dimensions(contour)
Compute the width and height of an object based on its contour, ensuring proper orientation.
This function: 1. Finds the minimum area rectangle that encloses the contour 2. Determines which edges correspond to width and height by analyzing their angles 3. Returns dimensions where width is the more horizontal edge and height is the more vertical edge
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contour
|
ndarray
|
Array of points representing the object's contour |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple[float, float]: A tuple of (width_pixels, height_pixels) where: - width_pixels: Length of the more horizontal edge - height_pixels: Length of the more vertical edge |
Note
The function uses angle analysis to ensure consistent width/height assignment regardless of the object's rotation. The edge closer to horizontal (0° or 180°) is always considered the width.
Source code in inference/core/workflows/core_steps/classical_cv/size_measurement/v1.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
get_detection_dimensions
¶
get_detection_dimensions(detection, index)
Retrieve the width and height dimensions of a detected object in pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection
|
Detections
|
Detection object containing masks and/or bounding boxes |
required |
index
|
int
|
Index of the specific detection to analyze |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Optional[float], Optional[float]]
|
Tuple[float, float]: A tuple of (width_pixels, height_pixels) where: - width_pixels: Width of the object in pixels - height_pixels: Height of the object in pixels |
Notes
The function uses two methods to compute dimensions: 1. If a segmentation mask is available: - Extracts the largest contour from the mask - Uses compute_aligned_dimensions() to get orientation-aware measurements 2. If no mask is available: - Falls back to using the bounding box dimensions - Simply computes width and height as box edges
Source code in inference/core/workflows/core_steps/classical_cv/size_measurement/v1.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
horizontal_score
¶
horizontal_score(angle)
Determine how close an angle is to horizontal (0 or 180 degrees). Lower score means more horizontal.
Source code in inference/core/workflows/core_steps/classical_cv/size_measurement/v1.py
128 129 130 131 132 133 134 | |
parse_reference_dimensions
¶
parse_reference_dimensions(reference_dimensions)
Parse reference dimensions from various input formats.
Source code in inference/core/workflows/core_steps/classical_cv/size_measurement/v1.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
core/workflows/core_steps/classical_cv/threshold¶
inference.core.workflows.core_steps.classical_cv.threshold.v1
¶
Classes¶
Functions¶
apply_thresholding
¶
apply_thresholding(
image, threshold_type, thresh_value, max_value
)
Applies the specified thresholding to the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input image in grayscale. |
required |
threshold_type
|
str
|
Type of thresholding ('binary', 'binary_inv', 'trunc', 'tozero', 'tozero_inv', 'adaptive_mean', 'adaptive_gaussian', 'otsu'). |
required |
thresh_value
|
int
|
Threshold value. |
required |
max_value
|
int
|
Maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Image with thresholding applied. |
Source code in inference/core/workflows/core_steps/classical_cv/threshold/v1.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
core/workflows/core_steps/common¶
inference.core.workflows.core_steps.common.utils
¶
Classes¶
Functions¶
remove_unexpected_keys_from_dictionary
¶
remove_unexpected_keys_from_dictionary(
dictionary, expected_keys
)
This function mutates input dictionary
Source code in inference/core/workflows/core_steps/common/utils.py
430 431 432 433 434 435 436 437 438 | |
core/workflows/core_steps/fusion/detections_list_rollup¶
inference.core.workflows.core_steps.fusion.detections_list_rollup.v1
¶
Functions¶
merge_crop_predictions
¶
merge_crop_predictions(
parent_prediction,
child_predictions,
confidence_strategy="max",
overlap_threshold=0.0,
keypoint_merge_threshold=10.0,
)
Merge predictions from multiple crops back to parent image coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_prediction
|
Supervision Detections object that defines the crop locations. Each detection in this prediction represents one crop region. |
required | |
child_predictions
|
List
|
List of Supervision Detections objects from crops. Order matches the detection order in parent_prediction. |
required |
confidence_strategy
|
str
|
How to handle confidence when merging overlaps. Options: "max", "mean", "min" |
'max'
|
overlap_threshold
|
float
|
Minimum IoU/overlap ratio to merge detections (0.0 to 1.0). - 0.0: Only merge if detections touch or overlap at all (default) - >0.0: Only merge if overlap ratio exceeds this threshold - 1.0: Only merge completely overlapping detections |
0.0
|
keypoint_merge_threshold
|
float
|
Maximum distance in pixels to merge keypoints (default: 10). For keypoint detections, merges detections if their average keypoint distance is below this threshold. |
10.0
|
Returns:
| Type | Description |
|---|---|
Tuple
|
Tuple of (detections, crop_zones): |
Tuple
|
|
Tuple
|
|
Source code in inference/core/workflows/core_steps/fusion/detections_list_rollup/v1.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
core/workflows/core_steps/fusion/detections_stitch¶
inference.core.workflows.core_steps.fusion.detections_stitch.v1
¶
Classes¶
Functions¶
move_detections
¶
move_detections(detections, offset, resolution_wh)
Copied from: https://github.com/roboflow/supervision/blob/5123085037ec594524fc8f9d9b71b1cd9f487e8d/supervision/detection/tools/inference_slicer.py#L17-L16 to avoid fragile contract with supervision, as this function is not element of public API.
Source code in inference/core/workflows/core_steps/fusion/detections_stitch/v1.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
core/workflows/core_steps¶
core/workflows/core_steps/models/foundation/anthropic_claude¶
inference.core.workflows.core_steps.models.foundation.anthropic_claude.v3
¶
Classes¶
Functions¶
execute_claude_request
¶
execute_claude_request(
roboflow_api_key,
anthropic_api_key,
system_prompt,
messages,
model_version,
max_tokens,
temperature,
extended_thinking,
thinking_budget_tokens,
)
Route to proxied or direct execution based on API key format.
Source code in inference/core/workflows/core_steps/models/foundation/anthropic_claude/v3.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
core/workflows/core_steps/models/foundation/gaze¶
inference.core.workflows.core_steps.models.foundation.gaze.v1
¶
Classes¶
GazeBlockV1
¶
Bases: WorkflowBlock
Source code in inference/core/workflows/core_steps/models/foundation/gaze/v1.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
Functions¶
convert_gaze_detections_to_sv_detections_and_angles
¶
convert_gaze_detections_to_sv_detections_and_angles(
images, gaze_predictions
)
Convert gaze detection results to supervision detections and angle lists.
Source code in inference/core/workflows/core_steps/models/foundation/gaze/v1.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
core/workflows/core_steps/models/foundation/google_gemini¶
inference.core.workflows.core_steps.models.foundation.google_gemini.v3
¶
Classes¶
Functions¶
execute_gemini_request
¶
execute_gemini_request(
roboflow_api_key, google_api_key, prompt, model_version
)
Route to proxied or direct execution based on API key format.
Source code in inference/core/workflows/core_steps/models/foundation/google_gemini/v3.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
core/workflows/core_steps/models/foundation/openai¶
core/workflows/core_steps/models/foundation/segment_anything3_3d¶
inference.core.workflows.core_steps.models.foundation.segment_anything3_3d.v1
¶
Classes¶
Functions¶
extract_masks_from_input
¶
extract_masks_from_input(mask_input)
Extract binary masks from sv.Detections, pass through other formats.
Source code in inference/core/workflows/core_steps/models/foundation/segment_anything3_3d/v1.py
229 230 231 232 233 234 235 236 237 | |
core/workflows/core_steps/models/foundation/stability_ai/inpainting¶
inference.core.workflows.core_steps.models.foundation.stability_ai.inpainting.v1
¶
Credits to: https://github.com/Fafruch for origin idea
Classes¶
core/workflows/core_steps/models/foundation/stability_ai/outpainting¶
inference.core.workflows.core_steps.models.foundation.stability_ai.outpainting.v1
¶
Credits to: https://github.com/Fafruch for origin idea
Classes¶
core/workflows/core_steps/sinks/email_notification¶
inference.core.workflows.core_steps.sinks.email_notification.v2
¶
Classes¶
Functions¶
apply_operations_to_message_parameters
¶
apply_operations_to_message_parameters(
message_parameters, message_parameters_operations
)
Apply per-parameter operation chains to message parameter values.
For each parameter in message_parameters, if operations are defined in message_parameters_operations for that parameter name, the operations are applied in order (e.g. ToString, StringToUpperCase, LookupTable). Parameters with no operations are returned unchanged.
Supports all value types, including WorkflowImageData: image operations such as ExtractImageProperty, ConvertImageToBase64, and ConvertImageToJPEG can be used to transform image parameters before they are serialized or interpolated into the message.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dict with the same keys as message_parameters and values that are |
Dict[str, Any]
|
either the original value (no operations) or the result of the |
Dict[str, Any]
|
operations chain. |
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
format_email_message
¶
format_email_message(
message,
message_parameters,
message_parameters_operations,
)
Format email message by replacing parameter placeholders with actual values.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
format_email_message_html_with_images
¶
format_email_message_html_with_images(
message,
message_parameters,
message_parameters_operations,
)
Format email message as HTML with inline images.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
process_attachments
¶
process_attachments(attachments)
Process attachments dict to convert WorkflowImageData to JPEG bytes. Returns a dict with filename -> bytes mapping.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
send_email_using_smtp_server_v2
¶
send_email_using_smtp_server_v2(
sender_email,
receiver_email,
cc_receiver_email,
bcc_receiver_email,
subject,
message,
attachments,
smtp_server,
smtp_port,
sender_email_password,
inline_images,
is_html,
)
V2-specific SMTP email sender with inline image support. This function is used only by v2 block and does not modify v1 behavior.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |
send_email_via_roboflow_proxy
¶
send_email_via_roboflow_proxy(
roboflow_api_key,
receiver_email,
cc_receiver_email,
bcc_receiver_email,
subject,
message,
message_parameters,
message_parameters_operations,
attachments,
)
Send email through Roboflow's proxy service.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
serialize_image_data
¶
serialize_image_data(value)
Serialize WorkflowImageData objects to base64 strings for JSON transmission. Returns the value unchanged if it's not a WorkflowImageData object.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
serialize_image_data_parameters
¶
serialize_image_data_parameters(message_parameters)
Convert any WorkflowImageData objects in message_parameters to base64 strings so they can be serialized to JSON for the API call.
Source code in inference/core/workflows/core_steps/sinks/email_notification/v2.py
746 747 748 749 750 751 752 753 | |
core/workflows/core_steps/sinks/roboflow/dataset_upload¶
inference.core.workflows.core_steps.sinks.roboflow.dataset_upload.v1
¶
- WARNING! *
This module contains the utility functions used by RoboflowDatasetUploadBlockV2.
We do not recommend making multiple blocks dependent on the same code, but the change between v1 and v2 was basically the default value of some parameter - hence we decided not to replicate the code.
If you need to modify this module beware that you may introduce change to RoboflowDatasetUploadBlockV2! If that happens, probably that's the time to disentangle those blocks and copy the code.
Classes¶
core/workflows/core_steps/sinks/twilio/sms¶
inference.core.workflows.core_steps.sinks.twilio.sms.v2
¶
Classes¶
Functions¶
format_message
¶
format_message(
message,
message_parameters,
message_parameters_operations,
)
Format SMS/MMS message by replacing parameter placeholders with actual values.
Returns:
| Type | Description |
|---|---|
str
|
Tuple of (formatted_message, needs_mms) where needs_mms is True if message |
bool
|
exceeds SMS character limit and should be sent as MMS. |
Source code in inference/core/workflows/core_steps/sinks/twilio/sms/v2.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
process_media_urls_for_twilio
¶
process_media_urls_for_twilio(media_url)
Process media URLs for Twilio MMS. Converts WorkflowImageData to temporary public URLs.
Source code in inference/core/workflows/core_steps/sinks/twilio/sms/v2.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
send_sms_using_twilio_client
¶
send_sms_using_twilio_client(
client,
message,
sender_number,
receiver_number,
media_urls,
)
Send SMS/MMS using Twilio client directly.
Source code in inference/core/workflows/core_steps/sinks/twilio/sms/v2.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
send_sms_via_roboflow_proxy
¶
send_sms_via_roboflow_proxy(
roboflow_api_key,
receiver_number,
message,
message_parameters,
message_parameters_operations,
media_url,
)
Send SMS/MMS through Roboflow's proxy service.
Source code in inference/core/workflows/core_steps/sinks/twilio/sms/v2.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
serialize_media_for_api
¶
serialize_media_for_api(media_url)
Serialize media for API transmission. Separates URL-based media from base64 image data.
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
Tuple of (media_urls, media_base64) where: |
Optional[List[Dict[str, str]]]
|
|
Tuple[Optional[List[str]], Optional[List[Dict[str, str]]]]
|
|
Source code in inference/core/workflows/core_steps/sinks/twilio/sms/v2.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
core/workflows/core_steps/transformations/detections_merge¶
inference.core.workflows.core_steps.transformations.detections_merge.v1
¶
Functions¶
calculate_union_bbox
¶
calculate_union_bbox(detections)
Calculate a single bounding box that contains all input detections.
Source code in inference/core/workflows/core_steps/transformations/detections_merge/v1.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
get_lowest_confidence_index
¶
get_lowest_confidence_index(detections)
Get the index of the detection with the lowest confidence.
Source code in inference/core/workflows/core_steps/transformations/detections_merge/v1.py
134 135 136 137 138 | |
core/workflows/core_steps/transformations/image_slicer¶
inference.core.workflows.core_steps.transformations.image_slicer.v1
¶
Classes¶
Functions¶
generate_offsets
¶
generate_offsets(resolution_wh, slice_wh, overlap_ratio_wh)
Original code: https://github.com/roboflow/supervision/blob/5123085037ec594524fc8f9d9b71b1cd9f487e8d/supervision/detection/tools/inference_slicer.py#L204-L203 to avoid fragile contract with supervision, as this function is not element of public API.
Generate offset coordinates for slicing an image based on the given resolution, slice dimensions, and overlap ratios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution_wh
|
Tuple[int, int]
|
A tuple representing the width and height of the image to be sliced. |
required |
slice_wh
|
Tuple[int, int]
|
Dimensions of each slice measured in pixels. The |
required |
overlap_ratio_wh
|
Optional[Tuple[float, float]]
|
A tuple representing the desired overlap ratio for width and height between consecutive slices. Each value should be in the range [0, 1), where 0 means no overlap and a value close to 1 means high overlap. |
required |
Note
The function ensures that slices do not exceed the boundaries of the original image. As a result, the final slices in the row and column dimensions might be smaller than the specified slice dimensions if the image's width or height is not a multiple of the slice's width or height minus the overlap.
Source code in inference/core/workflows/core_steps/transformations/image_slicer/v1.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
inference.core.workflows.core_steps.transformations.image_slicer.v2
¶
Classes¶
Functions¶
generate_offsets
¶
generate_offsets(resolution_wh, slice_wh, overlap_ratio_wh)
This is modification of the function from block v1, which makes sure that the "border" crops are pushed towards the center of the image, making sure: * all crops will be the same size * deduplication of crops coordinates is done
Source code in inference/core/workflows/core_steps/transformations/image_slicer/v2.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
core/workflows/core_steps/transformations/qr_code_generator¶
inference.core.workflows.core_steps.transformations.qr_code_generator.v1
¶
Classes¶
Functions¶
generate_qr_code
¶
generate_qr_code(
text,
version=None,
box_size=10,
error_correct="M",
border=4,
fill_color="BLACK",
back_color="WHITE",
)
Generate a QR code PNG image from text input.
Source code in inference/core/workflows/core_steps/transformations/qr_code_generator/v1.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
core/workflows/core_steps/transformations/stitch_ocr_detections¶
inference.core.workflows.core_steps.transformations.stitch_ocr_detections.v1
¶
Functions¶
get_line_separator
¶
get_line_separator(reading_direction)
Get the appropriate separator based on reading direction.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v1.py
341 342 343 | |
group_detections_by_line
¶
group_detections_by_line(
xyxy, reading_direction, tolerance
)
Group detections into lines based on primary coordinate.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v1.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
prepare_coordinates
¶
prepare_coordinates(xyxy, reading_direction)
Prepare coordinates based on reading direction.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v1.py
294 295 296 297 298 299 300 301 302 | |
sort_line_detections
¶
sort_line_detections(line_xyxy, reading_direction)
Sort detections within a line based on reading direction.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v1.py
329 330 331 332 333 334 335 336 337 338 | |
stitch_ocr_detections
¶
stitch_ocr_detections(
detections,
reading_direction="left_to_right",
tolerance=10,
delimiter="",
)
Stitch OCR detections into coherent text based on spatial arrangement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Detections
|
Supervision Detections object containing OCR results |
required |
reading_direction
|
str
|
Direction to read text ("left_to_right", "right_to_left", "vertical_top_to_bottom", "vertical_bottom_to_top") |
'left_to_right'
|
tolerance
|
int
|
Vertical tolerance for grouping text into lines |
10
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict containing stitched OCR text under 'ocr_text' key |
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v1.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
inference.core.workflows.core_steps.transformations.stitch_ocr_detections.v2
¶
Classes¶
CollimateDetection
¶
Helper class for collimate algorithm to store detection properties.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
688 689 690 691 692 693 694 695 696 697 698 699 700 | |
StitchingAlgorithm
¶
Bases: str, Enum
Algorithm for grouping detections into words/lines.
Uses fixed pixel tolerance for line grouping (original algorithm).
Good for consistent font sizes and line spacing.
Uses Otsu's method on normalized gaps to find natural breaks.
Resolution-invariant and works well with bimodal distributions (e.g., character-level vs word-level spacing).
Uses greedy parent-child traversal to group detections.
Good for skewed or curved text where bucket-based approaches fail.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
Functions¶
adaptive_word_grouping
¶
adaptive_word_grouping(
detections,
reading_direction,
delimiter="",
threshold_multiplier=1.0,
)
Stitch OCR detections using adaptive gap analysis with Otsu thresholding.
This approach is resolution-invariant because it normalizes gaps by local character dimensions. It works well with bimodal gap distributions (e.g., character-level vs word-level spacing).
The algorithm computes a global threshold across all lines to leverage the full dataset of gaps, which provides more robust Otsu thresholding than per-line computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Detections
|
Supervision Detections object containing OCR results |
required |
reading_direction
|
str
|
Direction to read text |
required |
delimiter
|
str
|
String to insert between text elements |
''
|
threshold_multiplier
|
float
|
Multiplier applied to Otsu threshold (>1.0 = fewer word breaks, <1.0 = more word breaks) |
1.0
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict containing stitched OCR text under 'ocr_text' key |
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
collimate_word_grouping
¶
collimate_word_grouping(
detections,
reading_direction,
delimiter="",
tolerance=10,
)
Stitch OCR detections using greedy parent-child traversal (collimate algorithm).
This algorithm is good for skewed or curved text where traditional bucket-based line grouping may fail. It works by: 1. Sorting detections by primary reading coordinate 2. Starting with the first detection as a "parent" 3. Finding all detections that "follow" the parent (within tolerance) 4. Building lines/columns through greedy traversal
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Detections
|
Supervision Detections object containing OCR results |
required |
reading_direction
|
str
|
Direction to read text |
required |
delimiter
|
str
|
String to insert between characters within words |
''
|
tolerance
|
int
|
Pixel tolerance for alignment |
10
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict containing stitched OCR text under 'ocr_text' key |
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 | |
find_otsu_threshold
¶
find_otsu_threshold(gaps)
Find natural break between intra-word and inter-word gaps using Otsu's method.
This is a resolution-invariant approach that finds the optimal threshold to separate two classes of gaps (e.g., gaps within words vs gaps between words).
Also detects whether the distribution is bimodal (two distinct groups) or unimodal (single group, suggesting single word or uniform spacing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gaps
|
ndarray
|
Array of normalized gap values |
required |
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (threshold, is_bimodal): |
bool
|
|
tuple[float, bool]
|
|
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
get_line_separator
¶
get_line_separator(reading_direction)
Get the appropriate separator based on reading direction.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
426 427 428 | |
group_detections_by_line
¶
group_detections_by_line(
xyxy, reading_direction, tolerance
)
Group detections into lines based on primary coordinate.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
prepare_coordinates
¶
prepare_coordinates(xyxy, reading_direction)
Prepare coordinates based on reading direction.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
379 380 381 382 383 384 385 386 387 | |
sort_line_detections
¶
sort_line_detections(line_xyxy, reading_direction)
Sort detections within a line based on reading direction.
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
414 415 416 417 418 419 420 421 422 423 | |
stitch_ocr_detections
¶
stitch_ocr_detections(
detections,
reading_direction="left_to_right",
tolerance=10,
delimiter="",
)
Stitch OCR detections into coherent text based on spatial arrangement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Detections
|
Supervision Detections object containing OCR results |
required |
reading_direction
|
str
|
Direction to read text ("left_to_right", "right_to_left", "vertical_top_to_bottom", "vertical_bottom_to_top") |
'left_to_right'
|
tolerance
|
int
|
Vertical tolerance for grouping text into lines |
10
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict containing stitched OCR text under 'ocr_text' key |
Source code in inference/core/workflows/core_steps/transformations/stitch_ocr_detections/v2.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
core/workflows/core_steps/visualizations/classification_label¶
inference.core.workflows.core_steps.visualizations.classification_label.v1
¶
Classes¶
Functions¶
create_label_visualization
¶
create_label_visualization(
sorted_predictions,
text_position,
text,
w,
h,
initial_offset,
total_spacing,
text_scale,
text_padding,
)
Create visualization layout for classification labels.
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
detect_prediction_type
¶
detect_prediction_type(predictions)
Detect whether predictions are single-label or multi-label based on structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
dict
|
The predictions dictionary |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
'single-label' or 'multi-label' |
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
478 479 480 481 482 483 484 485 486 487 488 489 490 | |
format_labels
¶
format_labels(predictions, text='Class and Confidence')
Format labels based on specified text option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list
|
List of prediction dictionaries containing 'class' and 'confidence' |
required |
text
|
str
|
One of "class", "confidence", or "class and confidence" |
'Class and Confidence'
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
Formatted label strings |
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
format_multi_label_predictions
¶
format_multi_label_predictions(predictions)
Transform multi-label predictions from predicted_classes into standard format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
dict
|
The predictions dictionary |
required |
Returns:
| Type | Description |
|---|---|
List[dict]
|
List[dict]: Formatted predictions list |
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
handle_bottom_position
¶
handle_bottom_position(
sorted_predictions,
text,
w,
h,
initial_offset,
total_spacing,
)
Handle visualization layout for bottom positions.
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
handle_center_position
¶
handle_center_position(
sorted_predictions,
text,
text_position,
w,
h,
total_spacing,
text_scale,
text_padding,
)
Handle visualization layout for center positions.
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
handle_top_position
¶
handle_top_position(
sorted_predictions,
text,
w,
h,
initial_offset,
total_spacing,
)
Handle visualization layout for top positions.
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
validate_prediction_format
¶
validate_prediction_format(predictions, task_type)
Validate that the predictions format matches the specified task type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
dict
|
The predictions dictionary |
required |
task_type
|
str
|
The specified task type ('single-label' or 'multi-label') |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If prediction format doesn't match task type |
Source code in inference/core/workflows/core_steps/visualizations/classification_label/v1.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
core/workflows/core_steps/visualizations/common/annotators¶
inference.core.workflows.core_steps.visualizations.common.annotators.background_color
¶
Classes¶
BackgroundColorAnnotator
¶
Bases: BaseAnnotator
A class for drawing background colors outside of detected box or mask regions.
Warning
This annotator uses sv.Detections.mask.
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/background_color.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
Functions¶
__init__
¶
__init__(color=Color.BLACK, opacity=0.5, force_box=False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
Color
|
The color to use for annotating detections. |
BLACK
|
opacity
|
float
|
Opacity of the overlay mask. Must be between |
0.5
|
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/background_color.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
annotate
¶
annotate(scene, detections)
Annotates the given scene with masks based on the provided detections.
Args:
scene (ImageType): The image where masks will be drawn.
ImageType is a flexible type, accepting either numpy.ndarray
or PIL.Image.Image.
detections (Detections): Object detections to annotate.
Returns:
The annotated image, matching the type of scene (numpy.ndarray
or PIL.Image.Image)
Example:
import supervision as sv
image = ...
detections = sv.Detections(...)
background_color_annotator = sv.BackgroundColorAnnotator()
annotated_frame = background_color_annotator.annotate(
scene=image.copy(),
detections=detections
)
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/background_color.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
inference.core.workflows.core_steps.visualizations.common.annotators.halo
¶
Classes¶
HaloAnnotator
¶
Bases: BaseAnnotator
A class for drawing Halos on an image using provided detections.
Warning
This annotator uses sv.Detections.mask.
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/halo.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
Functions¶
__init__
¶
__init__(
color=ColorPalette.DEFAULT,
opacity=0.8,
kernel_size=40,
color_lookup=ColorLookup.CLASS,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
Union[Color, ColorPalette]
|
The color or color palette to use for annotating detections. |
DEFAULT
|
opacity
|
float
|
Opacity of the overlay mask. Must be between |
0.8
|
kernel_size
|
int
|
The size of the average pooling kernel used for creating the halo. |
40
|
color_lookup
|
ColorLookup
|
Strategy for mapping colors to annotations.
Options are |
CLASS
|
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/halo.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
annotate
¶
annotate(scene, detections, custom_color_lookup=None)
Annotates the given scene with halos based on the provided detections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
ImageType
|
The image where masks will be drawn.
|
required |
detections
|
Detections
|
Object detections to annotate. |
required |
custom_color_lookup
|
Optional[ndarray]
|
Custom color lookup array. Allows to override the default color mapping strategy. |
None
|
Returns:
| Type | Description |
|---|---|
ImageType
|
The annotated image, matching the type of |
Example
import supervision as sv
image = ...
detections = sv.Detections(...)
halo_annotator = sv.HaloAnnotator()
annotated_frame = halo_annotator.annotate(
scene=image.copy(),
detections=detections
)

Source code in inference/core/workflows/core_steps/visualizations/common/annotators/halo.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
inference.core.workflows.core_steps.visualizations.common.annotators.model_comparison
¶
Classes¶
ModelComparisonAnnotator
¶
Bases: BaseAnnotator
A class for annotating images by highlighting regions predicted by two different models. This annotator visually distinguishes areas uniquely predicted by each model as well as the background where neither model made a prediction.
Attributes:
| Name | Type | Description |
|---|---|---|
color_a |
Color
|
Color used to highlight predictions made only by Model A. |
color_b |
Color
|
Color used to highlight predictions made only by Model B. |
background_color |
Color
|
Color used for parts of the image where neither model made a prediction. |
opacity |
float
|
Opacity level of the overlays, ranging between 0 and 1. |
force_box |
bool
|
If True, forces the use of bounding boxes for predictions even if masks are available. |
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/model_comparison.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
Functions¶
__init__
¶
__init__(
color_a=Color.GREEN,
color_b=Color.RED,
background_color=Color.BLACK,
opacity=0.7,
force_box=False,
)
Initializes the ModelComparisonAnnotator with the specified colors, opacity, and behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color_a
|
Color
|
Color used to highlight predictions made only by Model A. |
GREEN
|
color_b
|
Color
|
Color used to highlight predictions made only by Model B. |
RED
|
background_color
|
Color
|
Color for parts of the image not covered by any prediction. |
BLACK
|
opacity
|
float
|
Opacity of the overlay mask, must be between 0 and 1. |
0.7
|
force_box
|
bool
|
Whether to use bounding boxes instead of masks if masks are available. |
False
|
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/model_comparison.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
annotate
¶
annotate(scene, detections_a, detections_b)
Annotates the given scene with highlights representing predictions from two models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
ndarray
|
Original image as a NumPy array (H x W x C). |
required |
detections_a
|
Detections
|
Predictions from Model A. |
required |
detections_b
|
Detections
|
Predictions from Model B. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Annotated image as a NumPy array. |
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/model_comparison.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
inference.core.workflows.core_steps.visualizations.common.annotators.polygon
¶
Classes¶
PolygonAnnotator
¶
Bases: BaseAnnotator
A class for drawing polygons on an image using provided detections.
Warning
This annotator uses sv.Detections.mask.
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/polygon.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
Functions¶
__init__
¶
__init__(
color=ColorPalette.DEFAULT,
thickness=2,
color_lookup=ColorLookup.CLASS,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
Union[Color, ColorPalette]
|
The color or color palette to use for annotating detections. |
DEFAULT
|
thickness
|
int
|
Thickness of the polygon lines. |
2
|
color_lookup
|
ColorLookup
|
Strategy for mapping colors to annotations.
Options are |
CLASS
|
Source code in inference/core/workflows/core_steps/visualizations/common/annotators/polygon.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
annotate
¶
annotate(scene, detections, custom_color_lookup=None)
Annotates the given scene with polygons based on the provided detections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
ImageType
|
The image where polygons will be drawn.
|
required |
detections
|
Detections
|
Object detections to annotate. |
required |
custom_color_lookup
|
Optional[ndarray]
|
Custom color lookup array. Allows to override the default color mapping strategy. |
None
|
Returns:
| Type | Description |
|---|---|
ImageType
|
The annotated image, matching the type of |
Example
import supervision as sv
image = ...
detections = sv.Detections(...)
polygon_annotator = sv.PolygonAnnotator()
annotated_frame = polygon_annotator.annotate(
scene=image.copy(),
detections=detections
)

Source code in inference/core/workflows/core_steps/visualizations/common/annotators/polygon.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
core/workflows/core_steps/visualizations/text_display¶
inference.core.workflows.core_steps.visualizations.text_display.utils
¶
Functions¶
align_offset
¶
align_offset(text_align, max_width, line_width)
Calculate horizontal offset for text alignment.
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
88 89 90 91 92 93 94 95 | |
calculate_relative_position
¶
calculate_relative_position(
anchor,
offset_x,
offset_y,
box_width,
box_height,
img_width,
img_height,
)
Calculate the top-left corner position for a box positioned relative to an image anchor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anchor
|
str
|
Anchor point name (e.g., "top_left", "center", "bottom_right") |
required |
offset_x
|
int
|
Horizontal offset from anchor point (positive = right) |
required |
offset_y
|
int
|
Vertical offset from anchor point (positive = down) |
required |
box_width
|
int
|
Width of the box to position |
required |
box_height
|
int
|
Height of the box to position |
required |
img_width
|
int
|
Width of the image |
required |
img_height
|
int
|
Height of the image |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, int]
|
Tuple of (x, y) coordinates for the top-left corner of the box |
Raises:
| Type | Description |
|---|---|
ValueError
|
If anchor is not recognized |
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
clamp_box
¶
clamp_box(box_x, box_y, box_w, box_h, img_w, img_h)
Clamp box position to image bounds.
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
79 80 81 82 83 84 85 | |
compute_layout
¶
compute_layout(
*,
formatted_text,
font,
font_scale,
font_thickness,
padding,
position_mode,
position_x,
position_y,
anchor,
offset_x,
offset_y,
img_w,
img_h
)
Compute text layout including dimensions and position.
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
draw_background
¶
draw_background(
img,
x1,
y1,
x2,
y2,
bg_color_bgr,
background_opacity,
border_radius,
)
Draw background rectangle with optional transparency and rounded corners.
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
draw_background_with_alpha
¶
draw_background_with_alpha(
img, pt1, pt2, color, alpha, border_radius
)
Draw a filled rectangle with alpha blending using overlay compositing.
Uses proper overlay-based alpha blending for smooth antialiased edges, especially important for rounded rectangles.
Process: 1. Extract the affected region 2. Create overlay and draw shape on it 3. Alpha-blend overlay with original region 4. Write blended result back
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
draw_rounded_rectangle
¶
draw_rounded_rectangle(img, pt1, pt2, color, radius)
Draw a filled rounded rectangle on an image.
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
draw_text_lines
¶
draw_text_lines(
img,
*,
layout,
padding,
text_align,
font,
font_scale,
font_thickness,
color_bgr
)
Draw text lines on the image.
Source code in inference/core/workflows/core_steps/visualizations/text_display/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
inference.core.workflows.core_steps.visualizations.text_display.v1
¶
Classes¶
Functions¶
format_text_with_parameters
¶
format_text_with_parameters(
text, text_parameters, text_parameters_operations
)
Format text by replacing parameter placeholders with actual values.
Uses a single-pass regex substitution for efficiency and correctness.
Source code in inference/core/workflows/core_steps/visualizations/text_display/v1.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
core/workflows/execution_engine/introspection¶
inference.core.workflows.execution_engine.introspection.blocks_loader
¶
Functions¶
clear_caches
¶
clear_caches()
Clear all LRU caches in this module. Useful for testing or when environment configuration changes.
Source code in inference/core/workflows/execution_engine/introspection/blocks_loader.py
62 63 64 65 66 67 68 69 70 71 | |
inference.core.workflows.execution_engine.introspection.schema_parser
¶
core/workflows/execution_engine/v1/compiler¶
inference.core.workflows.execution_engine.v1.compiler.cache
¶
Classes¶
BasicWorkflowsCache
¶
Bases: Generic[V]
Base cache which is capable of hashing compound payloads based on
list of injected hash functions. Hash functions are to produce stable hashing strings.
Each function is invoked on get_hash_key(...) kwarg (use named args only!),
output string is concatenated and md5 value is calculated.
Cache is size bounded, each entry lives until cache_size new entries appear.
Raises WorkflowEnvironmentConfigurationError when get_hash_key(...) is not
provided with params corresponding to all hash functions.
Thread safe thanks to thread lock on get(...) and cache(...).
Source code in inference/core/workflows/execution_engine/v1/compiler/cache.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
inference.core.workflows.execution_engine.v1.compiler.graph_constructor
¶
Functions¶
establish_step_execution_dimensionality
¶
establish_step_execution_dimensionality(
inputs_dimensionalities,
control_flow_lineage_support,
output_dimensionality_offset,
)
Determine how many batch dimensions (execution slices) a step runs with.
Used during workflow compilation in denote_data_flow_for_step. The result is stored on StepNode.step_execution_dimensionality and consumed at execution time to: - Drive how many times the step is executed (which batch indices/slices). - Align and expand inputs (e.g. auto-batch casting) to match this size. - Validate that parameter dimensionalities are compatible (runtime checks in step_input_assembler and manager).
Logic: - If no input has non-zero dimensionality but the step is gated by control flow (control_flow_lineage_support non-empty), the dimensionality is the number of control-flow branches. - Otherwise, the minimum non-zero input dimensionality is used; if output_dimensionality_offset < 0 (step reduces batch dimension), one is subtracted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs_dimensionalities
|
Dict[str, Set[int]]
|
Per-input sets of dimensionalities (from get_inputs_dimensionalities). |
required |
control_flow_lineage_support
|
List[str]
|
Lineage identifiers for control-flow branches that gate this step (from establish_batch_oriented_step_lineage). |
required |
output_dimensionality_offset
|
int
|
Block's output dimensionality offset (positive = expand, negative = reduce batch dimension). |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of batch dimensions (execution slices) for this step. |
Source code in inference/core/workflows/execution_engine/v1/compiler/graph_constructor.py
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 | |
get_lineage_derived_from_control_flow
¶
get_lineage_derived_from_control_flow(
control_flow_steps_selectors, execution_graph
)
Return unique non-empty data lineages from the given control flow steps.
Each lineage is taken from the step's data_lineage in the execution graph. Lineages are deduplicated by lineage id (see identify_lineage); empty lineages are omitted. Used when establishing batch-oriented step lineage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_flow_steps_selectors
|
List[str]
|
Step selectors (node ids) of control flow steps whose data_lineage is to be collected. |
required |
execution_graph
|
DiGraph
|
The workflow execution graph containing step nodes and their data_lineage. |
required |
Returns:
| Type | Description |
|---|---|
List[List[str]]
|
List of distinct non-empty data lineages, one per unique lineage id. |
Source code in inference/core/workflows/execution_engine/v1/compiler/graph_constructor.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
verify_compatibility_of_input_data_lineage_with_control_flow_lineage
¶
verify_compatibility_of_input_data_lineage_with_control_flow_lineage(
step_name,
inputs_lineage,
control_flow_steps_selectors,
execution_graph,
)
Ensure control flow steps' data lineage is compatible with the step's inputs.
Control flow steps that affect this step must operate on data that is compatible with the data fed to the step; otherwise the step could never execute. Compares unique control flow lineages against input lineage prefixes and raises ControlFlowDefinitionError if any control flow lineage is not covered by the inputs.
If inputs_lineage is empty, there is no sense to verify compatibility. The lineage of the step should be established based on the control flow lineages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_name
|
str
|
Name of the step being verified (used in error messages). |
required |
inputs_lineage
|
List[List[str]]
|
Data lineages derived from the step's input data. |
required |
control_flow_steps_selectors
|
List[str]
|
Step selectors of control flow steps that affect this step's execution. |
required |
execution_graph
|
DiGraph
|
The workflow execution graph. |
required |
Raises:
| Type | Description |
|---|---|
ControlFlowDefinitionError
|
When a control flow step's lineage is not compatible with the step's input lineage (step would never execute). |
Source code in inference/core/workflows/execution_engine/v1/compiler/graph_constructor.py
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 | |
inference.core.workflows.execution_engine.v1.compiler.graph_traversal
¶
Functions¶
traverse_graph_ensuring_parents_are_reached_first
¶
traverse_graph_ensuring_parents_are_reached_first(
graph, start_node
)
This function works under assumption of common super-input node in the graph - otherwise,
there is no common entry point to put as start_node.
Source code in inference/core/workflows/execution_engine/v1/compiler/graph_traversal.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
inference.core.workflows.execution_engine.v1.compiler.syntactic_parser
¶
core/workflows/execution_engine/v1/dynamic_blocks¶
inference.core.workflows.execution_engine.v1.dynamic_blocks.block_assembler
¶
Functions¶
ensure_dynamic_blocks_allowed
¶
ensure_dynamic_blocks_allowed(dynamic_blocks_definitions)
Ensure that dynamic blocks are allowed based on configuration.
Dynamic blocks are allowed if: 1. Local custom Python execution is enabled (ALLOW_CUSTOM_PYTHON_EXECUTION_IN_WORKFLOWS=True) 2. OR Modal execution mode is set (WORKFLOWS_CUSTOM_PYTHON_EXECUTION_MODE=modal)
This allows secure execution via Modal sandboxes even when local execution is disabled.
Source code in inference/core/workflows/execution_engine/v1/dynamic_blocks/block_assembler.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
inference.core.workflows.execution_engine.v1.dynamic_blocks.modal_executor
¶
Modal executor for Custom Python Blocks in Workflows using Web Endpoints.
This module handles the execution of untrusted user code in Modal sandboxes using web endpoints for better security and no size limitations.
Classes¶
ModalExecutor
¶
Manages execution of Custom Python Blocks in Modal sandboxes via web endpoints.
Source code in inference/core/workflows/execution_engine/v1/dynamic_blocks/modal_executor.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
Functions¶
__init__
¶
__init__(workspace_id=None)
Initialize the Modal executor for a specific workspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_id
|
Optional[str]
|
The workspace ID to namespace execution, defaults to "anonymous" |
None
|
Source code in inference/core/workflows/execution_engine/v1/dynamic_blocks/modal_executor.py
181 182 183 184 185 186 187 188 | |
execute_remote
¶
execute_remote(
block_type_name, python_code, inputs, workspace_id=None
)
Execute a Custom Python Block in a Modal sandbox via web endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_type_name
|
str
|
Name of the block type |
required |
python_code
|
PythonCode
|
The Python code to execute |
required |
inputs
|
Dict[str, Any]
|
Input data for the function |
required |
workspace_id
|
Optional[str]
|
Optional workspace ID override |
None
|
Returns:
| Type | Description |
|---|---|
BlockResult
|
BlockResult from the execution |
Raises:
| Type | Description |
|---|---|
DynamicBlockError
|
If Modal is not available or Modal request fails |
Exception
|
If remote execution throws an exception |
Source code in inference/core/workflows/execution_engine/v1/dynamic_blocks/modal_executor.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
Functions¶
validate_code_in_modal
¶
validate_code_in_modal(python_code, workspace_id=None)
Validate Python code syntax in a Modal sandbox via web endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_code
|
PythonCode
|
The Python code to validate |
required |
workspace_id
|
Optional[str]
|
The workspace ID for Modal App |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if code is valid, raises otherwise |
Raises:
| Type | Description |
|---|---|
DynamicBlockError
|
If code validation fails |
Source code in inference/core/workflows/execution_engine/v1/dynamic_blocks/modal_executor.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
core/workflows/execution_engine/v1/executor/execution_data_manager¶
inference.core.workflows.execution_engine.v1.executor.execution_data_manager.step_input_assembler
¶
Functions¶
filter_to_valid_prefix_chains
¶
filter_to_valid_prefix_chains(per_dim_sets, dimensions)
Keep only indices that form a complete parent-child chain across dimensions.
Given per-dimension sets (e.g. from intersect_masks_per_dimension), retains only indices that have a full lineage from the smallest to the largest dimension. Used for inter-level intersection.
Source code in inference/core/workflows/execution_engine/v1/executor/execution_data_manager/step_input_assembler.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
get_masks_intersection_for_dimensions
¶
get_masks_intersection_for_dimensions(
batch_masks, dimensions
)
Intersect masks at each dimension and filter to valid prefix chains.
Source code in inference/core/workflows/execution_engine/v1/executor/execution_data_manager/step_input_assembler.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
intersect_masks_per_dimension
¶
intersect_masks_per_dimension(batch_masks, dimensions)
Intersect masks at each dimensionality level.
For each dimension d, returns the set of indices (with length d) that appear in every mask that has at least one index at that dimension. Masks with no indices at d are ignored for that dimension. Used for intra-dimensional intersection.
Source code in inference/core/workflows/execution_engine/v1/executor/execution_data_manager/step_input_assembler.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
enterprise/parallel¶
Parallel HTTP inference via Celery workers for high-throughput deployments.
inference.enterprise.parallel.dispatch_manager
¶
Classes¶
ResultsChecker
¶
Class responsible for queuing asyncronous inference runs, keeping track of running requests, and awaiting their results.
Source code in inference/enterprise/parallel/dispatch_manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
Functions¶
add_task
¶
add_task(task_id, request)
Wait until there's available cylce to queue a task. When there are cycles, add the task's id to a list to keep track of its results, launch the preprocess celeryt task, set the task's status to in progress in redis.
Source code in inference/enterprise/parallel/dispatch_manager.py
36 37 38 39 40 41 42 43 44 | |
get_result
¶
get_result(task_id)
Check the done tasks and errored tasks for this task id.
Source code in inference/enterprise/parallel/dispatch_manager.py
46 47 48 49 50 51 52 53 54 55 56 57 58 | |
loop
¶
loop()
Main loop. Check all in progress tasks for their status, and if their status is final, (either failure or success) then add their results to the appropriate results dictionary.
Source code in inference/enterprise/parallel/dispatch_manager.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
Functions¶
inference.enterprise.parallel.infer
¶
Classes¶
Functions¶
get_batch
¶
get_batch(redis, model_names)
Run a heuristic to select the best batch to infer on redis[Redis]: redis client model_names[List[str]]: list of models with nonzero number of requests returns: Tuple[List[Dict], str] List[Dict] represents a batch of request dicts str is the model id
Source code in inference/enterprise/parallel/infer.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
write_infer_arrays_and_launch_postprocess
¶
write_infer_arrays_and_launch_postprocess(
arrs, request, preproc_return_metadata
)
Write inference results to shared memory and launch the postprocessing task
Source code in inference/enterprise/parallel/infer.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
inference.enterprise.parallel.utils
¶
Classes¶
SharedMemoryMetadata
dataclass
¶
Info needed to load array from shared memory
Source code in inference/enterprise/parallel/utils.py
64 65 66 67 68 69 70 | |
Functions¶
failure_handler
¶
failure_handler(redis, *request_ids)
Context manager that updates the status/results key in redis with exception info on failure.
Source code in inference/enterprise/parallel/utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
shm_manager
¶
shm_manager(*shms, unlink_on_success=False)
Context manager that closes and frees shared memory objects.
Source code in inference/enterprise/parallel/utils.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
enterprise/workflows/enterprise_blocks/sinks/PLC_modbus¶
inference.enterprise.workflows.enterprise_blocks.sinks.PLC_modbus.v1
¶
Classes¶
ModbusTCPBlockV1
¶
Bases: WorkflowBlock
A Modbus TCP communication block using pymodbus.
Supports: - 'read': Reads specified registers. - 'write': Writes values to specified registers. - 'read_and_write': Reads and writes in one execution.
On failures, errors are printed and marked as "ReadFailure" or "WriteFailure".
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/PLC_modbus/v1.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
enterprise/workflows/enterprise_blocks/sinks/PLCethernetIP¶
inference.enterprise.workflows.enterprise_blocks.sinks.PLCethernetIP.v1
¶
Classes¶
PLCBlockManifest
¶
Bases: WorkflowBlockManifest
Manifest for a PLC communication block using Ethernet/IP.
The block can be used in one of three modes: - 'read': Only reads specified tags. - 'write': Only writes specified tags. - 'read_and_write': Performs both reading and writing in one execution.
tags_to_read and tags_to_write are applicable depending on the mode chosen.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/PLCethernetIP/v1.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
PLCBlockV1
¶
Bases: WorkflowBlock
A PLC communication workflow block using Ethernet/IP and pylogix.
Depending on the selected mode: - 'read': Reads specified tags. - 'write': Writes provided values to specified tags. - 'read_and_write': Reads and writes in one go.
In case of failures, errors are printed to terminal and the corresponding tag entry in the output is set to "ReadFailure" or "WriteFailure".
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/PLCethernetIP/v1.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
Functions¶
run
¶
run(
plc_ip,
mode,
tags_to_read,
tags_to_write,
depends_on,
image=None,
metadata=None,
)
Run PLC read/write operations using pylogix over Ethernet/IP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plc_ip
|
str
|
PLC IP address. |
required |
mode
|
str
|
'read', 'write', or 'read_and_write'. |
required |
tags_to_read
|
List[str]
|
Tags to read if applicable. |
required |
tags_to_write
|
Dict[str, Union[int, float, str]]
|
Tags to write if applicable. |
required |
depends_on
|
any
|
The step output this block depends on. |
required |
image
|
Optional[WorkflowImageData]
|
Not required for this block. |
None
|
metadata
|
Optional[VideoMetadata]
|
Not required for this block. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary with |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/PLCethernetIP/v1.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
enterprise/workflows/enterprise_blocks/sinks/microsoft_sql_server¶
inference.enterprise.workflows.enterprise_blocks.sinks.microsoft_sql_server.v1
¶
Classes¶
SQLServerConnectionError
¶
Bases: SQLServerError
Exception raised for connection-related errors
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/microsoft_sql_server/v1.py
43 44 45 46 | |
SQLServerError
¶
Bases: Exception
Base exception for SQL Server related errors
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/microsoft_sql_server/v1.py
37 38 39 40 | |
SQLServerInsertError
¶
Bases: SQLServerError
Exception raised for insert operation errors
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/microsoft_sql_server/v1.py
49 50 51 52 | |
enterprise/workflows/enterprise_blocks/sinks/opc_writer¶
inference.enterprise.workflows.enterprise_blocks.sinks.opc_writer.v1
¶
Classes¶
OPCUAConnectionManager
¶
Thread-safe connection manager for OPC UA clients with connection pooling and circuit breaker pattern.
Maintains a pool of connections keyed by (url, user_name) to avoid creating new connections for every write operation. Uses circuit breaker to fail fast when servers are unreachable.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
Functions¶
__new__
¶
__new__()
Singleton pattern to ensure one connection manager across the application.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
35 36 37 38 39 40 41 42 | |
close_all
¶
close_all()
Close all connections in the pool and stop the shared ThreadLoop.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
332 333 334 335 336 337 338 339 340 | |
get_connection
¶
get_connection(
url,
user_name,
password,
timeout,
max_retries=1,
base_backoff=0.0,
)
Get a connection from the pool or create a new one.
This method is thread-safe and will reuse existing healthy connections. Uses circuit breaker pattern to fail fast for recently failed servers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
user_name
|
Optional[str]
|
Optional username for authentication |
required |
password
|
Optional[str]
|
Optional password for authentication |
required |
timeout
|
int
|
Connection timeout in seconds |
required |
max_retries
|
int
|
Maximum number of connection attempts (default 1) |
1
|
base_backoff
|
float
|
Base delay between retries (default 0) |
0.0
|
Returns:
| Type | Description |
|---|---|
Client
|
A connected OPC UA client |
Raises:
| Type | Description |
|---|---|
Exception
|
If connection fails or circuit breaker is open |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
get_pool_stats
¶
get_pool_stats()
Get statistics about the connection pool.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
invalidate_connection
¶
invalidate_connection(url, user_name)
Invalidate a connection, forcing it to be recreated on next use.
Call this when a connection error occurs during an operation to ensure the next operation gets a fresh connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
user_name
|
Optional[str]
|
Optional username used for the connection |
required |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
release_connection
¶
release_connection(url, user_name, force_close=False)
Release a connection back to the pool.
By default, connections are kept alive for reuse. Set force_close=True to immediately close the connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
user_name
|
Optional[str]
|
Optional username used for the connection |
required |
force_close
|
bool
|
If True, close the connection instead of keeping it |
False
|
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
UnsupportedTypeError
¶
Bases: Exception
Raised when an unsupported value type is specified
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
370 371 372 373 | |
Functions¶
get_available_namespaces
¶
get_available_namespaces(client)
Get list of available namespaces from OPC UA server. Returns empty list if unable to fetch namespaces.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
778 779 780 781 782 783 784 785 786 787 788 789 790 | |
get_connection_manager
¶
get_connection_manager()
Get the global OPC UA connection manager instance.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
362 363 364 365 366 367 | |
get_node_data_type
¶
get_node_data_type(var)
Get the data type of an OPC UA node. Returns a string representation of the type, or "Unknown" if unable to read.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
802 803 804 805 806 807 808 809 810 811 | |
opc_connect_and_write_value
¶
opc_connect_and_write_value(
url,
namespace,
user_name,
password,
object_name,
variable_name,
value,
timeout,
node_lookup_mode="hierarchical",
value_type="String",
max_retries=1,
retry_backoff_seconds=0.0,
)
Connect to OPC UA server and write a value using connection pooling.
Uses the connection manager to reuse existing connections. If no connection exists, attempts to create one. Fails fast on connection errors to avoid blocking the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
namespace
|
str
|
Namespace URI or index |
required |
user_name
|
Optional[str]
|
Optional username for authentication |
required |
password
|
Optional[str]
|
Optional password for authentication |
required |
object_name
|
str
|
Target object path |
required |
variable_name
|
str
|
Variable to write |
required |
value
|
Union[bool, float, int, str]
|
Value to write |
required |
timeout
|
int
|
Connection timeout in seconds |
required |
node_lookup_mode
|
Literal['hierarchical', 'direct']
|
Path lookup strategy ('hierarchical' or 'direct') |
'hierarchical'
|
value_type
|
str
|
OPC UA data type for the value |
'String'
|
max_retries
|
int
|
Maximum number of connection attempts (default 1 = no retries) |
1
|
retry_backoff_seconds
|
float
|
Base delay between retries (default 0 = no delay) |
0.0
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (error_status, message) |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | |
safe_disconnect
¶
safe_disconnect(client)
Safely disconnect from OPC UA server, swallowing any errors
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
793 794 795 796 797 798 799 | |
models/clip¶
inference.models.clip.clip_inference_models
¶
Classes¶
InferenceModelsClipAdapter
¶
Bases: Model
Roboflow ONNX ClipModel model.
This class is responsible for handling the ONNX ClipModel model, including loading the model, preprocessing the input, and performing inference.
Attributes:
| Name | Type | Description |
|---|---|---|
visual_onnx_session |
InferenceSession
|
ONNX Runtime session for visual inference. |
textual_onnx_session |
InferenceSession
|
ONNX Runtime session for textual inference. |
resolution |
int
|
The resolution of the input image. |
clip_preprocess |
function
|
Function to preprocess the image. |
Source code in inference/models/clip/clip_inference_models.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
Functions¶
compare
¶
compare(
subject,
prompt,
subject_type="image",
prompt_type="text",
**kwargs
)
Compares the subject with the prompt to calculate similarity scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
Any
|
The subject data to be compared. Can be either an image or text. |
required |
prompt
|
Any
|
The prompt data to be compared against the subject. Can be a single value (image/text), list of values, or dictionary of values. |
required |
subject_type
|
str
|
Specifies the type of the subject data. Must be either "image" or "text". Defaults to "image". |
'image'
|
prompt_type
|
Union[str, List[str], Dict[str, Any]]
|
Specifies the type of the prompt data. Can be "image", "text", list of these types, or a dictionary containing these types. Defaults to "text". |
'text'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[float], Dict[str, float]]
|
Union[List[float], Dict[str, float]]: A list or dictionary containing cosine similarity scores between the subject and prompt(s). If prompt is a dictionary, returns a dictionary with keys corresponding to the original prompt dictionary's keys. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If subject_type or prompt_type is neither "image" nor "text". |
ValueError
|
If the number of prompts exceeds the maximum batch size. |
Source code in inference/models/clip/clip_inference_models.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
embed_image
¶
embed_image(image, **kwargs)
Embeds an image or a list of images using the Clip model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to be embedded. Image can be in any format that is acceptable by the preproc_image method. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the image(s) as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of images in the list exceeds the maximum batch size. |
Notes
The function measures performance using perf_counter and also has support for ONNX session to get embeddings.
Source code in inference/models/clip/clip_inference_models.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
embed_text
¶
embed_text(text, **kwargs)
Embeds a text or a list of texts using the Clip model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Union[str, List[str]]
|
The text string or list of text strings to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the text or texts as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of text strings in the list exceeds the maximum batch size. |
Notes
The function utilizes an ONNX session to compute embeddings and measures the embedding time with perf_counter.
Source code in inference/models/clip/clip_inference_models.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
infer
¶
infer(image, **kwargs)
Embeds an image - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Source code in inference/models/clip/clip_inference_models.py
318 319 320 321 322 323 | |
infer_from_request
¶
infer_from_request(request)
Routes the request to the appropriate inference function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClipInferenceRequest
|
The request object containing the inference details. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipEmbeddingResponse |
ClipEmbeddingResponse
|
The response object containing the embeddings. |
Source code in inference/models/clip/clip_inference_models.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
make_compare_response
¶
make_compare_response(similarities)
Creates a ClipCompareResponse object from the provided similarity data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
similarities
|
Union[List[float], Dict[str, float]]
|
A list or dictionary containing similarity scores. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipCompareResponse |
ClipCompareResponse
|
An instance of the ClipCompareResponse with the given similarity scores. |
Example
Assuming ClipCompareResponse expects a dictionary of string-float pairs:
make_compare_response({"image1": 0.98, "image2": 0.76}) ClipCompareResponse(similarity={"image1": 0.98, "image2": 0.76})
Source code in inference/models/clip/clip_inference_models.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
make_embed_image_response
¶
make_embed_image_response(embeddings)
Converts the given embeddings into a ClipEmbeddingResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
ndarray
|
A numpy array containing the embeddings for an image or images. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipEmbeddingResponse |
ClipEmbeddingResponse
|
An instance of the ClipEmbeddingResponse with the provided embeddings converted to a list. |
Example
embeddings_array = np.array([[0.5, 0.3, 0.2], [0.1, 0.9, 0.0]]) make_embed_image_response(embeddings_array) ClipEmbeddingResponse(embeddings=[[0.5, 0.3, 0.2], [0.1, 0.9, 0.0]])
Source code in inference/models/clip/clip_inference_models.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
make_embed_text_response
¶
make_embed_text_response(embeddings)
Converts the given text embeddings into a ClipEmbeddingResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
ndarray
|
A numpy array containing the embeddings for a text or texts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipEmbeddingResponse |
ClipEmbeddingResponse
|
An instance of the ClipEmbeddingResponse with the provided embeddings converted to a list. |
Example
embeddings_array = np.array([[0.8, 0.1, 0.1], [0.4, 0.5, 0.1]]) make_embed_text_response(embeddings_array) ClipEmbeddingResponse(embeddings=[[0.8, 0.1, 0.1], [0.4, 0.5, 0.1]])
Source code in inference/models/clip/clip_inference_models.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
preproc_image
¶
preproc_image(image)
Preprocesses an inference request image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The object containing information necessary to load the image for inference. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A numpy array of the preprocessed image pixel data. |
Source code in inference/models/clip/clip_inference_models.py
325 326 327 328 329 330 331 332 333 334 | |
Functions¶
inference.models.clip.clip_model
¶
Classes¶
Clip
¶
Bases: OnnxRoboflowCoreModel
Roboflow ONNX ClipModel model.
This class is responsible for handling the ONNX ClipModel model, including loading the model, preprocessing the input, and performing inference.
Attributes:
| Name | Type | Description |
|---|---|---|
visual_onnx_session |
InferenceSession
|
ONNX Runtime session for visual inference. |
textual_onnx_session |
InferenceSession
|
ONNX Runtime session for textual inference. |
resolution |
int
|
The resolution of the input image. |
clip_preprocess |
function
|
Function to preprocess the image. |
Source code in inference/models/clip/clip_model.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
Functions¶
__init__
¶
__init__(
*args,
model_id=CLIP_MODEL_ID,
onnxruntime_execution_providers=get_onnxruntime_execution_providers(
ONNXRUNTIME_EXECUTION_PROVIDERS
),
**kwargs
)
Initializes the Clip with the given arguments and keyword arguments.
Source code in inference/models/clip/clip_model.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
compare
¶
compare(
subject,
prompt,
subject_type="image",
prompt_type="text",
**kwargs
)
Compares the subject with the prompt to calculate similarity scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
Any
|
The subject data to be compared. Can be either an image or text. |
required |
prompt
|
Any
|
The prompt data to be compared against the subject. Can be a single value (image/text), list of values, or dictionary of values. |
required |
subject_type
|
str
|
Specifies the type of the subject data. Must be either "image" or "text". Defaults to "image". |
'image'
|
prompt_type
|
Union[str, List[str], Dict[str, Any]]
|
Specifies the type of the prompt data. Can be "image", "text", list of these types, or a dictionary containing these types. Defaults to "text". |
'text'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[float], Dict[str, float]]
|
Union[List[float], Dict[str, float]]: A list or dictionary containing cosine similarity scores between the subject and prompt(s). If prompt is a dictionary, returns a dictionary with keys corresponding to the original prompt dictionary's keys. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If subject_type or prompt_type is neither "image" nor "text". |
ValueError
|
If the number of prompts exceeds the maximum batch size. |
Source code in inference/models/clip/clip_model.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
embed_image
¶
embed_image(image, **kwargs)
Embeds an image or a list of images using the Clip model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to be embedded. Image can be in any format that is acceptable by the preproc_image method. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the image(s) as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of images in the list exceeds the maximum batch size. |
Notes
The function measures performance using perf_counter and also has support for ONNX session to get embeddings.
Source code in inference/models/clip/clip_model.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
embed_text
¶
embed_text(text, **kwargs)
Embeds a text or a list of texts using the Clip model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Union[str, List[str]]
|
The text string or list of text strings to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the text or texts as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of text strings in the list exceeds the maximum batch size. |
Notes
The function utilizes an ONNX session to compute embeddings and measures the embedding time with perf_counter.
Source code in inference/models/clip/clip_model.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Gets the list of files required for inference.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The list of file names. |
Source code in inference/models/clip/clip_model.py
298 299 300 301 302 303 304 | |
infer
¶
infer(image, **kwargs)
Embeds an image - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Source code in inference/models/clip/clip_model.py
347 348 349 350 351 352 | |
infer_from_request
¶
infer_from_request(request)
Routes the request to the appropriate inference function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClipInferenceRequest
|
The request object containing the inference details. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipEmbeddingResponse |
ClipEmbeddingResponse
|
The response object containing the embeddings. |
Source code in inference/models/clip/clip_model.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
make_compare_response
¶
make_compare_response(similarities)
Creates a ClipCompareResponse object from the provided similarity data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
similarities
|
Union[List[float], Dict[str, float]]
|
A list or dictionary containing similarity scores. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipCompareResponse |
ClipCompareResponse
|
An instance of the ClipCompareResponse with the given similarity scores. |
Example
Assuming ClipCompareResponse expects a dictionary of string-float pairs:
make_compare_response({"image1": 0.98, "image2": 0.76}) ClipCompareResponse(similarity={"image1": 0.98, "image2": 0.76})
Source code in inference/models/clip/clip_model.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
make_embed_image_response
¶
make_embed_image_response(embeddings)
Converts the given embeddings into a ClipEmbeddingResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
ndarray
|
A numpy array containing the embeddings for an image or images. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipEmbeddingResponse |
ClipEmbeddingResponse
|
An instance of the ClipEmbeddingResponse with the provided embeddings converted to a list. |
Example
embeddings_array = np.array([[0.5, 0.3, 0.2], [0.1, 0.9, 0.0]]) make_embed_image_response(embeddings_array) ClipEmbeddingResponse(embeddings=[[0.5, 0.3, 0.2], [0.1, 0.9, 0.0]])
Source code in inference/models/clip/clip_model.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
make_embed_text_response
¶
make_embed_text_response(embeddings)
Converts the given text embeddings into a ClipEmbeddingResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
ndarray
|
A numpy array containing the embeddings for a text or texts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ClipEmbeddingResponse |
ClipEmbeddingResponse
|
An instance of the ClipEmbeddingResponse with the provided embeddings converted to a list. |
Example
embeddings_array = np.array([[0.8, 0.1, 0.1], [0.4, 0.5, 0.1]]) make_embed_text_response(embeddings_array) ClipEmbeddingResponse(embeddings=[[0.8, 0.1, 0.1], [0.4, 0.5, 0.1]])
Source code in inference/models/clip/clip_model.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
preproc_image
¶
preproc_image(image)
Preprocesses an inference request image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The object containing information necessary to load the image for inference. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A numpy array of the preprocessed image pixel data. |
Source code in inference/models/clip/clip_model.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
Functions¶
models/deep_lab_v3_plus¶
inference.models.deep_lab_v3_plus.deep_lab_v3_plus_segmentation
¶
Classes¶
DeepLabV3PlusSemanticSegmentation
¶
Bases: SemanticSegmentationBaseOnnxRoboflowInferenceModel
DeepLabV3Plus Semantic Segmentation ONNX Inference Model.
This class is responsible for performing semantic segmentation using the DeepLabV3Plus model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Methods:
| Name | Description |
|---|---|
predict |
Performs inference on the given image using the ONNX session. |
Source code in inference/models/deep_lab_v3_plus/deep_lab_v3_plus_segmentation.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
models/depth_anything_v3/architecture¶
inference.models.depth_anything_v3.architecture.da3
¶
Classes¶
DepthAnything3Net
¶
Bases: Module
Depth Anything 3 network for depth estimation. Simplified for single-view depth-only inference.
This network consists of: - Backbone: DinoV2 feature extractor - Head: DualDPT for depth prediction
Returns:
| Type | Description |
|---|---|
|
Dictionary containing: |
|
|
|
|
Source code in inference/models/depth_anything_v3/architecture/da3.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
Functions¶
__init__
¶
__init__(
backbone_name,
out_layers,
alt_start,
qknorm_start,
rope_start,
cat_token,
head_dim_in,
head_output_dim,
head_features,
head_out_channels,
)
Initialize DepthAnything3Net.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone_name
|
str
|
DinoV2 backbone variant ("vits" or "vitb") |
required |
out_layers
|
list
|
Layer indices to extract features from |
required |
alt_start
|
int
|
Layer index to start alternating attention |
required |
qknorm_start
|
int
|
Layer index to start QK normalization |
required |
rope_start
|
int
|
Layer index to start RoPE |
required |
cat_token
|
bool
|
Whether to concatenate local and global tokens |
required |
head_dim_in
|
int
|
Input dimension for the head |
required |
head_output_dim
|
int
|
Output dimension for the head |
required |
head_features
|
int
|
Feature dimension in the head |
required |
head_out_channels
|
list
|
Output channel dimensions per stage |
required |
Source code in inference/models/depth_anything_v3/architecture/da3.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
forward
¶
forward(x)
Forward pass through the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input images (B, N, 3, H, W) where N=1 for single-view |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Tensor]
|
Dictionary containing depth predictions |
Source code in inference/models/depth_anything_v3/architecture/da3.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
inference.models.depth_anything_v3.architecture.dpt
¶
Classes¶
FeatureFusionBlock
¶
Bases: Module
Top-down fusion block
Source code in inference/models/depth_anything_v3/architecture/dpt.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
ResidualConvUnit
¶
Bases: Module
Lightweight residual convolution block for fusion
Source code in inference/models/depth_anything_v3/architecture/dpt.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
Functions¶
inference.models.depth_anything_v3.architecture.dualdpt
¶
Classes¶
DualDPT
¶
Bases: Module
Dual-head DPT for dense prediction with an auxiliary head. Simplified for single-view depth estimation - only depth output is used.
Source code in inference/models/depth_anything_v3/architecture/dualdpt.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
Functions¶
inference.models.depth_anything_v3.architecture.head_utils
¶
Classes¶
Permute
¶
Bases: Module
nn.Module wrapper around Tensor.permute for cleaner nn.Sequential usage.
Source code in inference/models/depth_anything_v3/architecture/head_utils.py
22 23 24 25 26 27 28 29 30 31 32 | |
Functions¶
create_uv_grid
¶
create_uv_grid(
width,
height,
aspect_ratio=None,
dtype=None,
device=None,
)
Create a normalized UV grid of shape (width, height, 2).
Source code in inference/models/depth_anything_v3/architecture/head_utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
custom_interpolate
¶
custom_interpolate(
x,
size=None,
scale_factor=None,
mode="bilinear",
align_corners=True,
)
Safe interpolation implementation to avoid INT_MAX overflow.
Source code in inference/models/depth_anything_v3/architecture/head_utils.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
make_sincos_pos_embed
¶
make_sincos_pos_embed(embed_dim, pos, omega_0=100)
Generate 1D positional embedding from a given grid using sine and cosine functions.
Source code in inference/models/depth_anything_v3/architecture/head_utils.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
position_grid_to_embed
¶
position_grid_to_embed(pos_grid, embed_dim, omega_0=100)
Convert 2D position grid (HxWx2) to sinusoidal embeddings (HxWxC)
Source code in inference/models/depth_anything_v3/architecture/head_utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
models/depth_anything_v3/architecture/layers¶
inference.models.depth_anything_v3.architecture.layers.drop_path
¶
Classes¶
DropPath
¶
Bases: Module
Drop paths (Stochastic Depth) per sample.
Source code in inference/models/depth_anything_v3/architecture/layers/drop_path.py
27 28 29 30 31 32 33 34 35 | |
inference.models.depth_anything_v3.architecture.layers.patch_embed
¶
Classes¶
PatchEmbed
¶
Bases: Module
2D image to patch embedding: (B,C,H,W) -> (B,N,D)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_size
|
Union[int, Tuple[int, int]]
|
Image size. |
224
|
patch_size
|
Union[int, Tuple[int, int]]
|
Patch token size. |
16
|
in_chans
|
int
|
Number of input image channels. |
3
|
embed_dim
|
int
|
Number of linear projection output channels. |
768
|
norm_layer
|
Optional[Callable]
|
Normalization layer. |
None
|
Source code in inference/models/depth_anything_v3/architecture/layers/patch_embed.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
inference.models.depth_anything_v3.architecture.layers.rope
¶
Classes¶
PositionGetter
¶
Generates and caches 2D spatial positions for patches in a grid.
Source code in inference/models/depth_anything_v3/architecture/layers/rope.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
RotaryPositionEmbedding2D
¶
Bases: Module
2D Rotary Position Embedding implementation.
Source code in inference/models/depth_anything_v3/architecture/layers/rope.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
models/depth_anything_v3¶
inference.models.depth_anything_v3.depth_anything_v3
¶
Classes¶
DepthAnythingV3
¶
Bases: DepthAnythingV2
Depth Anything V3 model for monocular depth estimation.
This model uses the Depth Anything V3 architecture with DinoV2 backbone and DualDPT head for dense depth prediction.
Note: Unlike V2, V3 is not HuggingFace Transformers compatible, so the architecture is vendored in and model loading is custom. However, the external interface (inputs/outputs) matches V2.
Source code in inference/models/depth_anything_v3/depth_anything_v3.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
Functions¶
initialize_model
¶
initialize_model(**kwargs)
Initialize the model with vendored architecture instead of HF Transformers.
Source code in inference/models/depth_anything_v3/depth_anything_v3.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
predict
¶
predict(image_in, prompt='', history=None, **kwargs)
Run depth prediction on an input image.
Unlike V2, the vendored DepthAnything3Net expects a tensor directly with shape (B, N, 3, H, W) where N=1 for single-view inference.
Source code in inference/models/depth_anything_v3/depth_anything_v3.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
Functions¶
convert_state_dict
¶
convert_state_dict(state_dict)
Convert state dict from official DA3 format to our simplified format.
Source code in inference/models/depth_anything_v3/depth_anything_v3.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
parse_config
¶
parse_config(config_path)
Parse the config.json file from HuggingFace/official DA3 format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to the config.json file |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with model configuration parameters |
Source code in inference/models/depth_anything_v3/depth_anything_v3.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
models/dinov3¶
inference.models.dinov3.dinov3_classification
¶
Classes¶
DinoV3Classification
¶
Bases: ClassificationBaseOnnxRoboflowInferenceModel
DinoV3Classification handles classification inference for Dinov3 linear probe models using ONNX.
Inherits
Attributes:
| Name | Type | Description |
|---|---|---|
multiclass |
bool
|
A flag that specifies if the model should handle multiclass classification. |
Source code in inference/models/dinov3/dinov3_classification.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Attributes¶
weights_file
property
¶
weights_file
Determines the weights file to be used based on the availability of AWS keys.
If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set, it returns the path to 'weights.onnx'. Otherwise, it returns the path to 'best.onnx'.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the weights file. |
Functions¶
__init__
¶
__init__(*args, **kwargs)
Initializes the DinoV3Classification instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/dinov3/dinov3_classification.py
22 23 24 25 26 27 28 29 30 | |
models/doctr¶
inference.models.doctr.doctr_model
¶
Classes¶
DocTR
¶
Bases: RoboflowCoreModel
Source code in inference/models/doctr/doctr_model.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Functions¶
__init__
¶
__init__(
*args, model_id="doctr_rec/crnn_vgg16_bn", **kwargs
)
Initializes the DocTR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/doctr/doctr_model.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["model.pt"]. |
Source code in inference/models/doctr/doctr_model.py
210 211 212 213 214 215 216 | |
infer
¶
infer(image, **kwargs)
Run inference on a provided image. - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
DoctrOCRInferenceRequest
|
The inference request. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
OCRInferenceResponse |
Union[str, Tuple[str, InferenceResponseImage, List[ObjectDetectionPrediction]]]
|
The inference response. |
Source code in inference/models/doctr/doctr_model.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
preprocess_image
¶
preprocess_image(image)
DocTR pre-processes images as part of its inference pipeline.
Thus, no preprocessing is required here.
Source code in inference/models/doctr/doctr_model.py
104 105 106 107 108 109 110 | |
DocTRDet
¶
Bases: RoboflowCoreModel
DocTR class for document Optical Character Recognition (OCR).
Attributes:
| Name | Type | Description |
|---|---|---|
doctr |
The DocTR model. |
|
ort_session |
ONNX runtime inference session. |
Source code in inference/models/doctr/doctr_model.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
Functions¶
__init__
¶
__init__(
*args, model_id="doctr_det/db_resnet50_v2", **kwargs
)
Initializes the DocTR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/doctr/doctr_model.py
251 252 253 254 255 256 257 258 259 260 261 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["model.pt"]. |
Source code in inference/models/doctr/doctr_model.py
266 267 268 269 270 271 272 | |
DocTRRec
¶
Bases: RoboflowCoreModel
Source code in inference/models/doctr/doctr_model.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
Functions¶
__init__
¶
__init__(
*args, model_id="doctr_rec/crnn_vgg16_bn_v2", **kwargs
)
Initializes the DocTR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/doctr/doctr_model.py
220 221 222 223 224 225 226 227 228 229 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["model.pt"]. |
Source code in inference/models/doctr/doctr_model.py
234 235 236 237 238 239 240 | |
Functions¶
models/easy_ocr¶
inference.models.easy_ocr.easy_ocr
¶
Classes¶
EasyOCR
¶
Bases: RoboflowCoreModel
Roboflow EasyOCR model implementation.
This class is responsible for handling the EasyOCR model, including loading the model, preprocessing the input, and performing inference.
Source code in inference/models/easy_ocr/easy_ocr.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
Functions¶
__init__
¶
__init__(
model_id="easy_ocr/english_g2",
device=DEVICE,
*args,
**kwargs
)
Initializes EasyOCR with the given arguments and keyword arguments.
Source code in inference/models/easy_ocr/easy_ocr.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
Functions¶
inference.models.easy_ocr.easy_ocr_inference_models
¶
Classes¶
InferenceModelsEasyOCRAdapter
¶
Bases: Model
Roboflow EasyOCR model implementation.
This class is responsible for handling the EasyOCR model, including loading the model, preprocessing the input, and performing inference.
Source code in inference/models/easy_ocr/easy_ocr_inference_models.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
models/florence2¶
inference.models.florence2.utils
¶
Functions¶
import_class_from_file
¶
import_class_from_file(
file_path, class_name, alias_name=None
)
Emulates what huggingface transformers does to load remote code with trust_remote_code=True, but allows us to use the class directly so that we don't have to load untrusted code.
Source code in inference/models/florence2/utils.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
models/gaze¶
inference.models.gaze.gaze
¶
Classes¶
Gaze
¶
Bases: OnnxRoboflowCoreModel
Roboflow ONNX Gaze model.
This class is responsible for handling the ONNX Gaze model, including loading the model, preprocessing the input, and performing inference.
Attributes:
| Name | Type | Description |
|---|---|---|
gaze_onnx_session |
InferenceSession
|
ONNX Runtime session for gaze detection inference. |
Source code in inference/models/gaze/gaze.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
Functions¶
__init__
¶
__init__(*args, **kwargs)
Initializes the Gaze with the given arguments and keyword arguments.
Source code in inference/models/gaze/gaze.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Gets the list of files required for inference.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The list of file names. |
Source code in inference/models/gaze/gaze.py
209 210 211 212 213 214 215 216 217 218 | |
infer_from_request
¶
infer_from_request(request)
Detect faces and gazes in image(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
GazeDetectionInferenceRequest
|
The request object containing the image. |
required |
Returns:
| Type | Description |
|---|---|
List[GazeDetectionInferenceResponse]
|
List[GazeDetectionInferenceResponse]: The list of response objects containing the faces and corresponding gazes. |
Source code in inference/models/gaze/gaze.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
L2C2Wrapper
¶
Bases: L2CS
Roboflow L2CS Gaze detection model.
This class is responsible for converting L2CS model to ONNX model. It is ONLY intended for internal usage.
Workflow
After training a L2CS model, create an instance of this wrapper class. Load the trained weights file, and save it as ONNX model.
Source code in inference/models/gaze/gaze.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
inference.models.gaze.gaze_inference_models
¶
Classes¶
InferenceModelsGazeAdapter
¶
Bases: Model
Roboflow ONNX Gaze model.
This class is responsible for handling the ONNX Gaze model, including loading the model, preprocessing the input, and performing inference.
Attributes:
| Name | Type | Description |
|---|---|---|
gaze_onnx_session |
InferenceSession
|
ONNX Runtime session for gaze detection inference. |
Source code in inference/models/gaze/gaze_inference_models.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
Functions¶
__init__
¶
__init__(*args, api_key=None, **kwargs)
Initializes the Gaze with the given arguments and keyword arguments.
Source code in inference/models/gaze/gaze_inference_models.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
infer_from_request
¶
infer_from_request(request)
Detect faces and gazes in image(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
GazeDetectionInferenceRequest
|
The request object containing the image. |
required |
Returns:
| Type | Description |
|---|---|
List[GazeDetectionInferenceResponse]
|
List[GazeDetectionInferenceResponse]: The list of response objects containing the faces and corresponding gazes. |
Source code in inference/models/gaze/gaze_inference_models.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
inference.models.gaze.l2cs
¶
Classes¶
L2CS
¶
Bases: Module
L2CS Gaze Detection Model.
This class is responsible for performing gaze detection using the L2CS-Net model. Ref: https://github.com/Ahmednull/L2CS-Net
Methods:
| Name | Description |
|---|---|
forward |
Performs inference on the given image. |
Source code in inference/models/gaze/l2cs.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
models/grounding_dino¶
inference.models.grounding_dino.grounding_dino
¶
Classes¶
GroundingDINO
¶
Bases: RoboflowCoreModel
GroundingDINO class for zero-shot object detection.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The GroundingDINO model. |
Source code in inference/models/grounding_dino/grounding_dino.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
Functions¶
__init__
¶
__init__(
*args,
model_id="grounding_dino/groundingdino_swint_ogc",
**kwargs
)
Initializes the GroundingDINO model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/grounding_dino/grounding_dino.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["model.pt"]. |
Source code in inference/models/grounding_dino/grounding_dino.py
192 193 194 195 196 197 198 | |
infer
¶
infer(
image,
text=None,
class_filter=None,
box_threshold=0.5,
text_threshold=0.5,
class_agnostic_nms=CLASS_AGNOSTIC_NMS,
**kwargs
)
Run inference on a provided image. - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
CVInferenceRequest
|
The inference request. |
required |
class_filter
|
Optional[List[str]]
|
A list of class names to filter, if provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GroundingDINOInferenceRequest |
The inference response. |
Source code in inference/models/grounding_dino/grounding_dino.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
infer_from_request
¶
infer_from_request(request)
Perform inference based on the details provided in the request, and return the associated responses.
Source code in inference/models/grounding_dino/grounding_dino.py
116 117 118 119 120 121 122 123 124 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/grounding_dino/grounding_dino.py
104 105 106 107 108 109 110 111 112 113 114 | |
Functions¶
inference.models.grounding_dino.grounding_dino_inference_models
¶
Classes¶
InferenceModelsGroundingDINOAdapter
¶
Bases: Model
GroundingDINO class for zero-shot object detection.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The GroundingDINO model. |
Source code in inference/models/grounding_dino/grounding_dino_inference_models.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
Functions¶
infer
¶
infer(
image,
text=None,
class_filter=None,
box_threshold=0.5,
text_threshold=0.5,
class_agnostic_nms=CLASS_AGNOSTIC_NMS,
**kwargs
)
Run inference on a provided image. - image: can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
CVInferenceRequest
|
The inference request. |
required |
class_filter
|
Optional[List[str]]
|
A list of class names to filter, if provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GroundingDINOInferenceRequest |
The inference response. |
Source code in inference/models/grounding_dino/grounding_dino_inference_models.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
infer_from_request
¶
infer_from_request(request)
Perform inference based on the details provided in the request, and return the associated responses.
Source code in inference/models/grounding_dino/grounding_dino_inference_models.py
79 80 81 82 83 84 85 86 87 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/grounding_dino/grounding_dino_inference_models.py
68 69 70 71 72 73 74 75 76 77 | |
Functions¶
models/owlv2¶
inference.models.owlv2.owlv2
¶
Classes¶
OwlV2
¶
Bases: RoboflowInferenceModel
Source code in inference/models/owlv2/owlv2.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
Functions¶
draw_predictions
¶
draw_predictions(inference_request, inference_response)
Draw predictions from an inference response onto the original image provided by an inference request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inference_request
|
ObjectDetectionInferenceRequest
|
The inference request containing the image on which to draw predictions |
required |
inference_response
|
ObjectDetectionInferenceResponse
|
The inference response containing predictions to be drawn |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
bytes
|
A base64 encoded image string |
Source code in inference/models/owlv2/owlv2.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
SerializedOwlV2
¶
Bases: RoboflowInferenceModel
Source code in inference/models/owlv2/owlv2.py
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | |
Functions¶
get_or_create_owlv2_instance
classmethod
¶
get_or_create_owlv2_instance(roboflow_id)
Get an existing OwlV2 instance from cache or create a new one if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roboflow_id
|
str
|
The model ID for the OwlV2 model |
required |
Returns:
| Type | Description |
|---|---|
OwlV2
|
An OwlV2 instance |
Source code in inference/models/owlv2/owlv2.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
Functions¶
preprocess_image
¶
preprocess_image(
np_image, image_size, image_mean, image_std
)
Preprocess an image for OWLv2 by resizing, normalizing, and padding it. This is much faster than using the Owlv2Processor directly, as we ensure we use GPU if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
np_image
|
ndarray
|
The image to preprocess, with shape (H, W, 3) |
required |
image_size
|
tuple[int, int]
|
The target size of the image |
required |
image_mean
|
Tensor
|
The mean of the image, on DEVICE, with shape (1, 3, 1, 1) |
required |
image_std
|
Tensor
|
The standard deviation of the image, on DEVICE, with shape (1, 3, 1, 1) |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: The preprocessed image, on DEVICE, with shape (1, 3, H, W) |
Source code in inference/models/owlv2/owlv2.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
models/paligemma¶
inference.models.paligemma.paligemma
¶
Classes¶
LoRAPaliGemma
¶
Bases: LoRATransformerModel
By using you agree to the terms listed at https://ai.google.dev/gemma/terms
Source code in inference/models/paligemma/paligemma.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
PaliGemma
¶
Bases: TransformerModel
By using you agree to the terms listed at https://ai.google.dev/gemma/terms
Source code in inference/models/paligemma/paligemma.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
models/perception_encoder¶
inference.models.perception_encoder.perception_encoder
¶
Classes¶
PerceptionEncoder
¶
Bases: RoboflowCoreModel
Roboflow Perception Encoder model implementation.
This class is responsible for handling the Percpetion Encoder model, including loading the model, preprocessing the input, and performing inference.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
CLIP
|
The PE-CLIP model instance. |
preprocess |
function
|
Function to preprocess the image. |
tokenizer |
function
|
Function to tokenize text. |
device |
str
|
The device to run inference on (cuda/cpu). |
Source code in inference/models/perception_encoder/perception_encoder.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
Functions¶
__init__
¶
__init__(
model_id=PERCEPTION_ENCODER_MODEL_ID,
device=DEVICE,
*args,
**kwargs
)
Initializes the PerceptionEncoder with the given arguments and keyword arguments.
Source code in inference/models/perception_encoder/perception_encoder.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
compare
¶
compare(
subject,
prompt,
subject_type="image",
prompt_type="text",
**kwargs
)
Compares the subject with the prompt to calculate similarity scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
Any
|
The subject data to be compared. Can be either an image or text. |
required |
prompt
|
Any
|
The prompt data to be compared against the subject. Can be a single value (image/text), list of values, or dictionary of values. |
required |
subject_type
|
str
|
Specifies the type of the subject data. Must be either "image" or "text". Defaults to "image". |
'image'
|
prompt_type
|
Union[str, List[str], Dict[str, Any]]
|
Specifies the type of the prompt data. Can be "image", "text", list of these types, or a dictionary containing these types. Defaults to "text". |
'text'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[float], Dict[str, float]]
|
Union[List[float], Dict[str, float]]: A list or dictionary containing cosine similarity scores between the subject and prompt(s). |
Source code in inference/models/perception_encoder/perception_encoder.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
embed_image
¶
embed_image(image, **kwargs)
Embeds an image or a list of images using the PE-CLIP model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the image(s) as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
embed_text
¶
embed_text(text, **kwargs)
Embeds a text or a list of texts using the PE-CLIP model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Union[str, List[str]]
|
The text string or list of text strings to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the text or texts as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Gets the list of files required for inference.
Source code in inference/models/perception_encoder/perception_encoder.py
78 79 80 | |
infer
¶
infer(image, **kwargs)
Embeds an image
Source code in inference/models/perception_encoder/perception_encoder.py
314 315 316 | |
infer_from_request
¶
infer_from_request(request)
Routes the request to the appropriate inference function.
Source code in inference/models/perception_encoder/perception_encoder.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
initialize_model
¶
initialize_model(**kwargs)
Initialize the model. Not needed for PE-CLIP as it's loaded in init.
Source code in inference/models/perception_encoder/perception_encoder.py
82 83 84 | |
make_compare_response
¶
make_compare_response(similarities)
Creates a PerceptionEncoderCompareResponse object from the provided similarity data.
Source code in inference/models/perception_encoder/perception_encoder.py
159 160 161 162 163 164 | |
make_embed_image_response
¶
make_embed_image_response(embeddings)
Converts the given embeddings into a PerceptionEncoderEmbeddingResponse object.
Source code in inference/models/perception_encoder/perception_encoder.py
266 267 268 269 270 271 | |
make_embed_text_response
¶
make_embed_text_response(embeddings)
Converts the given text embeddings into a PerceptionEncoderEmbeddingResponse object.
Source code in inference/models/perception_encoder/perception_encoder.py
273 274 275 276 277 278 | |
predict
¶
predict(img_in, **kwargs)
Predict embeddings for an input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
Tensor
|
The input tensor to get embeddings for. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: A tuple containing the embeddings as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
preproc_image
¶
preproc_image(image)
Preprocesses an inference request image.
Source code in inference/models/perception_encoder/perception_encoder.py
86 87 88 89 90 | |
Functions¶
inference.models.perception_encoder.perception_encoder_inference_models
¶
Classes¶
InferenceModelsPerceptionEncoderAdapter
¶
Bases: Model
Roboflow Perception Encoder model implementation.
This class is responsible for handling the Percpetion Encoder model, including loading the model, preprocessing the input, and performing inference.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
Functions¶
compare
¶
compare(
subject,
prompt,
subject_type="image",
prompt_type="text",
**kwargs
)
Compares the subject with the prompt to calculate similarity scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
Any
|
The subject data to be compared. Can be either an image or text. |
required |
prompt
|
Any
|
The prompt data to be compared against the subject. Can be a single value (image/text), list of values, or dictionary of values. |
required |
subject_type
|
str
|
Specifies the type of the subject data. Must be either "image" or "text". Defaults to "image". |
'image'
|
prompt_type
|
Union[str, List[str], Dict[str, Any]]
|
Specifies the type of the prompt data. Can be "image", "text", list of these types, or a dictionary containing these types. Defaults to "text". |
'text'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[float], Dict[str, float]]
|
Union[List[float], Dict[str, float]]: A list or dictionary containing cosine similarity scores between the subject and prompt(s). |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
embed_image
¶
embed_image(image, **kwargs)
Embeds an image or a list of images using the PE-CLIP model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the image(s) as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
embed_text
¶
embed_text(text, **kwargs)
Embeds a text or a list of texts using the PE-CLIP model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Union[str, List[str]]
|
The text string or list of text strings to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the text or texts as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
infer
¶
infer(image, **kwargs)
Embeds an image
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
269 270 271 | |
infer_from_request
¶
infer_from_request(request)
Routes the request to the appropriate inference function.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
make_compare_response
¶
make_compare_response(similarities)
Creates a PerceptionEncoderCompareResponse object from the provided similarity data.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
150 151 152 153 154 155 | |
make_embed_image_response
¶
make_embed_image_response(embeddings)
Converts the given embeddings into a PerceptionEncoderEmbeddingResponse object.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
221 222 223 224 225 226 | |
make_embed_text_response
¶
make_embed_text_response(embeddings)
Converts the given text embeddings into a PerceptionEncoderEmbeddingResponse object.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
228 229 230 231 232 233 | |
predict
¶
predict(img_in, **kwargs)
Predict embeddings for an input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
Tensor
|
The input tensor to get embeddings for. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: A tuple containing the embeddings as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
208 209 210 211 212 213 214 215 216 217 218 219 | |
preproc_image
¶
preproc_image(image)
Preprocesses an inference request image.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
79 80 81 | |
Functions¶
models/perception_encoder/vision_encoder¶
inference.models.perception_encoder.vision_encoder.config
¶
Include all available vision encoder configurations.
Classes¶
PEConfig
dataclass
¶
Vision Tower Config.
Source code in inference/models/perception_encoder/vision_encoder/config.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
PETextConfig
dataclass
¶
Text Tower Config.
Source code in inference/models/perception_encoder/vision_encoder/config.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
inference.models.perception_encoder.vision_encoder.pe
¶
Classes¶
SelfAttention
¶
Bases: Module
Implements sequence packed attention and RoPe
Source code in inference/models/perception_encoder/vision_encoder/pe.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Transformer
¶
Bases: Module
Source code in inference/models/perception_encoder/vision_encoder/pe.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
Functions¶
truncate
¶
truncate(layer_idx)
Delete layers so the last layer is the given layer index.
Source code in inference/models/perception_encoder/vision_encoder/pe.py
269 270 271 272 273 | |
VisionTransformer
¶
Bases: Module
Source code in inference/models/perception_encoder/vision_encoder/pe.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
Functions¶
truncate
¶
truncate(layer_idx)
Delete layers so the last layer is the given layer index.
Source code in inference/models/perception_encoder/vision_encoder/pe.py
426 427 428 429 | |
inference.models.perception_encoder.vision_encoder.rope
¶
Classes¶
Rope2D
¶
Helper class to apply RoPE2D as well as interpolate on the fly.
Source code in inference/models/perception_encoder/vision_encoder/rope.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
inference.models.perception_encoder.vision_encoder.tokenizer
¶
CLIP tokenizer
Copied from https://github.com/openai/CLIP. Originally MIT License, Copyright (c) 2021 OpenAI.
Classes¶
SimpleTokenizer
¶
Bases: object
Source code in inference/models/perception_encoder/vision_encoder/tokenizer.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
Functions¶
__call__
¶
__call__(texts, context_length=None)
Returns the tokenized representation of given input string(s)
Parameters¶
texts : Union[str, List[str]] An input string or a list of input strings to tokenize context_length : int The context length to use; all CLIP models use 77 as the context length
Returns¶
A two-dimensional tensor containing the resulting tokens, shape = [number of input strings, context_length]
Source code in inference/models/perception_encoder/vision_encoder/tokenizer.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
Functions¶
bytes_to_unicode
cached
¶
bytes_to_unicode()
Returns list of utf-8 byte and a corresponding list of unicode strings. The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for decent coverage. This is a significant percentage of your normal, say, 32K bpe vocab. To avoid that, we want lookup tables between utf-8 bytes and unicode strings. And avoids mapping to whitespace/control characters the bpe code barfs on.
Source code in inference/models/perception_encoder/vision_encoder/tokenizer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
canonicalize_text
¶
canonicalize_text(
text, *, keep_punctuation_exact_string=None
)
Returns canonicalized text (lowercase and punctuation removed).
From: https://github.com/google-research/big_vision/blob/53f18caf27a9419231bbf08d3388b07671616d3d/big_vision/evaluators/proj/image_text/prompt_engineering.py#L94
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
string to be canonicalized. |
required | |
keep_punctuation_exact_string
|
If provided, then this exact string kept. For example providing '{}' will keep any occurrences of '{}' (but will still remove '{' and '}' that appear separately). |
None
|
Source code in inference/models/perception_encoder/vision_encoder/tokenizer.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
get_pairs
¶
get_pairs(word)
Return set of symbol pairs in a word. Word is represented as tuple of symbols (symbols being variable-length strings).
Source code in inference/models/perception_encoder/vision_encoder/tokenizer.py
62 63 64 65 66 67 68 69 70 71 | |
get_reduction_mask_fn
¶
get_reduction_mask_fn(type)
Choose strategy for dropping (masking) tokens to achieve target context length
Source code in inference/models/perception_encoder/vision_encoder/tokenizer.py
335 336 337 338 339 340 341 342 343 344 345 | |
models/qwen25vl¶
models/resnet¶
inference.models.resnet.resnet_classification
¶
Classes¶
ResNetClassification
¶
Bases: ClassificationBaseOnnxRoboflowInferenceModel
VitClassification handles classification inference for Vision Transformer (ViT) models using ONNX.
Inherits
Attributes:
| Name | Type | Description |
|---|---|---|
multiclass |
bool
|
A flag that specifies if the model should handle multiclass classification. |
Source code in inference/models/resnet/resnet_classification.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Attributes¶
weights_file
property
¶
weights_file
Determines the weights file to be used based on the availability of AWS keys.
If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set, it returns the path to 'weights.onnx'. Otherwise, it returns the path to 'best.onnx'.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the weights file. |
Functions¶
__init__
¶
__init__(*args, **kwargs)
Initializes the VitClassification instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/resnet/resnet_classification.py
22 23 24 25 26 27 28 29 30 | |
models/rfdetr¶
inference.models.rfdetr.rfdetr
¶
Classes¶
RFDETRInstanceSegmentation
¶
Bases: RFDETRObjectDetection, InstanceSegmentationBaseOnnxRoboflowInferenceModel
Source code in inference/models/rfdetr/rfdetr.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
Functions¶
make_response
¶
make_response(
predictions,
masks,
img_dims,
class_filter=None,
*args,
**kwargs
)
Constructs instance segmentation response objects from preprocessed predictions and polygons.
Source code in inference/models/rfdetr/rfdetr.py
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session with the RFDETR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: NumPy array representing the predictions, including boxes, confidence scores, and class IDs. |
Source code in inference/models/rfdetr/rfdetr.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | |
RFDETRObjectDetection
¶
Bases: ObjectDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX Object detection with the RFDETR model.
This class is responsible for performing object detection using the RFDETR model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Methods:
| Name | Description |
|---|---|
predict |
Performs object detection on the given image using the ONNX session. |
Source code in inference/models/rfdetr/rfdetr.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the RFDETR model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
initialize_model
¶
initialize_model(**kwargs)
Initializes the ONNX model, setting up the inference session and other necessary properties.
Source code in inference/models/rfdetr/rfdetr.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session with the RFDETR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: NumPy array representing the predictions, including boxes, confidence scores, and class IDs. |
Source code in inference/models/rfdetr/rfdetr.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
preproc_image
¶
preproc_image(
image,
disable_preproc_auto_orient=False,
disable_preproc_contrast=False,
disable_preproc_grayscale=False,
disable_preproc_static_crop=False,
)
Preprocesses an inference request image by loading it, then applying any pre-processing specified by the Roboflow platform, then scaling it to the inference input dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Union[Any, InferenceRequestImage]
|
An object containing information necessary to load the image for inference. |
required |
disable_preproc_auto_orient
|
bool
|
If true, the auto orient preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_contrast
|
bool
|
If true, the contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, Tuple[int, int]]
|
Tuple[np.ndarray, Tuple[int, int]]: A tuple containing a numpy array of the preprocessed image pixel data and a tuple of the images original size. |
Source code in inference/models/rfdetr/rfdetr.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
Functions¶
models/sam¶
inference.models.sam.segment_anything
¶
Classes¶
SegmentAnything
¶
Bases: RoboflowCoreModel
SegmentAnything class for handling segmentation tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
sam |
The segmentation model. |
|
predictor |
The predictor for the segmentation model. |
|
ort_session |
ONNX runtime inference session. |
|
embedding_cache |
Cache for embeddings. |
|
image_size_cache |
Cache for image sizes. |
|
embedding_cache_keys |
Keys for the embedding cache. |
|
low_res_logits_cache |
Cache for low resolution logits. |
|
segmentation_cache_keys |
Keys for the segmentation cache. |
Source code in inference/models/sam/segment_anything.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
Functions¶
__init__
¶
__init__(*args, model_id=f'sam/{SAM_VERSION_ID}', **kwargs)
Initializes the SegmentAnything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/sam/segment_anything.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
embed_image
¶
embed_image(image, image_id=None, **kwargs)
Embeds an image and caches the result if an image_id is provided. If the image has been embedded before and cached, the cached result will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be embedded. The format should be compatible with the preproc_image method. |
required |
image_id
|
Optional[str]
|
An identifier for the image. If provided, the embedding result will be cached with this ID. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, Tuple[int, int]]: A tuple where the first element is the embedding of the image and the second element is the shape (height, width) of the processed image. |
Notes
- Embeddings and image sizes are cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM_MAX_EMBEDDING_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Example
img_array = ... # some image array embed_image(img_array, image_id="sample123") (array([...]), (224, 224))
Source code in inference/models/sam/segment_anything.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Gets the list of files required for inference.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of file names. |
Source code in inference/models/sam/segment_anything.py
74 75 76 77 78 79 80 | |
infer_from_request
¶
infer_from_request(request)
Performs inference based on the request type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SamInferenceRequest
|
The inference request. |
required |
Returns:
| Type | Description |
|---|---|
|
Union[SamEmbeddingResponse, SamSegmentationResponse]: The inference response. |
Source code in inference/models/sam/segment_anything.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/sam/segment_anything.py
175 176 177 178 179 180 181 182 183 184 185 | |
segment_image
¶
segment_image(
image,
embeddings=None,
embeddings_format="json",
has_mask_input=False,
image_id=None,
mask_input=None,
mask_input_format="json",
orig_im_size=None,
point_coords=[],
point_labels=[],
use_mask_input_cache=True,
**kwargs
)
Segments an image based on provided embeddings, points, masks, or cached results. If embeddings are not directly provided, the function can derive them from the input image or cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be segmented. |
required |
embeddings
|
Optional[Union[ndarray, List[List[float]]]]
|
The embeddings of the image. Defaults to None, in which case the image is used to compute embeddings. |
None
|
embeddings_format
|
Optional[str]
|
Format of the provided embeddings; either 'json' or 'binary'. Defaults to 'json'. |
'json'
|
has_mask_input
|
Optional[bool]
|
Specifies whether mask input is provided. Defaults to False. |
False
|
image_id
|
Optional[str]
|
A cached identifier for the image. Useful for accessing cached embeddings or masks. |
None
|
mask_input
|
Optional[Union[ndarray, List[List[List[float]]]]]
|
Input mask for the image. |
None
|
mask_input_format
|
Optional[str]
|
Format of the provided mask input; either 'json' or 'binary'. Defaults to 'json'. |
'json'
|
orig_im_size
|
Optional[List[int]]
|
Original size of the image when providing embeddings directly. |
None
|
point_coords
|
Optional[List[List[float]]]
|
Coordinates of points in the image. Defaults to an empty list. |
[]
|
point_labels
|
Optional[List[int]]
|
Labels associated with the provided points. Defaults to an empty list. |
[]
|
use_mask_input_cache
|
Optional[bool]
|
Flag to determine if cached mask input should be used. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, np.ndarray]: A tuple where the first element is the segmentation masks of the image and the second element is the low resolution segmentation masks. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If necessary inputs are missing or inconsistent. |
Notes
- Embeddings, segmentations, and low-resolution logits can be cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM_MAX_EMBEDDING_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Source code in inference/models/sam/segment_anything.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
Functions¶
models/sam2¶
inference.models.sam2.segment_anything2
¶
Classes¶
SegmentAnything2
¶
Bases: RoboflowCoreModel
SegmentAnything class for handling segmentation tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
sam |
The segmentation model. |
|
embedding_cache |
Cache for embeddings. |
|
image_size_cache |
Cache for image sizes. |
|
embedding_cache_keys |
Keys for the embedding cache. |
Source code in inference/models/sam2/segment_anything2.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
Functions¶
__init__
¶
__init__(
*args,
model_id=f"sam2/{SAM2_VERSION_ID}",
low_res_logits_cache_size=SAM2_MAX_LOGITS_CACHE_SIZE,
embedding_cache_size=SAM2_MAX_EMBEDDING_CACHE_SIZE,
**kwargs,
)
Initializes the SegmentAnything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/sam2/segment_anything2.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
embed_image
¶
embed_image(image, image_id=None, **kwargs)
Embeds an image and caches the result if an image_id is provided. If the image has been embedded before and cached, the cached result will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be embedded. The format should be compatible with the preproc_image method. |
required |
image_id
|
Optional[str]
|
An identifier for the image. If provided, the embedding result will be cached with this ID. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, Tuple[int, int]]: A tuple where the first element is the embedding of the image and the second element is the shape (height, width) of the processed image. |
Notes
- Embeddings and image sizes are cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM2_MAX_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Example
img_array = ... # some image array embed_image(img_array, image_id="sample123") (array([...]), (224, 224))
Source code in inference/models/sam2/segment_anything2.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Gets the list of files required for inference.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of file names. |
Source code in inference/models/sam2/segment_anything2.py
105 106 107 108 109 110 111 | |
infer_from_request
¶
infer_from_request(request)
Performs inference based on the request type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SamInferenceRequest
|
The inference request. |
required |
Returns:
| Type | Description |
|---|---|
|
Union[SamEmbeddingResponse, SamSegmentationResponse]: The inference response. |
Source code in inference/models/sam2/segment_anything2.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/sam2/segment_anything2.py
226 227 228 229 230 231 232 233 234 235 236 | |
segment_image
¶
segment_image(
image,
image_id=None,
prompts=None,
multimask_output=True,
mask_input=None,
save_logits_to_cache=False,
load_logits_from_cache=False,
**kwargs
)
Segments an image based on provided embeddings, points, masks, or cached results. If embeddings are not directly provided, the function can derive them from the input image or cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be segmented. |
required |
image_id
|
Optional[str]
|
A cached identifier for the image. Useful for accessing cached embeddings or masks. |
None
|
prompts
|
Optional[List[Sam2Prompt]]
|
List of prompts to use for segmentation. Defaults to None. |
None
|
mask_input
|
Optional[Union[ndarray, List[List[List[float]]]]]
|
Input low_res_logits for the image. |
None
|
multimask_output
|
Optional[bool]
|
(bool): Flag to decide if multiple masks proposal to be predicted (among which the most promising will be returned |
True
|
use_logits_cache
|
(bool): Flag to decide to use cached logits from prior prompting |
required | |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: Tuple of np.array, where: - first element is of size (prompt_set_size, h, w) and represent mask with the highest confidence for each prompt element - second element is of size (prompt_set_size, ) and represents ths score for most confident mask of each prompt element - third element is of size (prompt_set_size, 256, 256) and represents the low resolution logits for most confident mask of each prompt element |
Raises:
| Type | Description |
|---|---|
ValueError
|
If necessary inputs are missing or inconsistent. |
Notes
- Embeddings, segmentations, and low-resolution logits can be cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM_MAX_EMBEDDING_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Source code in inference/models/sam2/segment_anything2.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
Functions¶
choose_most_confident_sam_prediction
¶
choose_most_confident_sam_prediction(
masks, scores, low_resolution_logits
)
This function is supposed to post-process SAM2 inference and choose most confident
mask regardless of multimask_output parameter value
Args:
masks: np array with values 0.0 and 1.0 representing predicted mask of size
(prompt_set_size, proposed_maks, h, w) or (proposed_maks, h, w) - depending on
prompt set size - unfortunately, prompt_set_size=1 causes squeeze operation
in SAM2 library, so to handle inference uniformly, we need to compensate with
this function.
scores: array of size (prompt_set_size, proposed_maks) or (proposed_maks, ) depending
on prompt set size - this array gives confidence score for mask proposal
low_resolution_logits: array of size (prompt_set_size, proposed_maks, 256, 256) or
(proposed_maks, 256, 256) - depending on prompt set size. These low resolution logits
can be passed to a subsequent iteration as mask input.
Returns:
Tuple of np.array, where:
- first element is of size (prompt_set_size, h, w) and represent mask with the highest confidence
for each prompt element
- second element is of size (prompt_set_size, ) and represents ths score for most confident mask
of each prompt element
- third element is of size (prompt_set_size, 256, 256) and represents the low resolution logits
for most confident mask of each prompt element
Source code in inference/models/sam2/segment_anything2.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
find_prior_prompt_in_cache
¶
find_prior_prompt_in_cache(
initial_prompt_set, image_id, cache
)
Performs search over the cache to see if prior used prompts are subset of this one.
Source code in inference/models/sam2/segment_anything2.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
hash_prompt_set
¶
hash_prompt_set(image_id, prompt_set)
Computes unique hash from a prompt set.
Source code in inference/models/sam2/segment_anything2.py
364 365 366 367 368 | |
maybe_load_low_res_logits_from_cache
¶
maybe_load_low_res_logits_from_cache(
image_id, prompt_set, cache
)
Loads prior masks from the cache by searching over possibel prior prompts.
Source code in inference/models/sam2/segment_anything2.py
371 372 373 374 375 376 377 378 379 380 381 | |
pad_points
¶
pad_points(args)
Pad arguments to be passed to sam2 model with not_a_point label (-1). This is necessary when there are multiple prompts per image so that a tensor can be created.
Also pads empty point lists with a dummy non-point entry.
Source code in inference/models/sam2/segment_anything2.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
inference.models.sam2.segment_anything2_inference_models
¶
Classes¶
InferenceModelsSAM2Adapter
¶
Bases: Model
SegmentAnything class for handling segmentation tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
sam |
The segmentation model. |
|
embedding_cache |
Cache for embeddings. |
|
image_size_cache |
Cache for image sizes. |
|
embedding_cache_keys |
Keys for the embedding cache. |
Source code in inference/models/sam2/segment_anything2_inference_models.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
Functions¶
__init__
¶
__init__(
*args,
model_id=f"sam2/{SAM2_VERSION_ID}",
api_key=None,
low_res_logits_cache_size=SAM2_MAX_LOGITS_CACHE_SIZE,
embedding_cache_size=SAM2_MAX_EMBEDDING_CACHE_SIZE,
**kwargs,
)
Initializes the SegmentAnything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/sam2/segment_anything2_inference_models.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
embed_image
¶
embed_image(image, image_id=None, **kwargs)
Embeds an image and caches the result if an image_id is provided. If the image has been embedded before and cached, the cached result will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be embedded. The format should be compatible with the preproc_image method. |
required |
image_id
|
Optional[str]
|
An identifier for the image. If provided, the embedding result will be cached with this ID. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, Tuple[int, int]]: A tuple where the first element is the embedding of the image and the second element is the shape (height, width) of the processed image. |
Notes
- Embeddings and image sizes are cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM2_MAX_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Example
img_array = ... # some image array embed_image(img_array, image_id="sample123") (array([...]), (224, 224))
Source code in inference/models/sam2/segment_anything2_inference_models.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
infer_from_request
¶
infer_from_request(request)
Performs inference based on the request type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SamInferenceRequest
|
The inference request. |
required |
Returns:
| Type | Description |
|---|---|
|
Union[SamEmbeddingResponse, SamSegmentationResponse]: The inference response. |
Source code in inference/models/sam2/segment_anything2_inference_models.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/sam2/segment_anything2_inference_models.py
217 218 219 220 221 222 223 224 225 226 227 228 | |
segment_image
¶
segment_image(
image,
image_id=None,
prompts=None,
multimask_output=True,
mask_input=None,
save_logits_to_cache=False,
load_logits_from_cache=False,
**kwargs
)
Segments an image based on provided embeddings, points, masks, or cached results. If embeddings are not directly provided, the function can derive them from the input image or cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be segmented. |
required |
image_id
|
Optional[str]
|
A cached identifier for the image. Useful for accessing cached embeddings or masks. |
None
|
prompts
|
Optional[List[Sam2Prompt]]
|
List of prompts to use for segmentation. Defaults to None. |
None
|
mask_input
|
Optional[Union[ndarray, List[List[List[float]]]]]
|
Input low_res_logits for the image. |
None
|
multimask_output
|
Optional[bool]
|
(bool): Flag to decide if multiple masks proposal to be predicted (among which the most promising will be returned |
True
|
use_logits_cache
|
(bool): Flag to decide to use cached logits from prior prompting |
required | |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: Tuple of np.array, where: - first element is of size (prompt_set_size, h, w) and represent mask with the highest confidence for each prompt element - second element is of size (prompt_set_size, ) and represents ths score for most confident mask of each prompt element - third element is of size (prompt_set_size, 256, 256) and represents the low resolution logits for most confident mask of each prompt element |
Raises:
| Type | Description |
|---|---|
ValueError
|
If necessary inputs are missing or inconsistent. |
Notes
- Embeddings, segmentations, and low-resolution logits can be cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM_MAX_EMBEDDING_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Source code in inference/models/sam2/segment_anything2_inference_models.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
Functions¶
choose_most_confident_sam_prediction
¶
choose_most_confident_sam_prediction(
masks, scores, low_resolution_logits
)
This function is supposed to post-process SAM2 inference and choose most confident
mask regardless of multimask_output parameter value
Args:
masks: np array with values 0.0 and 1.0 representing predicted mask of size
(prompt_set_size, proposed_maks, h, w) or (proposed_maks, h, w) - depending on
prompt set size - unfortunately, prompt_set_size=1 causes squeeze operation
in SAM2 library, so to handle inference uniformly, we need to compensate with
this function.
scores: array of size (prompt_set_size, proposed_maks) or (proposed_maks, ) depending
on prompt set size - this array gives confidence score for mask proposal
low_resolution_logits: array of size (prompt_set_size, proposed_maks, 256, 256) or
(proposed_maks, 256, 256) - depending on prompt set size. These low resolution logits
can be passed to a subsequent iteration as mask input.
Returns:
Tuple of np.array, where:
- first element is of size (prompt_set_size, h, w) and represent mask with the highest confidence
for each prompt element
- second element is of size (prompt_set_size, ) and represents ths score for most confident mask
of each prompt element
- third element is of size (prompt_set_size, 256, 256) and represents the low resolution logits
for most confident mask of each prompt element
Source code in inference/models/sam2/segment_anything2_inference_models.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
pad_points
¶
pad_points(args)
Pad arguments to be passed to sam2 model with not_a_point label (-1). This is necessary when there are multiple prompts per image so that a tensor can be created.
Also pads empty point lists with a dummy non-point entry.
Source code in inference/models/sam2/segment_anything2_inference_models.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
models/sam3¶
inference.models.sam3.segment_anything3
¶
Classes¶
SegmentAnything3
¶
Bases: RoboflowCoreModel
SAM3 wrapper with a similar interface to SAM2 in this codebase.
Source code in inference/models/sam3/segment_anything3.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
Functions¶
inference.models.sam3.visual_segmentation
¶
Classes¶
Sam3ForInteractiveImageSegmentation
¶
Bases: RoboflowCoreModel
SegmentAnything3 class for handling segmentation tasks onm images with box prompting and point prompting, the way as SAM2 did.
Source code in inference/models/sam3/visual_segmentation.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
Functions¶
__init__
¶
__init__(
*args,
model_id="sam3/sam3_final",
low_res_logits_cache_size=SAM3_MAX_LOGITS_CACHE_SIZE,
embedding_cache_size=SAM3_MAX_EMBEDDING_CACHE_SIZE,
**kwargs
)
Initializes the SegmentAnything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/sam3/visual_segmentation.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
embed_image
¶
embed_image(image, image_id=None, **kwargs)
Embeds an image and caches the result if an image_id is provided. If the image has been embedded before and cached, the cached result will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be embedded. The format should be compatible with the preproc_image method. |
required |
image_id
|
Optional[str]
|
An identifier for the image. If provided, the embedding result will be cached with this ID. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, Tuple[int, int]]: A tuple where the first element is the embedding of the image and the second element is the shape (height, width) of the processed image. |
Notes
- Embeddings and image sizes are cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM2_MAX_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Example
img_array = ... # some image array embed_image(img_array, image_id="sample123") (array([...]), (224, 224))
Source code in inference/models/sam3/visual_segmentation.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Gets the list of files required for inference.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of file names. |
Source code in inference/models/sam3/visual_segmentation.py
114 115 116 117 118 119 120 | |
infer_from_request
¶
infer_from_request(request)
Performs inference based on the request type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SamInferenceRequest
|
The inference request. |
required |
Returns:
| Type | Description |
|---|---|
|
Union[SamEmbeddingResponse, SamSegmentationResponse]: The inference response. |
Source code in inference/models/sam3/visual_segmentation.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/sam3/visual_segmentation.py
215 216 217 218 219 220 221 222 223 224 225 | |
segment_image
¶
segment_image(
image,
image_id=None,
prompts=None,
multimask_output=True,
mask_input=None,
save_logits_to_cache=False,
load_logits_from_cache=False,
**kwargs
)
Segments an image based on provided embeddings, points, masks, or cached results. If embeddings are not directly provided, the function can derive them from the input image or cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image to be segmented. |
required |
image_id
|
Optional[str]
|
A cached identifier for the image. Useful for accessing cached embeddings or masks. |
None
|
prompts
|
Optional[List[Sam2Prompt]]
|
List of prompts to use for segmentation. Defaults to None. |
None
|
mask_input
|
Optional[Union[ndarray, List[List[List[float]]]]]
|
Input low_res_logits for the image. |
None
|
multimask_output
|
Optional[bool]
|
(bool): Flag to decide if multiple masks proposal to be predicted (among which the most promising will be returned |
True
|
use_logits_cache
|
(bool): Flag to decide to use cached logits from prior prompting |
required | |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
|
Tuple[np.ndarray, np.ndarray, np.ndarray]: Tuple of np.array, where: - first element is of size (prompt_set_size, h, w) and represent mask with the highest confidence for each prompt element - second element is of size (prompt_set_size, ) and represents ths score for most confident mask of each prompt element - third element is of size (prompt_set_size, 256, 256) and represents the low resolution logits for most confident mask of each prompt element |
Raises:
| Type | Description |
|---|---|
ValueError
|
If necessary inputs are missing or inconsistent. |
Notes
- Embeddings, segmentations, and low-resolution logits can be cached to improve performance on repeated requests for the same image.
- The cache has a maximum size defined by SAM_MAX_EMBEDDING_CACHE_SIZE. When the cache exceeds this size, the oldest entries are removed.
Source code in inference/models/sam3/visual_segmentation.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
Functions¶
choose_most_confident_sam_prediction
¶
choose_most_confident_sam_prediction(
masks, scores, low_resolution_logits
)
This function is supposed to post-process SAM2 inference and choose most confident
mask regardless of multimask_output parameter value
Args:
masks: np array with values 0.0 and 1.0 representing predicted mask of size
(prompt_set_size, proposed_maks, h, w) or (proposed_maks, h, w) - depending on
prompt set size - unfortunately, prompt_set_size=1 causes squeeze operation
in SAM2 library, so to handle inference uniformly, we need to compensate with
this function.
scores: array of size (prompt_set_size, proposed_maks) or (proposed_maks, ) depending
on prompt set size - this array gives confidence score for mask proposal
low_resolution_logits: array of size (prompt_set_size, proposed_maks, 256, 256) or
(proposed_maks, 256, 256) - depending on prompt set size. These low resolution logits
can be passed to a subsequent iteration as mask input.
Returns:
Tuple of np.array, where:
- first element is of size (prompt_set_size, h, w) and represent mask with the highest confidence
for each prompt element
- second element is of size (prompt_set_size, ) and represents ths score for most confident mask
of each prompt element
- third element is of size (prompt_set_size, 256, 256) and represents the low resolution logits
for most confident mask of each prompt element
Source code in inference/models/sam3/visual_segmentation.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |
find_prior_prompt_in_cache
¶
find_prior_prompt_in_cache(
initial_prompt_set, image_id, cache
)
Performs search over the cache to see if prior used prompts are subset of this one.
Source code in inference/models/sam3/visual_segmentation.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
hash_prompt_set
¶
hash_prompt_set(image_id, prompt_set)
Computes unique hash from a prompt set.
Source code in inference/models/sam3/visual_segmentation.py
422 423 424 425 426 | |
maybe_load_low_res_logits_from_cache
¶
maybe_load_low_res_logits_from_cache(
image_id, prompt_set, cache
)
Loads prior masks from the cache by searching over possibel prior prompts.
Source code in inference/models/sam3/visual_segmentation.py
429 430 431 432 433 434 435 436 437 438 | |
pad_points
¶
pad_points(args)
Pad arguments to be passed to sam2 model with not_a_point label (-1). This is necessary when there are multiple prompts per image so that a tensor can be created.
Also pads empty point lists with a dummy non-point entry.
Source code in inference/models/sam3/visual_segmentation.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
models/sam3_3d¶
inference.models.sam3_3d.segment_anything_3d
¶
Classes¶
Sam3_3D_ObjectsPipelineSingleton
¶
Singleton to cache the heavy 3D pipeline initialization.
Source code in inference/models/sam3_3d/segment_anything_3d.py
237 238 239 240 241 242 243 244 245 246 247 248 249 | |
SegmentAnything3_3D_Objects
¶
Bases: RoboflowCoreModel
Source code in inference/models/sam3_3d/segment_anything_3d.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
Functions¶
create_3d
¶
create_3d(
image,
mask_input=None,
*,
output_meshes=True,
output_scene=True,
with_mesh_postprocess=True,
with_texture_baking=True,
use_distillations=False,
**kwargs
)
Generate 3D from image and mask(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Optional[InferenceRequestImage]
|
Input image |
required |
mask_input
|
Optional[Any]
|
Mask in any supported format: - np.ndarray (H,W) or (N,H,W): Binary mask(s) - List[float]: COCO polygon [x1,y1,x2,y2,...] - List[List[float]]: Multiple polygons - Dict with 'counts'/'size': RLE mask - List[Dict]: Multiple RLE masks |
None
|
Source code in inference/models/sam3_3d/segment_anything_3d.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
download_model_from_roboflow_api
¶
download_model_from_roboflow_api()
Override parent method to use streaming downloads for large SAM3_3D model files.
Source code in inference/models/sam3_3d/segment_anything_3d.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["environment.json"]. |
Source code in inference/models/sam3_3d/segment_anything_3d.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
Functions¶
apply_gaussian_view_correction
¶
apply_gaussian_view_correction(scene_gs)
Apply view correction to Gaussian scene to match GLB orientation. Used for combined scene PLY.
Source code in inference/models/sam3_3d/segment_anything_3d.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
convert_mask_to_binary
¶
convert_mask_to_binary(mask_input, image_shape)
Convert polygon, RLE, or binary mask to binary mask (H, W) with values 0/255.
Source code in inference/models/sam3_3d/segment_anything_3d.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
make_scene_glb
¶
make_scene_glb(*outputs)
Combine multiple GLB meshes into a single scene. Applies layout transforms and a final view correction rotation.
Source code in inference/models/sam3_3d/segment_anything_3d.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
prepare_individual_object_for_export
¶
prepare_individual_object_for_export(gs)
Prepare an individual object Gaussian for PLY export.
Source code in inference/models/sam3_3d/segment_anything_3d.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
transform_glb_to_world
¶
transform_glb_to_world(
glb_mesh, rotation, translation, scale
)
Transform a GLB mesh from local to world coordinates.
Source code in inference/models/sam3_3d/segment_anything_3d.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
models/vit¶
inference.models.vit.vit_classification
¶
Classes¶
VitClassification
¶
Bases: ClassificationBaseOnnxRoboflowInferenceModel
VitClassification handles classification inference for Vision Transformer (ViT) models using ONNX.
Inherits
Attributes:
| Name | Type | Description |
|---|---|---|
multiclass |
bool
|
A flag that specifies if the model should handle multiclass classification. |
Source code in inference/models/vit/vit_classification.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Attributes¶
weights_file
property
¶
weights_file
Determines the weights file to be used based on the availability of AWS keys.
If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set, it returns the path to 'weights.onnx'. Otherwise, it returns the path to 'best.onnx'.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the weights file. |
Functions¶
__init__
¶
__init__(*args, **kwargs)
Initializes the VitClassification instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/vit/vit_classification.py
22 23 24 25 26 27 28 29 30 | |
models/yolact¶
inference.models.yolact.yolact_instance_segmentation
¶
Classes¶
YOLACT
¶
Bases: OnnxRoboflowInferenceModel
Roboflow ONNX Object detection model (Implements an object detection specific infer method)
Source code in inference/models/yolact/yolact_instance_segmentation.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the weights file. |
Functions¶
decode_masks
¶
decode_masks(boxes, masks, proto, img_dim)
Decodes the masks from the given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boxes
|
array
|
Bounding boxes. |
required |
masks
|
array
|
Masks. |
required |
proto
|
array
|
Proto data. |
required |
img_dim
|
tuple
|
Image dimensions. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: Decoded masks. |
Source code in inference/models/yolact/yolact_instance_segmentation.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
decode_predicted_bboxes
¶
decode_predicted_bboxes(loc, priors)
Decode predicted bounding box coordinates using the scheme employed by Yolov2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc
|
array
|
The predicted bounding boxes of size [num_priors, 4]. |
required |
priors
|
array
|
The prior box coordinates with size [num_priors, 4]. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: A tensor of decoded relative coordinates in point form with size [num_priors, 4]. |
Source code in inference/models/yolact/yolact_instance_segmentation.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
infer
¶
infer(
image,
class_agnostic_nms=False,
confidence=0.5,
iou_threshold=0.5,
max_candidates=3000,
max_detections=300,
return_image_dims=False,
**kwargs
)
Performs instance segmentation inference on a given image, post-processes the results, and returns the segmented instances as dictionaries containing their properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to segment. - can be a BGR numpy array, filepath, InferenceRequestImage, PIL Image, byte-string, etc. |
required |
class_agnostic_nms
|
bool
|
Whether to perform class-agnostic non-max suppression. Defaults to False. |
False
|
confidence
|
float
|
Confidence threshold for filtering weak detections. Defaults to 0.5. |
0.5
|
iou_threshold
|
float
|
Intersection-over-union threshold for non-max suppression. Defaults to 0.5. |
0.5
|
max_candidates
|
int
|
Maximum number of candidate detections to consider. Defaults to 3000. |
3000
|
max_detections
|
int
|
Maximum number of detections to return after non-max suppression. Defaults to 300. |
300
|
return_image_dims
|
bool
|
Whether to return the dimensions of the input image(s). Defaults to False. |
False
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
List[List[dict]]
|
List[List[dict]]: Each list contains dictionaries of segmented instances for a given image. Each dictionary contains: - x, y: Center coordinates of the instance. - width, height: Width and height of the bounding box around the instance. - class: Name of the detected class. - confidence: Confidence score of the detection. - points: List of points describing the segmented mask's boundary. - class_id: ID corresponding to the detected class. |
List[List[dict]]
|
If |
List[List[dict]]
|
second element is the list of image dimensions. |
Notes
- The function supports processing multiple images in a batch.
- If an input list of images is provided, the function returns a list of lists, where each inner list corresponds to the detections for a specific image.
- The function internally uses an ONNX model for inference.
Source code in inference/models/yolact/yolact_instance_segmentation.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
make_response
¶
make_response(
predictions, img_dims, class_filter=None, **kwargs
)
Constructs a list of InstanceSegmentationInferenceResponse objects based on the provided predictions and image dimensions, optionally filtering by class name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[List[dict]]
|
A list containing batch predictions, where each inner list contains dictionaries of segmented instances for a given image. |
required |
img_dims
|
List[Tuple[int, int]]
|
List of tuples specifying the dimensions of each image in the format (height, width). |
required |
class_filter
|
List[str]
|
A list of class names to filter the predictions by. If not provided, all predictions are included. |
None
|
Returns:
| Type | Description |
|---|---|
List[InstanceSegmentationInferenceResponse]
|
List[InstanceSegmentationInferenceResponse]: A list of response objects, each containing the filtered |
List[InstanceSegmentationInferenceResponse]
|
predictions and corresponding image dimensions for a given image. |
Examples:
>>> predictions = [[{"class_name": "cat", ...}, {"class_name": "dog", ...}], ...]
>>> img_dims = [(300, 400), ...]
>>> responses = make_response(predictions, img_dims, class_filter=["cat"])
>>> len(responses[0].predictions) # Only predictions with "cat" class are included
1
Source code in inference/models/yolact/yolact_instance_segmentation.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
Functions¶
models/yolo26¶
inference.models.yolo26.yolo26_instance_segmentation
¶
Classes¶
YOLO26InstanceSegmentation
¶
Bases: YOLOv11InstanceSegmentation
YOLO26 Instance Segmentation model with end-to-end ONNX output.
YOLO26 exports with NMS already applied, outputting: - predictions: (batch, num_detections, 38) where 38 = 6 + 32 mask coefficients Format: [x1, y1, x2, y2, confidence, class_index, mask_coeff_0, ..., mask_coeff_31] - protos: (batch, 32, H, W) mask prototypes
Source code in inference/models/yolo26/yolo26_instance_segmentation.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
Functions¶
make_response
¶
make_response(
predictions,
masks,
img_dims,
class_filter=None,
*args,
**kwargs
)
Constructs instance segmentation response objects.
YOLO26 prediction format: [x1, y1, x2, y2, conf, class_idx, mask_coeffs...]
Source code in inference/models/yolo26/yolo26_instance_segmentation.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
postprocess
¶
postprocess(
predictions,
preprocess_return_metadata,
confidence=DEFAULT_CONFIDENCE,
mask_decode_mode=DEFAULT_MASK_DECODE_MODE,
tradeoff_factor=DEFAULT_TRADEOFF_FACTOR,
**kwargs
)
Postprocesses the instance segmentation predictions.
YOLO26 predictions come with NMS already applied, so we just need to: 1. Filter by confidence 2. Decode masks 3. Format response
Source code in inference/models/yolo26/yolo26_instance_segmentation.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
predict
¶
predict(img_in, **kwargs)
Performs inference on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Predictions and mask prototypes. |
Source code in inference/models/yolo26/yolo26_instance_segmentation.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Functions¶
inference.models.yolo26.yolo26_keypoints_detection
¶
Classes¶
YOLO26KeypointsDetection
¶
Bases: YOLOv11KeypointsDetection
YOLO26 Keypoints Detection model with end-to-end ONNX output.
YOLO26 exports with NMS already applied, outputting: - predictions: (batch, num_detections, 57) for COCO pose (17 keypoints * 3 + 6) Format: [x1, y1, x2, y2, confidence, class_index, kp0_x, kp0_y, kp0_conf, ...]
Source code in inference/models/yolo26/yolo26_keypoints_detection.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
Functions¶
make_response
¶
make_response(
predictions,
img_dims,
class_filter=None,
*args,
**kwargs
)
Constructs keypoints detection response objects.
YOLO26 prediction format: [x1, y1, x2, y2, conf, class_idx, keypoints...]
Source code in inference/models/yolo26/yolo26_keypoints_detection.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
postprocess
¶
postprocess(
predictions,
preproc_return_metadata,
confidence=DEFAULT_CONFIDENCE,
**kwargs
)
Postprocesses the keypoints detection predictions.
YOLO26 predictions come with NMS already applied, so we just need to: 1. Filter by confidence 2. Scale coordinates to original image size 3. Format response
Source code in inference/models/yolo26/yolo26_keypoints_detection.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
predict
¶
predict(img_in, **kwargs)
Performs inference on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ...]
|
Tuple[np.ndarray]: Predictions with boxes, confidence, class, and keypoints. |
Source code in inference/models/yolo26/yolo26_keypoints_detection.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
Functions¶
models/yolo_world¶
inference.models.yolo_world.yolo_world
¶
Classes¶
YOLOWorld
¶
Bases: RoboflowCoreModel
YOLO-World class for zero-shot object detection.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The YOLO-World model. |
Source code in inference/models/yolo_world/yolo_world.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
Functions¶
__init__
¶
__init__(*args, model_id='yolo_world/l', **kwargs)
Initializes the YOLO-World model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Source code in inference/models/yolo_world/yolo_world.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
get_infer_bucket_file_list
¶
get_infer_bucket_file_list()
Get the list of required files for inference.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of required files for inference, e.g., ["model.pt"]. |
Source code in inference/models/yolo_world/yolo_world.py
230 231 232 233 234 235 236 | |
infer
¶
infer(
image=None,
text=None,
confidence=DEFAULT_CONFIDENCE,
max_detections=DEFAUlT_MAX_DETECTIONS,
iou_threshold=DEFAULT_IOU_THRESH,
max_candidates=DEFAULT_MAX_CANDIDATES,
class_agnostic_nms=DEFAULT_CLASS_AGNOSTIC_NMS,
**kwargs
)
Run inference on a provided image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_filter
|
Optional[List[str]]
|
A list of class names to filter, if provided. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GroundingDINOInferenceRequest |
The inference response. |
Source code in inference/models/yolo_world/yolo_world.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
infer_from_request
¶
infer_from_request(request)
Perform inference based on the details provided in the request, and return the associated responses.
Source code in inference/models/yolo_world/yolo_world.py
76 77 78 79 80 81 82 83 84 | |
preproc_image
¶
preproc_image(image)
Preprocesses an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
InferenceRequestImage
|
The image to preprocess. |
required |
Returns:
| Type | Description |
|---|---|
|
np.array: The preprocessed image. |
Source code in inference/models/yolo_world/yolo_world.py
64 65 66 67 68 69 70 71 72 73 74 | |
set_classes
¶
set_classes(text)
Set the class names for the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
list
|
The class names. |
required |
Source code in inference/models/yolo_world/yolo_world.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
Functions¶
models/yolov10¶
inference.models.yolov10.yolov10_object_detection
¶
Classes¶
YOLOv10ObjectDetection
¶
Bases: ObjectDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX Object detection model (Implements an object detection specific infer method).
This class is responsible for performing object detection using the YOLOv10 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Methods:
| Name | Description |
|---|---|
predict |
Performs object detection on the given image using the ONNX session. |
Source code in inference/models/yolov10/yolov10_object_detection.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv10 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
postprocess
¶
postprocess(
predictions,
preproc_return_metadata,
confidence=DEFAULT_CONFIDENCE,
max_detections=DEFAUlT_MAX_DETECTIONS,
**kwargs
)
Postprocesses the object detection predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
ndarray
|
Raw predictions from the model. |
required |
img_dims
|
List[Tuple[int, int]]
|
Dimensions of the images. |
required |
confidence
|
float
|
Confidence threshold for filtering detections. Default is 0.5. |
DEFAULT_CONFIDENCE
|
max_detections
|
int
|
Maximum number of final detections. Default is 300. |
DEFAUlT_MAX_DETECTIONS
|
Returns:
| Type | Description |
|---|---|
List[ObjectDetectionInferenceResponse]
|
List[ObjectDetectionInferenceResponse]: The post-processed predictions. |
Source code in inference/models/yolov10/yolov10_object_detection.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: NumPy array representing the predictions, including boxes, confidence scores, and class confidence scores. |
Source code in inference/models/yolov10/yolov10_object_detection.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Functions¶
models/yolov5¶
inference.models.yolov5.yolov5_instance_segmentation
¶
Classes¶
YOLOv5InstanceSegmentation
¶
Bases: InstanceSegmentationBaseOnnxRoboflowInferenceModel
YOLOv5 Instance Segmentation ONNX Inference Model.
This class is responsible for performing instance segmentation using the YOLOv5 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Source code in inference/models/yolov5/yolov5_instance_segmentation.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv5 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
predict
¶
predict(img_in, **kwargs)
Performs inference on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Tuple containing two NumPy arrays representing the predictions. |
Source code in inference/models/yolov5/yolov5_instance_segmentation.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
inference.models.yolov5.yolov5_object_detection
¶
Classes¶
YOLOv5ObjectDetection
¶
Bases: ObjectDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX Object detection model (Implements an object detection specific infer method).
This class is responsible for performing object detection using the YOLOv5 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Source code in inference/models/yolov5/yolov5_object_detection.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv5 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: NumPy array representing the predictions. |
Source code in inference/models/yolov5/yolov5_object_detection.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
models/yolov7¶
inference.models.yolov7.yolov7_instance_segmentation
¶
Classes¶
YOLOv7InstanceSegmentation
¶
Bases: InstanceSegmentationBaseOnnxRoboflowInferenceModel
YOLOv7 Instance Segmentation ONNX Inference Model.
This class is responsible for performing instance segmentation using the YOLOv7 model with ONNX runtime.
Methods:
| Name | Description |
|---|---|
predict |
Performs inference on the given image using the ONNX session. |
Source code in inference/models/yolov7/yolov7_instance_segmentation.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
Functions¶
predict
¶
predict(img_in, **kwargs)
Performs inference on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Tuple containing two NumPy arrays representing the predictions and protos. |
Source code in inference/models/yolov7/yolov7_instance_segmentation.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
models/yolov8¶
inference.models.yolov8.yolov8_instance_segmentation
¶
Classes¶
YOLOv8InstanceSegmentation
¶
Bases: InstanceSegmentationBaseOnnxRoboflowInferenceModel
YOLOv8 Instance Segmentation ONNX Inference Model.
This class is responsible for performing instance segmentation using the YOLOv8 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Methods:
| Name | Description |
|---|---|
predict |
Performs inference on the given image using the ONNX session. |
Source code in inference/models/yolov8/yolov8_instance_segmentation.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv8 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
predict
¶
predict(img_in, **kwargs)
Performs inference on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Tuple containing two NumPy arrays representing the predictions and protos. The predictions include boxes, confidence scores, class confidence scores, and masks. |
Source code in inference/models/yolov8/yolov8_instance_segmentation.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
inference.models.yolov8.yolov8_keypoints_detection
¶
Classes¶
YOLOv8KeypointsDetection
¶
Bases: KeypointsDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX keypoints detection model (Implements an object detection specific infer method).
This class is responsible for performing keypoints detection using the YOLOv8 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Methods:
| Name | Description |
|---|---|
predict |
Performs object detection on the given image using the ONNX session. |
Source code in inference/models/yolov8/yolov8_keypoints_detection.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv8 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
keypoints_count
¶
keypoints_count()
Returns the number of keypoints in the model.
Source code in inference/models/yolov8/yolov8_keypoints_detection.py
59 60 61 62 63 | |
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ...]
|
Tuple[np.ndarray]: NumPy array representing the predictions, including boxes, confidence scores, and class confidence scores. |
Source code in inference/models/yolov8/yolov8_keypoints_detection.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
Functions¶
inference.models.yolov8.yolov8_object_detection
¶
Classes¶
YOLOv8ObjectDetection
¶
Bases: ObjectDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX Object detection model (Implements an object detection specific infer method).
This class is responsible for performing object detection using the YOLOv8 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Methods:
| Name | Description |
|---|---|
predict |
Performs object detection on the given image using the ONNX session. |
Source code in inference/models/yolov8/yolov8_object_detection.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv8 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: NumPy array representing the predictions, including boxes, confidence scores, and class confidence scores. |
Source code in inference/models/yolov8/yolov8_object_detection.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
models/yolov9¶
inference.models.yolov9.yolov9_object_detection
¶
Classes¶
YOLOv9ObjectDetection
¶
Bases: ObjectDetectionBaseOnnxRoboflowInferenceModel
Roboflow ONNX Object detection model (Implements an object detection specific infer method).
This class is responsible for performing object detection using the YOLOv9 model with ONNX runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
weights_file |
str
|
Path to the ONNX weights file. |
Source code in inference/models/yolov9/yolov9_object_detection.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
Attributes¶
weights_file
property
¶
weights_file
Gets the weights file for the YOLOv9 model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Path to the ONNX weights file. |
Functions¶
predict
¶
predict(img_in, **kwargs)
Performs object detection on the given image using the ONNX session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
ndarray
|
Input image as a NumPy array. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: NumPy array representing the predictions. |
Source code in inference/models/yolov9/yolov9_object_detection.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
usage_tracking¶
Anonymous usage and telemetry reporting.
inference.usage_tracking.redis_queue
¶
Classes¶
RedisQueue
¶
Store and forget, keys with specified hash tag are handled by external service
Source code in inference/usage_tracking/redis_queue.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |