- Version: 20261019
- Source Code Copyright: Apache License 2.0 — sirius-ai/LPRNet_Pytorch
- Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.
Console/terminal demo of Chinese license-plate recognition with LPRNet (PyTorch) for Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon): end-to-end plate-string recognition from 94x24 crops with CTC greedy decoding. A pretrained model ships with the project, so inference works out of the box. Training and inference run on the GPU (CUDA on Windows/Linux, MPS on Apple Silicon) and fall back to the CPU automatically. Based on LPRNet_Pytorch (Apache-2.0).
[Prerequisites]
- Python 3.14, installed by src\01_python_install_windows.bat (winget), src/01_python_install_linux.sh (apt, deadsnakes PPA when needed; uses sudo) or src/01_python_install_mac.sh (Homebrew).
- The venv scripts install PyTorch 2.13.0 first (torchvision is not needed), then src/requirements.txt (numpy, opencv-python, Pillow, matplotlib, imutils).
- Windows / Linux: the CUDA 13.0 (cu130) build. GPU use needs an NVIDIA Turing or newer GPU (GTX 16 / RTX 20 series and later) with a driver supporting CUDA 13.0 or newer (check nvidia-smi); without one the same build runs on the CPU.
- macOS: the PyPI build, using the Apple GPU through MPS. Apple Silicon (arm64) with macOS 14+ only; Intel Macs are not supported by PyTorch 2.13.0.
[Launcher Scripts]
1. 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh
Install Python 3.14 (winget / apt + deadsnakes / Homebrew). Skips when it is already installed.
2. 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh
Delete the old venv/, create a fresh one with Python 3.14, install PyTorch 2.13.0 (CUDA 13.0 build on Windows/Linux, PyPI/MPS build on macOS), then src/requirements.txt. Aborts loudly if pip fails; prints whether CUDA (or MPS) is available.
3. 03_venv_activate.bat / 03_venv_activate.sh
Activate the venv. On Linux/macOS, source it: source src/03_venv_activate.sh. If the project folder was renamed after the venv was created, re-create the venv with 02_venv_create_windows/linux/mac first; the other launchers do not need activation.
4. 04_train.bat / 04_train.sh
Train LPRNet (checkpoints to model/train/).
5. 05_inference.bat / 05_inference.sh
Recognize one plate crop (seconds).
6. 06_inference_folder.bat / 06_inference_folder.sh
Recognize every plate in data/test and report accuracy.
7. 99_venv_clean.bat / 99_venv_clean.sh
Delete the venv folder.
8. 99_venv_deactivate.bat / 99_venv_deactivate.sh
Deactivate the venv in the current shell. On Linux/macOS, source it: source src/99_venv_deactivate.sh (bash or zsh).
Extra arguments are forwarded to the Python entry point, e.g. src\05_inference.bat --device cpu.
[Python Entry Points]
src/train.py
[--train-dir data/train] [--test-dir data/test] [--learning-rate 0.01] [--train-batch-size 8] [--max-epoch 50] [--save-folder model/train/] [--pretrained-model model/pretrained_LPRNet_model.pth] [--device auto]. The shipped model is never overwritten; progress is printed to the console.
src/inference.py
[--image CROP] [--model model/pretrained_LPRNet_model.pth] [--show] [--device auto]. Prints the plate; saves model/inference/single.png.
src/inference_folder.py
[--folder data/test] [--model ...] [--no-save] [--device auto]. Per-plate results + accuracy; annotated images to model/inference/.
--device: auto (default) picks CUDA → MPS → CPU; cuda, cuda:N, mps or cpu forces a device. The selected device is printed at startup.
[Quick Start]
Windows 11
src\01_python_install_windows.bat
src\02_venv_create_windows.bat
src\05_inference.bat
src\06_inference_folder.bat
src\04_train.bat
Ubuntu 24.04
bash src/01_python_install_linux.sh
bash src/02_venv_create_linux.sh
bash src/05_inference.sh
bash src/06_inference_folder.sh
bash src/04_train.sh
macOS 14+ (Apple Silicon)
bash src/01_python_install_mac.sh
bash src/02_venv_create_mac.sh
bash src/05_inference.sh
bash src/06_inference_folder.sh
bash src/04_train.sh
[GPU]
- Device order: CUDA → MPS → CPU, overridable with --device.
- Windows / Linux: the venv scripts install the CUDA 13.0 (cu130) build directly. It needs a Turing-or-newer NVIDIA GPU and a driver supporting CUDA 13.0+. Pascal/Volta GPUs (GTX 10xx, V100) are not supported by cu130; on those, reinstall torch from the cu126 index inside the venv: pip install torch==2.13.0 --index-url https://download.pytorch.org/whl/cu126 --force-reinstall
- macOS (Apple Silicon): the model runs on the Apple GPU through MPS; ops MPS lacks fall back to the CPU (PYTORCH_ENABLE_MPS_FALLBACK=1 is set by the entry scripts).
- Without a usable GPU everything runs on the CPU (fine for inference and short training runs). Checkpoints load on any device.
[Notes]
- Crop file names are the ground-truth plate strings; the bundled Noto Sans CJK font renders the Chinese characters on any machine.
- Verified with the shipped model: 9/10 accuracy on the test crops (same result on CUDA and on the CPU).
This SDK is built in AppForAI - AI Dev Tools.