Skip to content

zjykzj/crnn-ctc

Repository files navigation

«crnn-ctc» implemented CRNN+CTC

ONLINE DEMO:LICENSE PLATE RECOGNITION

Model ARCH Input Shape GFLOPs Model Size (MB) EMNIST Accuracy (%) Training Data Testing Data
CRNN CONV+GRU (1, 32, 160) 2.2 31 98.640 100,000 5,000
CRNN_Tiny CONV+GRU (1, 32, 160) 0.1 1.7 98.482 100,000 5,000
Model ARCH Input Shape GFLOPs Model Size (MB) ChineseLicensePlate Accuracy (%) Training Data Testing Data
CRNN CONV+GRU (3, 48, 168) 4.0 58 82.311 269,621 149,002
CRNN_Tiny CONV+GRU (3, 48, 168) 0.3 4.0 76.590 269,621 149,002
LPRNetPlus CONV (3, 24, 94) 0.5 2.3 63.449 269,621 149,002
LPRNet CONV (3, 24, 94) 0.3 1.9 61.096 269,621 149,002

For each sub-dataset, the model performance as follows:

Model CCPD2019-Test Accuracy (%) Testing Data CCPD2020-Test Accuracy (%) Testing Data
CRNN 81.698 141,982 93.548 5,006
CRNN_Tiny 75.729 141,982 92.829 5,006
LPRNetPlus 62.080 141,982 89.213 5,006
LPRNet 59.686 141,982 87.335 5,006

Table of Contents

News🚀🚀🚀

Version Release Date Major Updates
v1.2.0 2024/09/17 Create a new LPRNet/LPRNetPlus model and update the training/evaluation/prediction results on the CCPD dataset.
v1.1.0 2024/08/17 Update EVAL/PREDICT implementation, support Pytorch format model conversion to ONNX, and finally provide online demo based on Gradio.
v1.0.0 2024/08/04 Optimize the CRNN architecture while achieving super lightweight CRNN_Tiny.
In addition, all training scripts support mixed precision training.
v0.3.0 2024/08/03 Implement models CRNN_LSTM and CRNN_GRU on datasets EMNIST and ChineseLicensePlate.
v0.2.0 2023/10/11 Support training/evaluation/prediction of CRNN+CTC based on license plate.
v0.1.0 2023/10/10 Support training/evaluation/prediction of CRNN+CTC based on EMNIST digital characters.

Background

This warehouse aims to better understand and apply CRNN+CTC, and currently achieves digital recognition and license plate recognition

Installation

$ pip install -r requirements.txt

Or use docker container

$ docker run -it --runtime nvidia --gpus=all --shm-size=16g -v /etc/localtime:/etc/localtime -v $(pwd):/workdir --workdir=/workdir --name crnn-ctc ultralytics/yolov5:latest

Usage

Train

# EMNIST
$ python3 train_emnist.py ../datasets/emnist/ ./runs/crnn-emnist-b512/ --batch-size 512 --device 0 --not-tiny
# Plate
$ python3 train_plate.py ../datasets/chinese_license_plate/recog/ ./runs/crnn-plate-b512/ --batch-size 512 --device 0 --not-tiny

Eval

# EMNIST
$ CUDA_VISIBLE_DEVICES=0 python eval_emnist.py crnn_tiny-emnist.pth ../datasets/emnist/
args: Namespace(not_tiny=False, pretrained='crnn_tiny-emnist.pth', use_lstm=False, val_root='../datasets/emnist/')
Loading CRNN pretrained: crnn_tiny-emnist.pth
crnn_tiny-emnist summary: 22 layers, 427467 parameters, 427467 gradients, 0.1 GFLOPs
Batch:1562 ACC:100.000: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1563/1563 [00:19<00:00, 80.29it/s]
ACC:98.278
# Plate
$ CUDA_VISIBLE_DEVICES=0 python3 eval_plate.py crnn_tiny-plate.pth ../datasets/chinese_license_plate/recog/
args: Namespace(not_tiny=False, only_ccpd2019=False, only_ccpd2020=False, only_others=False, pretrained='crnn_tiny-plate.pth', use_lprnet=False, use_lstm=False, use_origin_block=False, val_root='../datasets/chinese_license_plate/recog/')
Loading CRNN pretrained: crnn_tiny-plate.pth
crnn_tiny-plate summary: 22 layers, 1042318 parameters, 1042318 gradients, 0.3 GFLOPs
Load test data: 149002
Batch:4656 ACC:100.000: 100%|███████████████████████████████████████████████████████████| 4657/4657 [00:36<00:00, 125.99it/s]
ACC:76.590

Predict

$ CUDA_VISIBLE_DEVICES=0 python predict_emnist.py crnn_tiny-emnist.pth ../datasets/emnist/ ./runs/predict/emnist/
args: Namespace(not_tiny=False, pretrained='crnn_tiny-emnist.pth', save_dir='./runs/predict/emnist/', use_lstm=False, val_root='../datasets/emnist/')
Loading CRNN pretrained: crnn_tiny-emnist.pth
crnn_tiny-emnist summary: 22 layers, 427467 parameters, 427467 gradients, 0.1 GFLOPs
Label: [3 8 5 8 5] Pred: [3 8 5 8 5]
Label: [4 8 6 8 0] Pred: [4 8 6 8 0]
Label: [4 6 4 7 0] Pred: [4 6 4 7 0]
Label: [2 3 5 0 7] Pred: [2 3 5 0 7]
Label: [4 7 8 4 6] Pred: [4 7 8 4 6]
Label: [0 1 4 3 6] Pred: [0 1 4 3 6]

$ CUDA_VISIBLE_DEVICES=0 python predict_plate.py crnn_tiny-plate.pth ./assets/plate/宁A87J92_0.jpg runs/predict/plate/
args: Namespace(image_path='./assets/plate/宁A87J92_0.jpg', not_tiny=False, pretrained='crnn_tiny-plate.pth', save_dir='runs/predict/plate/', use_lprnet=False, use_lstm=False, use_origin_block=False)
Loading CRNN pretrained: crnn_tiny-plate.pth
crnn_tiny-plate summary: 22 layers, 1042318 parameters, 1042318 gradients, 0.3 GFLOPs
Pred: 宁A·87J92 - Predict time: 3.7 ms
Save to runs/predict/plate/plate_宁A87J92_0.jpg
$ CUDA_VISIBLE_DEVICES=0 python predict_plate.py crnn_tiny-plate.pth ./assets/plate/川A3X7J1_0.jpg runs/predict/plate/
args: Namespace(image_path='./assets/plate/川A3X7J1_0.jpg', not_tiny=False, pretrained='crnn_tiny-plate.pth', save_dir='runs/predict/plate/', use_lprnet=False, use_lstm=False, use_origin_block=False)
Loading CRNN pretrained: crnn_tiny-plate.pth
crnn_tiny-plate summary: 22 layers, 1042318 parameters, 1042318 gradients, 0.3 GFLOPs
Pred: 川A·3X7J1 - Predict time: 3.5 ms
Save to runs/predict/plate/plate_川A3X7J1_0.jpg

Maintainers

  • zhujian - Initial work - zjykzj

Thanks

Contributing

Anyone's participation is welcome! Open an issue or submit PRs.

Small note:

License

Apache License 2.0 © 2023 zjykzj