Holmeyoung / crnn-pytorch

Pytorch implementation of CRNN (CNN + RNN + CTCLoss) for all language OCR.
MIT License
378 stars 105 forks source link
cnn ctc-loss ocr rnn

Convolutional Recurrent Neural Network + CTCLoss

I think i have fixed the ctcloss nan problem!

Now!

Please pull the latest code from master.

Please update the pytorch to >= v1.2.0

Enjoy it!

PS: Once there is ctclossnan, please

  1. Change the batchSize to smaller (eg: 8, 16, 32)
  2. Change the lr to smaller (eg: 0.00001, 0.0001)
  3. Contact me by emailing to holmeyoung@gmail.com

Dependence

Run demo

Feature

Train your data

Prepare data

Folder mode

  1. Put your images in a folder and organize your images in the following format:

    label_number.jpg

    For example

    • English
    hi_0.jpg hello_1.jpg English_2.jpg English_3.jpg E n g l i s h_4.jpg...
    • Chinese
    一身转战_0.jpg 三千里_1.jpg 一剑曾当百万师_2.jpg 一剑曾当百万师_3.jpg 一 剑 曾 当 百 万 师_3.jpg ...

    So you can see, the number is used to distinguish the same label.

  2. Run the create_dataset.py in tool folder by

    python tool/create_dataset.py --out lmdb/data/output/path --folder path/to/folder
  3. Use the same step to create train and val data.

  4. The advantage of the folder mode is that it's convenient! But due to some illegal character can't be in the path

    Illegal character

    So the disadvantage of the folder mode is that it's labels are limited.

File mode

  1. Your data file should like

    absolute/path/to/image/一身转战_0.jpg
    一身转战
    absolute/path/to/image/三千里_1.jpg
    三千里
    absolute/path/to/image/一剑曾当百万师_2.jpg
    一剑曾当百万师
    absolute/path/to/image/3.jpg
    一剑曾当百万师
    absolute/path/to/image/一 剑 曾 当 百 万 师_4.jpg
    一 剑 曾 当 百 万 师
    absolute/path/to/image/xxx.jpg
    label of xxx.jpg
    .
    .
    .

    DO REMEMBER:

    1. It must be the absolute path to image.
    2. The first line can't be empty.
    3. There are no blank line between two data.
  2. Run the create_dataset.py in tool folder by

    python tool/create_dataset.py --out lmdb/data/output/path --file path/to/file
  3. Use the same step to create train and val data.

Change parameters and alphabets

Parameters and alphabets can't always be the same in different situation.

Train

Run train.py by

python train.py --trainroot path/to/train/dataset --valroot path/to/val/dataset

Reference

meijieru/crnn.pytorch

Sierkinhane/crnn_chinese_characters_rec