GRU(Gated Recurrent Unit)是LSTM的一个变体,也能克服RNN无法很好处理远距离依赖的问题。

GRU的结构跟LSTM类似,不过增加了让三个门层也接收细胞状态的输入,是常用的LSTM变体之一。

LSTM核心模块:

这一核心模块在GRU中变为:

CTC网络结构定义:

def get_model(height,nclass):

    input = Input(shape=(height,None,1),name='the_input')
m = Conv2D(64,kernel_size=(3,3),activation='relu',padding='same',name='conv1')(input)
m = MaxPooling2D(pool_size=(2,2),strides=(2,2),name='pool1')(m)
m = Conv2D(128,kernel_size=(3,3),activation='relu',padding='same',name='conv2')(m)
m = MaxPooling2D(pool_size=(2,2),strides=(2,2),name='pool2')(m)
m = Conv2D(256,kernel_size=(3,3),activation='relu',padding='same',name='conv3')(m)
m = Conv2D(256,kernel_size=(3,3),activation='relu',padding='same',name='conv4')(m) m = ZeroPadding2D(padding=(0,1))(m)
m = MaxPooling2D(pool_size=(2,2),strides=(2,1),padding='valid',name='pool3')(m) m = Conv2D(512,kernel_size=(3,3),activation='relu',padding='same',name='conv5')(m)
m = BatchNormalization(axis=1)(m)
m = Conv2D(512,kernel_size=(3,3),activation='relu',padding='same',name='conv6')(m)
m = BatchNormalization(axis=1)(m)
m = ZeroPadding2D(padding=(0,1))(m)
m = MaxPooling2D(pool_size=(2,2),strides=(2,1),padding='valid',name='pool4')(m)
m = Conv2D(512,kernel_size=(2,2),activation='relu',padding='valid',name='conv7')(m) m = Permute((2,1,3),name='permute')(m)
m = TimeDistributed(Flatten(),name='timedistrib')(m) m = Bidirectional(GRU(rnnunit,return_sequences=True),name='blstm1')(m)
m = Dense(rnnunit,name='blstm1_out',activation='linear')(m)
m = Bidirectional(GRU(rnnunit,return_sequences=True),name='blstm2')(m)
y_pred = Dense(nclass,name='blstm2_out',activation='softmax')(m) basemodel = Model(inputs=input,outputs=y_pred) labels = Input(name='the_labels', shape=[None,], dtype='float32')
input_length = Input(name='input_length', shape=[1], dtype='int64')
label_length = Input(name='label_length', shape=[1], dtype='int64')
loss_out = Lambda(ctc_lambda_func, output_shape=(1,), name='ctc')([y_pred, labels, input_length, label_length])
model = Model(inputs=[input, labels, input_length, label_length], outputs=[loss_out])
sgd = SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True, clipnorm=5)
#model.compile(loss={'ctc': lambda y_true, y_pred: y_pred}, optimizer='adadelta')
model.compile(loss={'ctc': lambda y_true, y_pred: y_pred}, optimizer=sgd)
model.summary()
return model,basemodel

