Skip to content

Latest commit

 

History

History
 
 

text_recognition

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Text Recognition in TensorFlow*

This repository contains inference and training code for LSTM-based text recognition networks. Models code is designed to enable export to frozen graph and inference on CPU via OpenVINO™.

Setup

Prerequisites

  • Ubuntu* 16.04-20.04
  • Python* 3.5-3.7 (Python >=3.8 is not supported by TensorFlow 1.x)
  • TensorFlow* 1.13-1.15
  • CUDA* 10.0
  • cuDNN* 7.6.5

Installation

  1. Create virtual environment:

    virtualenv venv -p python3 --prompt="(tr)"
  2. Activate virtual environment and setup OpenVINO™ variables:

    . venv/bin/activate
    . /opt/intel/openvino/bin/setupvars.sh

    TIP: Good practice is adding . /opt/intel/openvino/bin/setupvars.sh to the end of the venv/bin/activate.

    echo ". /opt/intel/openvino/bin/setupvars.sh" >> venv/bin/activate
    
  3. Install the module:

    pip3 install -e .
    pip3 install -e ../utils
  4. Add path to CUDA libraries to LD_LIBRARY_PATH

    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda-10.0/lib64

Sources

A toy dataset located in ../../data/text_recognition/annotation.txt. You can use it to do all steps including:

  • model training
  • model evaluation

NOTE: This dataset is considerably small. It is highly recommended to use at least several thousand images datasets like MJSynth and SynthText in the Wild Dataset.

Format

Store your dataset in the format of a simple text file where each line has the following format: <relative_path_to_image> <text>

Example:

./images/intel_1.jpg intel

See ./data for more details.

Training

python tools/train.py \
    --annotation_path ../../data/text_recognition/annotation.txt \
    --learning_rate 0.1

Optional parameter:

python tools/train.py \
    --annotation_path ../../data/text_recognition/annotation.txt \
    --learning_rate 0.1 \
    --weights_path some_pre_trained_weights

Export to OpenVINO™ Intermediate Representation (IR)

To run the model via OpenVINO™, freeze TensorFlow graph and then convert it to OpenVINO™ Intermediate Representation (IR) using Model Optimizer:

python tools/export.py --checkpoint checkpoint_path \
    --data_type FP32 \
    --output_dir export

Evaluation

python tools/test.py \
    --annotation_path ../../data/text_recognition/annotation.txt \
    --weights_path some_pre_trained_weights

Demo in OpenVINO™

See https://github.com/opencv/open_model_zoo/tree/master/demos/text_detection_demo.