local model
LocalModel Module
This module provides the LocalModel
class that allows loading, inference,
and benchmark testing of models in a local environment. It supports detection
and segmentation tasks, and utilizes ONNXRuntime for model execution.
Classes:
Name | Description |
---|---|
LocalModel |
A class for managing and interacting with local models. |
Functions:
Name | Description |
---|---|
__init__ |
Initializes the LocalModel instance, loading the model, metadata, and setting up the runtime. |
_read_metadata |
Reads the model metadata from a JSON file. |
_annotate |
Annotates the input image with detection or segmentation results. |
infer |
Runs inference on an input image, with optional annotation. |
benchmark |
Benchmarks the model's inference performance over a specified number of iterations and input size. |
LocalModel
#
Source code in focoos/local_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 |
|
__init__(model_dir, runtime_type=FOCOOS_CONFIG.runtime_type)
#
Initialize the LocalModel instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_dir |
Union[str, Path]
|
Path to the model directory. |
required |
runtime_type |
RuntimeTypes
|
Type of runtime to use. Defaults to FOCOOS_CONFIG.runtime_type. |
runtime_type
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified model directory does not exist. |
Initializes the model, loads metadata, and prepares the runtime environment for inference.
Source code in focoos/local_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 |
|
benchmark(iterations, size)
#
Benchmark the model's inference performance over multiple iterations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterations |
int
|
Number of iterations to run for benchmarking. |
required |
size |
int
|
The input size for each benchmark iteration. |
required |
Returns:
Name | Type | Description |
---|---|---|
LatencyMetrics |
LatencyMetrics
|
Latency metrics including time taken for inference. |
Source code in focoos/local_model.py
186 187 188 189 190 191 192 193 194 195 196 197 |
|
infer(image, threshold=0.5, annotate=False)
#
Run inference on an input image and optionally annotate the results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
Union[bytes, str, Path, ndarray, Image]
|
The input image to infer on. |
required |
threshold |
float
|
The confidence threshold for detections. Defaults to 0.5. |
0.5
|
annotate |
bool
|
Whether to annotate the image with detection results. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Tuple[FocoosDetections, Optional[ndarray]]
|
Tuple[FocoosDetections, Optional[np.ndarray]]: The detections from the inference and the annotated image (if applicable). |
Raises:
Type | Description |
---|---|
ValueError
|
If the model is not deployed locally. |
Source code in focoos/local_model.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 183 184 |
|