Tensorflow implementation of character detection CTPN

Tensorflow implementation of character detection CTPN

Reference: https://github.com/Li-Ming-Fan/OCR-DETECTION-CTPN

Training steps

Follow the steps below to train the CTPN model:

1. python data_base_normalize.py# Normalize the pre-trained background image

2. python data_generator.py 0# Generate verification data

3. python data_generator.py 1# Generate training data

4. python script_detect.py# for training and verification

If the size is not 800x600, the pre-normalized image will be scaled first, and then an 800x600 rectangle will be cropped from the rescaled image. The 800x600 images will be stored in the newly created directory ./images_base.

Pass 2 and 3, will generate verification data and training data. These will be stored in the newly created directories ./data_valid and ./data_train, respectively.

At 4 o'clock, the model will be trained and validated. The verification results will be stored in ./data_valid/results. The ckpt file will be stored in the newly created directory ./model_detect

Predict a single picture

Change the python script_detect.py part:

# -*- coding: utf-8 -*-
"""
@author: limingfan

"""

import model_detect_meta as meta
import model_detect_data as model_data

from model_detect_wrap import ModelDetect


import os
#
os.environ['CUDA_VISIBLE_DEVICES'] = '0' #使用 GPU 0
#os.environ['CUDA_VISIBLE_DEVICES'] = '0,1' # 使用 GPU 0,1
#


#
model = ModelDetect()
#

#
# predict
model.prepare_for_prediction()

img_file="./my_test/korean1.jpg"
print(img_file)
#
conn_bbox, text_bbox, conf_bbox = model.predict(img_file, out_dir='./my_output')
#
'''
list_images_valid = model_data.get_files_with_ext(meta.dir_images_valid, 'png')
for img_file in list_images_valid:
    #
    # img_file = './data_test/images/bkgd_1_0_generated_0.png'
    #
    print(img_file)
    #
    conn_bbox, text_bbox, conf_bbox = model.predict(img_file, out_dir = './results_prediction')
    #

'''

Detection effect picture

The computer has only trained more than 4000 times, and the effect has not yet reached the best. You can train tens of thousands of times, and the effect will be much better.
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/mao_hui_fei/article/details/114461624