Skip to content

Inference

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

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
class BaseRequest(BaseModel):
    """Base request for inference.

    Attributes:
        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
    """

    def __init__(self, **kwargs):
        kwargs["id"] = kwargs.get("id", str(uuid4()))
        super().__init__(**kwargs)

    model_config = ConfigDict(protected_namespaces=())
    id: str
    api_key: Optional[str] = ApiKey
    usage_billable: bool = True
    start: Optional[float] = None
    source: Optional[str] = None
    source_info: Optional[str] = None

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
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
class CVInferenceRequest(InferenceRequest):
    """Computer Vision inference request.

    Attributes:
        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.
    """

    image: Union[List[InferenceRequestImage], InferenceRequestImage]
    disable_preproc_auto_orient: Optional[bool] = Field(
        default=False,
        description="If true, the auto orient preprocessing step is disabled for this call.",
    )
    disable_preproc_contrast: Optional[bool] = Field(
        default=False,
        description="If true, the auto contrast preprocessing step is disabled for this call.",
    )
    disable_preproc_grayscale: Optional[bool] = Field(
        default=False,
        description="If true, the grayscale preprocessing step is disabled for this call.",
    )
    disable_preproc_static_crop: Optional[bool] = Field(
        default=False,
        description="If true, the static crop preprocessing step is disabled for this call.",
    )

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
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
class ClassificationInferenceRequest(CVInferenceRequest):
    """Classification inference request.

    Attributes:
        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.
    """

    def __init__(self, **kwargs):
        kwargs["model_type"] = "classification"
        super().__init__(**kwargs)

    confidence: Optional[float] = Field(
        default=0.4,
        examples=[0.5],
        description="The confidence threshold used to filter out predictions",
    )
    visualization_stroke_width: Optional[int] = Field(
        default=1,
        examples=[1],
        description="The stroke width used when visualizing predictions",
    )
    visualize_predictions: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, the predictions will be drawn on the original image and returned as a base64 string",
    )
    disable_active_learning: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, the predictions will be prevented from registration by Active Learning (if the functionality is enabled)",
    )
    active_learning_target_dataset: Optional[str] = Field(
        default=None,
        examples=["my_dataset"],
        description="Parameter to be used when Active Learning data registration should happen against different dataset than the one pointed by model_id",
    )

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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class DepthEstimationRequest(InferenceRequest):
    """Request for depth estimation.

    Attributes:
        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.
    """

    image: Union[List[InferenceRequestImage], InferenceRequestImage]
    model_id: Optional[str] = Field(None)
    depth_version_id: Optional[str] = Field(
        default="small",
        examples=["small"],
        description="The version ID of the depth estimation model",
    )

    @validator("model_id", always=True)
    def validate_model_id(cls, value, values):
        if value is not None:
            return value
        if values.get("depth_version_id") is None:
            return None
        return f"depth-anything-v2/{values['depth_version_id']}"

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
31
32
33
34
35
36
37
38
39
40
class InferenceRequest(BaseRequest):
    """Base request for inference.

    Attributes:
        model_id (str): A unique model identifier.
        model_type (Optional[str]): The type of the model, usually referring to what task the model performs.
    """

    model_id: Optional[str] = ModelID
    model_type: Optional[str] = ModelType

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class InferenceRequestImage(BaseModel):
    """Image data for inference request.

    Attributes:
        type (str): The type of image data provided, one of 'url', 'base64', or 'numpy'.
        value (Optional[Any]): Image data corresponding to the image type.
    """

    type: str = Field(
        examples=["url"],
        description="The type of image data provided, one of 'url', 'base64', or 'numpy'",
    )
    value: Optional[Any] = Field(
        None,
        examples=["http://www.example-image-url.com"],
        description="Image data corresponding to the image type, if type = 'url' then value is a string containing the url of an image, else if type = 'base64' then value is a string containing base64 encoded image data, else if type = 'numpy' then value is binary numpy data serialized using pickle.dumps(); array should 3 dimensions, channels last, with values in the range [0,255].",
    )

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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
class InstanceSegmentationInferenceRequest(ObjectDetectionInferenceRequest):
    """Instance Segmentation inference request.

    Attributes:
        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'.
    """

    mask_decode_mode: Optional[str] = Field(
        default="accurate",
        examples=["accurate"],
        description="The mode used to decode instance segmentation masks, one of 'accurate', 'fast', 'tradeoff'",
    )
    tradeoff_factor: Optional[float] = Field(
        default=0.0,
        examples=[0.5],
        description="The amount to tradeoff between 0='fast' and 1='accurate'",
    )

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
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
class ObjectDetectionInferenceRequest(CVInferenceRequest):
    """Object Detection inference request.

    Attributes:
        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.
    """

    class_agnostic_nms: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, NMS is applied to all detections at once, if false, NMS is applied per class",
    )
    class_filter: Optional[List[str]] = Field(
        default=None,
        examples=[["class-1", "class-2", "class-n"]],
        description="If provided, only predictions for the listed classes will be returned",
    )
    confidence: Optional[float] = Field(
        default=0.4,
        examples=[0.5],
        description="The confidence threshold used to filter out predictions",
    )
    fix_batch_size: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, the batch size will be fixed to the maximum batch size configured for this server",
    )
    iou_threshold: Optional[float] = Field(
        default=0.3,
        examples=[0.5],
        description="The IoU threhsold that must be met for a box pair to be considered duplicate during NMS",
    )
    max_detections: Optional[int] = Field(
        default=300,
        examples=[300],
        description="The maximum number of detections that will be returned",
    )
    max_candidates: Optional[int] = Field(
        default=3000,
        description="The maximum number of candidate detections passed to NMS",
    )
    visualization_labels: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, labels will be rendered on prediction visualizations",
    )
    visualization_stroke_width: Optional[int] = Field(
        default=1,
        examples=[1],
        description="The stroke width used when visualizing predictions",
    )
    visualize_predictions: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, the predictions will be drawn on the original image and returned as a base64 string",
    )
    disable_active_learning: Optional[bool] = Field(
        default=False,
        examples=[False],
        description="If true, the predictions will be prevented from registration by Active Learning (if the functionality is enabled)",
    )
    active_learning_target_dataset: Optional[str] = Field(
        default=None,
        examples=["my_dataset"],
        description="Parameter to be used when Active Learning data registration should happen against different dataset than the one pointed by model_id",
    )

request_from_type(model_type, request_dict)

Uses original request id

Source code in inference/core/entities/requests/inference.py
272
273
274
275
276
277
278
279
280
281
282
283
def request_from_type(model_type, request_dict):
    """Uses original request id"""
    if model_type == "classification":
        request = ClassificationInferenceRequest(**request_dict)
    elif model_type == "instance-segmentation":
        request = InstanceSegmentationInferenceRequest(**request_dict)
    elif model_type == "object-detection":
        request = ObjectDetectionInferenceRequest(**request_dict)
    else:
        raise ValueError(f"Unknown task type {model_type}")
    request.id = request_dict.get("id", request.id)
    return request