The software has only been tested on Ubuntu 14.04 (x64). CUDA-enabled GPUs are required. To build the project, first install the latest versions of Torch7, fblualib and LMDB. Please follow their installation instructions respectively. On Ubuntu, lmdb can be installed by apt-get install liblmdb-dev.
To build the project, go to src/ and execute sh build_cpp.sh to build the C++ code. If successful, a file named libcrnn.so should be produced in the src/ directory.
Run demo
A demo program can be found in src/demo.lua. Before running the demo, download a pretrained model from here. Put the downloaded model file crnn_demo_model.t7 into directory model/crnn_demo/. Then launch the demo by:
th demo.lua
The demo reads an example image and recognizes its text content.
Example image:
Expected output:
Loading model...
Model loaded from ../model/crnn_demo/model.t7
Recognized text: available (raw: a-----v--a-i-l-a-bb-l-e---)
The pretrained model can be used for lexicon-free and lexicon-based recognition tasks. Refer to the functions recognizeImageLexiconFree and recognizeImageWithLexicion in file utilities.lua for details.
Train a new model
Follow the following steps to train a new model on your own dataset.
Create a new LMDB dataset. A python program is provided in tool/create_dataset.py. Refer to the function createDataset for details (need to pip install lmdb first).
Create model directory under model/. For example, model/foo_model. Then create configuraton file config.lua under the model directory. You can copy model/crnn_demo/config.lua and do modifications.
Go to src/ and execute th main_train.lua ../models/foo_model/. Model snapshots and logging file will be saved into the model directory.
Install nvidia-docker - Follow the instructions here
Clone this repo, from this directory run docker build -t crnn_docker .
Once the image is built, the docker can be run using nvidia-docker run -it crnn_docker.
Citation
Please cite the following paper if you are using the code/model in your research paper.
@article{ShiBY17,
author = {Baoguang Shi and
Xiang Bai and
Cong Yao},
title = {An End-to-End Trainable Neural Network for Image-Based Sequence Recognition
and Its Application to Scene Text Recognition},
journal = {{IEEE} Trans. Pattern Anal. Mach. Intell.},
volume = {39},
number = {11},
pages = {2298--2304},
year = {2017}
}
Acknowledgements
The authors would like to thank the developers of Torch7, TH++, lmdb-lua-ffi and char-rnn.