____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
the_input (InputLayer)           (None, 32, None, 1)   0                                            
____________________________________________________________________________________________________
conv1 (Conv2D)                   (None, 32, None, 64)  640         the_input[0][0]                  
____________________________________________________________________________________________________
pool1 (MaxPooling2D)             (None, 16, None, 64)  0           conv1[0][0]                      
____________________________________________________________________________________________________
conv2 (Conv2D)                   (None, 16, None, 128) 73856       pool1[0][0]                      
____________________________________________________________________________________________________
pool2 (MaxPooling2D)             (None, 8, None, 128)  0           conv2[0][0]                      
____________________________________________________________________________________________________
conv3 (Conv2D)                   (None, 8, None, 256)  295168      pool2[0][0]                      
____________________________________________________________________________________________________
conv4 (Conv2D)                   (None, 8, None, 256)  590080      conv3[0][0]                      
____________________________________________________________________________________________________
zero_padding2d_1 (ZeroPadding2D) (None, 8, None, 256)  0           conv4[0][0]                      
____________________________________________________________________________________________________
pool3 (MaxPooling2D)             (None, 4, None, 256)  0           zero_padding2d_1[0][0]           
____________________________________________________________________________________________________
conv5 (Conv2D)                   (None, 4, None, 512)  1180160     pool3[0][0]                      
____________________________________________________________________________________________________
batch_normalization_1 (BatchNorm (None, 4, None, 512)  16          conv5[0][0]                      
____________________________________________________________________________________________________
conv6 (Conv2D)                   (None, 4, None, 512)  2359808     batch_normalization_1[0][0]      
____________________________________________________________________________________________________
batch_normalization_2 (BatchNorm (None, 4, None, 512)  16          conv6[0][0]                      
____________________________________________________________________________________________________
zero_padding2d_2 (ZeroPadding2D) (None, 4, None, 512)  0           batch_normalization_2[0][0]      
____________________________________________________________________________________________________
pool4 (MaxPooling2D)             (None, 2, None, 512)  0           zero_padding2d_2[0][0]           
____________________________________________________________________________________________________
conv7 (Conv2D)                   (None, 1, None, 512)  1049088     pool4[0][0]                      
____________________________________________________________________________________________________
permute (Permute)                (None, None, 1, 512)  0           conv7[0][0]                      
____________________________________________________________________________________________________
timedistrib (TimeDistributed)    (None, None, 512)     0           permute[0][0]                    
____________________________________________________________________________________________________
blstm1 (Bidirectional)           (None, None, 512)     1181184     timedistrib[0][0]                
____________________________________________________________________________________________________
blstm1_out (Dense)               (None, None, 256)     131328      blstm1[0][0]                     
____________________________________________________________________________________________________
blstm2 (Bidirectional)           (None, None, 512)     787968      blstm1_out[0][0]                 
____________________________________________________________________________________________________
blstm2_out (Dense)               (None, None, 5531)    2837403     blstm2[0][0]                     
____________________________________________________________________________________________________
the_labels (InputLayer)          (None, None)          0                                            
____________________________________________________________________________________________________
input_length (InputLayer)        (None, 1)             0                                            
____________________________________________________________________________________________________
label_length (InputLayer)        (None, 1)             0                                            
____________________________________________________________________________________________________
ctc (Lambda)                     (None, 1)             0           blstm2_out[0][0]                 
                                                                   the_labels[0][0]                 
                                                                   input_length[0][0]               
                                                                   label_length[0][0]               
====================================================================================================
Total params: 10,486,715
Trainable params: 10,486,699

模型: 模型包含5500个中文字符,包括常用汉字、大小写英文字符、标点符号、特殊符号(@、¥、&)等,可以在现有模型基础上继续训练。

训练: 样本保存在data文件夹下,使用LMDB格式; train.py是训练文件,可以选择保存模型权重或模型结构+模型权重,训练结果保存在models文件夹下。

测试: test.py是中文OCR测试文件

识别效果:

济南华富锻造有限公司

夺得铜牌后,福民爱流下了激动的泪水。“石川

Itturnedoutthat328girswerenamedAbcdeintheUnitedstates

工程(含训练模型)地址:  http://download.csdn.net/download/dcrmg/10248818

Keras GRU 文字识别的更多相关文章

  1. 图像文字识别(OCR)用什么算法小结

    说明:主要考虑深度学习的方法,传统的方法不在考虑范围之内. 1.文字识别步骤 1.1detection:找到有文字的区域(proposal). 1.2classification:识别区域中的文字. ...

  2. emgucv文字识别

    今天讲如何通过emgucv中的函数来实现文字识别.总体的过程可以分为以下几步: 1.读取要识别的图片 2.对图片进行灰度变换 3.调用emgu.cv.ocr的类tessract中的recognize方 ...

  3. tesseract ocr文字识别Android实例程序和训练工具全部源代码

    tesseract ocr是一个开源的文字识别引擎,Android系统中也可以使用.可以识别50多种语言,通过自己训练识别库的方式,可以大大提高识别的准确率. 为了节省大家的学习时间,现将自己近期的学 ...

  4. 斯坦福第十八课:应用实例:图片文字识别(Application Example: Photo OCR)

    18.1  问题描述和流程图 18.2  滑动窗口 18.3  获取大量数据和人工数据 18.4  上限分析:哪部分管道的接下去做 18.1  问题描述和流程图

  5. 怎么给OCR文字识别软件重编文档页面号码

    ABBYY FineReader Pro for Mac OCR文字识别软件处理文档时,在FineReader文档中,页面的加载顺序即是页面的导入顺序,完成导入之后,文档的所有页面均会被编号,各编号会 ...

  6. 对OCR文字识别软件的扫描选项怎么设置

    说到OCR文字识别软件,越来越多的人选择使用ABBYY FineReader识别和转换文档,然而并不是每个人都知道转换质量取决于源图像的质量和所选的扫描选项,今天就给大家普及一下这方面的知识. ABB ...

  7. 给OCR文字识别软件添加图像的方法

    ABBYY FineReader 12是一款OCR图片文字识别软件,而且强大的它现在还可使用快速扫描窗口中的快速打开.扫描并保存为图像或任务自动化任务,在没有进行预处理和OCR的ABBYY FineR ...

  8. 怎么提高OCR文字识别软件的识别正确率

    在OCR文字识别软件当中,ABBYY FineReader是比较好用的程序之一,但再好的识别软件也不能保证100%的识别正确率,用户都喜欢软件的正确率高一些,以减轻识别后修正的负担,很多用户也都提过这 ...

  9. OCR文字识别软件许可文件被误删了怎么办

    使用任何一款软件,都会有误操作的情况发生,比如清理文件时一不小心删除了许可文件,对于ABBYY FineReader 12这样一款OCR文字识别软件,因失误错误删除了许可文件该怎么办呢?今天就来给大家 ...

随机推荐

  1. CNN学习笔记:卷积运算

    CNN学习笔记:卷积运算 边缘检测 卷积 卷积是一种有效提取图片特征的方法.一般用一个正方形卷积核,遍历图片上的每一个像素点.图片与卷积核重合区域内相对应的每一个像素值乘卷积核 .内相对应点的权重,然 ...

  2. $微信小程序开发实践点滴——Bmob基本REST API的python封装

    Refer:Bmob后端云REST API接口文档:http://docs.bmob.cn/data/Restful/a_faststart/doc/index.html 本文使用python对Bmo ...

  3. 使用阿里的maven库

    快使用阿里云的maven仓库 自从开源中国的maven仓库挂了之后就一直在用国外的仓库,慢得想要砸电脑的心都有了.如果你和我一样受够了国外maven仓库的龟速下载?快试试阿里云提供的maven仓库,从 ...

  4. MySQL-5.7 高阶语法及流程控制

    1.标签语句 [begin_label:] BEGIN [statement_list] END [end_label] [begin_label:] LOOP statement_list END ...

  5. vue.js 调用iOS原生方法,JavaScriptCore

    1. 2. 3. 4.vue.js调用

  6. hdu 2126 Buy the souvenirs 二维01背包方案总数

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. LeftoverDataException,依赖包,apache license 2.0

    1. poi3.9 LeftoverDataException org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: ...

  8. python 之Tornado

    一.Tomado Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webap ...

  9. angular ng-repeat 如何实现嵌套

    slides是一个二维数组 <div ng-repeat="links in slides"> <div ng-repeat="link in link ...

  10. 项目中如何使用EF

    本文将在技术层面挑战园子里的权威大牛们,言语不敬之处敬请包涵.本文旨为技术交流,欢迎拍砖. 园子里面分享和推荐Entity Framework(以下简称EF)的Repository(仓储)设计模式的文 ...