instance_segmentation_base
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 |
|
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.5. |
DEFAULT_CONFIDENCE
|
iou_threshold
|
float
|
IoU threshold for non-maximum suppression. Defaults to 0.5. |
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 |
|
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
InstanceSegmentationInferenceResponse
object. - Each response contains a list of
InstanceSegmentationPrediction
objects.
Source code in inference/core/models/instance_segmentation_base.py
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 |
|
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
276 277 278 279 280 281 282 283 284 285 286 287 288 |
|