LicensePlateRecognizer
ONNX inference class for performing license plates OCR.
The current OCR models available from the HUB are:
cct-s-v1-global-model
: OCR model trained with global plates data. Based on Compact Convolutional Transformer (CCT) architecture. This is the S variant.cct-xs-v1-global-model
: OCR model trained with global plates data. Based on Compact Convolutional Transformer (CCT) architecture. This is the XS variant.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
|
onnx_model_path
|
PathLike | None
|
Path to ONNX model file to use (In case you want to use a custom one). |
None
|
plate_config_path
|
PathLike | 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/plate_recognizer.py
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 |
|
benchmark ¶
benchmark(
n_iter: int = 2500,
batch_size: int = 1,
include_processing: bool = False,
warmup: int = 250,
) -> None
Run an inference benchmark and pretty print the results.
It reports the following metrics:
- Average latency per batch (milliseconds)
- Throughput in plates / second (PPS), i.e., how many plates the pipeline can process
per second at the chosen
batch_size
.
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. |
2500
|
batch_size
|
Batch size to use for the benchmark. |
1
|
|
include_processing
|
bool
|
Indicates whether the benchmark should include preprocessing and postprocessing times in the measurement. |
False
|
warmup
|
int
|
Number of warmup iterations to run before the benchmark. |
250
|
Source code in fast_plate_ocr/inference/plate_recognizer.py
run ¶
run(
source: str | list[str] | NDArray | list[NDArray],
return_confidence: bool = False,
) -> tuple[list[str], NDArray] | list[str]
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]
|
One or more image inputs, which can be:
Images will be automatically resized and converted as needed based on the model's configuration (including color mode and aspect ratio settings). |
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 recognized license plates (one per image). If |
tuple[list[str], NDArray] | list[str]
|
also returns a NumPy array of shape |
tuple[list[str], NDArray] | list[str]
|
for each predicted character. |