An implementation of CRNN algorithm using Pytorch framework
The most typical CTC algorithm is CRNN (Convolutional Recurrent Neural Network), which introduces the bidirectional LSTM (Long Short-Term Memory) to enhance the context modeling. Experiments have proved that the bidirectional LSTM module can effectively extract the contextual information of the picture, finally enter the output feature sequence into the CTC module, and decode the sequence result.
Environment The dependencies are listed in `requirements.txt`. Please install and follow the command below:pip install -r requirements.txt
You can download and use ICDAR2015 or MJSynth dataset for the training model.
After that,
- Put the data folder under the
datasets
directory - Setup config file for each dataset in
src/__init__.py
: replaceCFG_PATH
augment bysrc/config/rec_lmdb.yml
orsrc/config/rec_icdar15.yml
Before training, please modify configurations in src/config/rec_lmdb.yml
or src/config/rec_icdar15.yml
python -m src.train
To train the model with PyTorch lightning
python -m src.pl_modules.pl_train
python -m src.eval
python -m src.exports.exporter --export_format <torchscript/onnx/paddle/tensorrt> --device cuda
python -m src.predict --img_path <path_to_image_file> --export_format <torchscript/onnx/paddle/tensorrt> --device cuda
Example:
python -m src.predict --image_path images/tuongan.png --export_format pt --device cuda
>> tuongan
tensorboard --logdir debugs/tensorboard
Train Loss | Valid Loss | Valid Acc |
---|---|---|
Export format | Inference time | ACC with CTCLoss | ACC with Focal CTCLoss |
---|---|---|---|
Pytorch | 0.0008s | 95.47 | 96 |
TorchScript | 0.0007s | - | - |
ONNX | 0.001s | - | - |
TensorRT | 0.0001s | - | - |
Paddle | 0.01s | - | - |