base
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 |
|
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(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(*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 |
|
clear_cache()
¶
Clears any cache if necessary. This method should be implemented in derived classes as needed.
Source code in inference/core/models/base.py
95 96 97 |
|
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_predictions
is 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
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 |
|
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(*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
145 146 147 148 149 150 151 152 153 154 155 156 157 |
|