Reference
ONNX inference module.
ONNXPlateRecognizer
¶
ONNX inference class for performing license plates OCR.
Source code in fast_plate_ocr/inference/onnx_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 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 |
|
__init__(hub_ocr_model=None, device='auto', providers=None, sess_options=None, model_path=None, config_path=None, force_download=False)
¶
Initializes the ONNXPlateRecognizer with the specified OCR model and inference device.
The current OCR models available from the HUB are:
argentinian-plates-cnn-model
: OCR for Argentinian license plates. Uses fully conv architecture.argentinian-plates-cnn-synth-model
: OCR for Argentinian license plates trained with synthetic and real data. Uses fully conv architecture.european-plates-mobile-vit-v2-model
: OCR for European license plates. Uses MobileVIT-2 for the backbone.global-plates-mobile-vit-v2-model
: OCR for Global license plates (+65 countries). Uses MobileVIT-2 for the backbone.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hub_ocr_model |
OcrModel | None
|
Name of the OCR model to use from the HUB. |
None
|
device |
Literal['cuda', 'cpu', 'auto']
|
Device type for inference. Should be one of ('cpu', 'cuda', 'auto'). If
'auto' mode, the device will be deduced from
|
'auto'
|
providers |
Sequence[str | tuple[str, dict]] | None
|
Optional sequence of providers in order of decreasing precedence. If not specified, all available providers are used based on the device argument. |
None
|
sess_options |
SessionOptions | None
|
Advanced session options for ONNX Runtime. |
None
|
model_path |
str | PathLike[str] | None
|
Path to ONNX model file to use (In case you want to use a custom one). |
None
|
config_path |
str | PathLike[str] | None
|
Path to config file to use (In case you want to use a custom one). |
None
|
force_download |
bool
|
Force and download the model, even if it already exists. |
False
|
Returns: None.
Source code in fast_plate_ocr/inference/onnx_inference.py
benchmark(n_iter=10000, include_processing=False)
¶
Benchmark time taken to run the OCR model. This reports the average inference time and the throughput in plates per second.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_iter |
int
|
The number of iterations to run the benchmark. This determines how many times the inference will be executed to compute the average performance metrics. |
10000
|
include_processing |
bool
|
Indicates whether the benchmark should include preprocessing and postprocessing times in the measurement. |
False
|
Source code in fast_plate_ocr/inference/onnx_inference.py
run(source, return_confidence=False)
¶
Performs OCR to recognize license plate characters from an image or a list of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str | list[str] | NDArray | list[NDArray]
|
The path(s) to the image(s), a numpy array representing an image or a list
of NumPy arrays. If a numpy array is provided, it is expected to already be in
grayscale format, with shape |
required |
return_confidence |
bool
|
Whether to return confidence scores along with plate predictions. |
False
|
Returns:
Type | Description |
---|---|
tuple[list[str], NDArray] | list[str]
|
A list of plates for each input image. If |