LicensePlateRecognizer¶
LicensePlateRecognizer is the main ONNX Runtime inference entry point. It accepts file paths, NumPy arrays,
lists of images, and pre-batched arrays, and returns a list of PlatePrediction objects.
When passing NumPy arrays, they should already match the model configuration: uint8, channels_last, and the
expected color mode (grayscale or RGB). For RGB models, arrays are assumed to be RGB, not OpenCV-style BGR.
from fast_plate_ocr import LicensePlateRecognizer
recognizer = LicensePlateRecognizer("cct-s-v2-global-model")
predictions = recognizer.run("test_plate.png")
ONNX Runtime inference class for license plate recognition.
The current OCR models available from the HUB are:
cct-s-v2-global-model: OCR model trained with global plates data. Based on Compact Convolutional Transformer (CCT) architecture. This is the recommended S default.cct-xs-v2-global-model: OCR model trained with global plates data. Based on Compact Convolutional Transformer (CCT) architecture. This is the XS variant of the v2 family.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
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 220 221 | |
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
|
int
|
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,
remove_pad_char: bool = True,
) -> list[PlatePrediction]
Run plate recognition on one or more images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | list[str] | NDArray | list[NDArray]
|
One or more image inputs, which can be:
Inputs are resized/converted as needed according to the loaded |
required |
return_confidence
|
bool
|
If |
False
|
remove_pad_char
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
list[PlatePrediction]
|
A list of |
list[PlatePrediction]
|
|
list[PlatePrediction]
|
|
list[PlatePrediction]
|
|
list[PlatePrediction]
|
|
Source code in fast_plate_ocr/inference/plate_recognizer.py
run_one ¶
run_one(
source: str | NDArray,
return_confidence: bool = False,
remove_pad_char: bool = True,
) -> PlatePrediction
Convenience wrapper around run() for single-image inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | NDArray
|
A single image input (path or NumPy array). |
required |
return_confidence
|
bool
|
Whether to include per-character confidences. |
False
|
remove_pad_char
|
bool
|
Whether to remove trailing configured padding characters from decoded plate text. |
True
|
Returns:
| Type | Description |
|---|---|
PlatePrediction
|
A single |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input resolves to anything other than exactly one sample. |