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.570 100,000 5,000
CRNN_Tiny CONV+GRU (1, 32, 160) 0.1 1.7 98.306 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.147 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.546 269,621 149,002
LPRNet CONV (3, 24, 94) 0.3 1.9 60.105 269,621 149,002
LPRNetPlus+STNet CONV (3, 24, 94) 0.5 2.5 72.130 269,621 149,002
LPRNet+STNet CONV (3, 24, 94) 0.3 2.2 72.261 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.512 141,982 93.787 5,006
CRNN_Tiny 75.729 141,982 92.829 5,006
LPRNetPlus 62.184 141,982 89.373 5,006
LPRNet 59.597 141,982 89.153 5,006
LPRNetPlus+STNet 72.125 141,982 90.611 5,006
LPRNet+STNet 71.291 141,982 89.832 5,006

Table of Contents

News🚀🚀🚀

Version Release Date Major Updates
v1.3.0 2024/09/21 Add STNet module to LPRNet/LPRNetPlus and update the training/evaluation/prediction results on the CCPD dataset.
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 has currently achieved digital recognition and license plate recognition. Meanwhile, LPRNet(+STNet) is a pure convolutional architecture for license plate recognition network. I believe that the implementation of these algorithms can help with the deployment of license plate recognition algorithms, such as on edge devices.

Relevant papers include:

  1. Towards End-to-End License Plate Detection and Recognition: A Large Dataset and Baseline
  2. An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition
  3. Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurrent Neural Networks
  4. LPRNet: License Plate Recognition via Deep Neural Networks

Relevant blogs (Chinese):

  1. Towards End-to-End License Plate Detection and Recognition: A Large Dataset and Baseline
  2. An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition
  3. LPRNet: License Plate Recognition via Deep Neural Networks

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-emnist.pth ../datasets/emnist/ --not-tiny
args: Namespace(not_tiny=True, pretrained='crnn-emnist.pth', use_lstm=False, val_root='../datasets/emnist/')
Loading CRNN pretrained: crnn-emnist.pth
crnn-emnist summary: 29 layers, 7924363 parameters, 7924363 gradients, 2.2 GFLOPs
Batch:49999 ACC:100.000: 100%|████████████████████████████████████████████████████████| 50000/50000 [03:47<00:00, 219.75it/s]
ACC:98.570
# Plate
$ CUDA_VISIBLE_DEVICES=0 python3 eval_plate.py crnn-plate.pth ../datasets/chinese_license_plate/recog/ --not-tiny
args: Namespace(add_stnet=False, not_tiny=True, only_ccpd2019=False, only_ccpd2020=False, only_others=False, pretrained='crnn-plate.pth', use_lprnet=False, use_lstm=False, use_origin_block=False, val_root='../datasets/chinese_license_plate/recog/')
Loading CRNN pretrained: crnn-plate.pth
crnn-plate summary: 29 layers, 15083854 parameters, 15083854 gradients, 4.0 GFLOPs
Load test data: 149002
Batch:4656 ACC:100.000: 100%|████████████████████████████████████████████████████████████| 4657/4657 [00:52<00:00, 89.13it/s]
ACC:82.147

Predict

$ CUDA_VISIBLE_DEVICES=0 python predict_emnist.py crnn-emnist.pth ../datasets/emnist/ ./runs/predict/emnist/ --not-tiny
args: Namespace(not_tiny=True, pretrained='crnn-emnist.pth', save_dir='./runs/predict/emnist/', use_lstm=False, val_root='../datasets/emnist/')
Loading CRNN pretrained: crnn-emnist.pth
crnn-emnist summary: 29 layers, 7924363 parameters, 7924363 gradients, 2.2 GFLOPs
Label: [0 4 2 4 7] Pred: [0 4 2 4 7]
Label: [2 0 6 5 4] Pred: [2 0 6 5 4]
Label: [7 3 9 9 5] Pred: [7 3 9 9 5]
Label: [9 6 6 0 9] Pred: [9 6 6 0 9]
Label: [2 3 0 7 6] Pred: [2 3 0 7 6]
Label: [6 5 9 5 2] Pred: [6 5 9 5 2]

$ CUDA_VISIBLE_DEVICES=0 python predict_plate.py crnn-plate.pth ./assets/plate/宁A87J92_0.jpg runs/predict/plate/ --not-tiny
args: Namespace(add_stnet=False, image_path='./assets/plate/宁A87J92_0.jpg', not_tiny=True, pretrained='crnn-plate.pth', save_dir='runs/predict/plate/', use_lprnet=False, use_lstm=False, use_origin_block=False)
Loading CRNN pretrained: crnn-plate.pth
crnn-plate summary: 29 layers, 15083854 parameters, 15083854 gradients, 4.0 GFLOPs
Pred: 宁A·87J92 - Predict time: 5.4 ms
Save to runs/predict/plate/plate_宁A87J92_0.jpg
$ CUDA_VISIBLE_DEVICES=0 python predict_plate.py crnn-plate.pth ./assets/plate/川A3X7J1_0.jpg runs/predict/plate/ --not-tiny
args: Namespace(add_stnet=False, image_path='./assets/plate/川A3X7J1_0.jpg', not_tiny=True, pretrained='crnn-plate.pth', save_dir='runs/predict/plate/', use_lprnet=False, use_lstm=False, use_origin_block=False)
Loading CRNN pretrained: crnn-plate.pth
crnn-plate summary: 29 layers, 15083854 parameters, 15083854 gradients, 4.0 GFLOPs
Pred: 川A·3X7J1 - Predict time: 4.7 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