百度SRN的网络结构

论文

《Towards Accurate Scene Text Recognition with Semantic Reasoning Networks》
paddlepaddle ocr

整体网络流程

resnet50+fpn
2_stack_transformers
fc&expand_dim1
add_gsrm_pos_embedding+tanh
fc+softmax
dotproduct
dotproduct
reshape+fc+softmax+argmax+reshape
pad+dim_1_cut
4_stack_transformers_forward_mask
4_stack_transformers_backward_mask
add
add
concat
concat
fc+sigmoid
*img_combine_features_map
*1-img_combine_features_map
coefficient
reshape+fc+softmax
image
conv_features
word_features
word_features
temp
attention
pvam_features
pvam_fetures
word_ids
word1
word2
gsrm_feature_1
gsrm_feature_2
gsrm_feature
img_combine_features
img_combine_features_map
combine_features
vsfd_out

pvam

  特征提取部分:resnet50+fpn
  这时候输出的特征是[b,t,c](t = imgH/8 * imgW/8)
  这时候,每个特征值乘以 根号下512 ,并加上位置信息的特征。
  encoder_word_pos [[[0],[1],[2],…[t-1]]]经过一个embedding层转换为位置信息特征。
  输入两层的transformer堆叠,8头注意力,d_key = 512/8, 最后输出仍旧是512。
  这时候得到的是word_features为[b,t,c]
  dim2维度上全连接,c到c,然后expand维度1到max_length,得到[b,max_length,t,c](相当于复制max_length份)
  gsrm_word_pos[[[0],[1], …, [max_length-1]]]通过embedding层获得gsrm_pos_embedding,此时的gsrm_pos_embedding是[b,max_length,c],expand dim_2到t,得到[b,max_length,t,c]。
  gsrm_pos_embedding加上word_features之后经过tanh计划函数得到temp,temp通过全连接将将dim_3从c降到1,之后取出dim_3后做softmax获得attention值。
  attention[b,max_lenght,t] dot product wordfeatures[b,t,c]之后得到pvam_features [b,max_length,c],这对这个特征,左慈全连接到字符个数,之后做softmax,argmax就可以进行字符的判断。

gsrm

  word_ids [b,max_length,1] ,在dim1的维度上pad 一个 idx(这个idx相当于是一个起始符),这时候word_ids是[b,max_length+1,1]。
  这里假设word_ids 是 [[[s], [1], [2], …,[n-1],[n]]], 那么word_1就是 [[[s], [1], [2], …,[n-1]]],word_2是[[[1], [2], …,[n-1],[n]]]。
  之后二者分别过embedding层之后输入四层的transformer中,注意这里分别有两个mask。word 1 的mask 保证字符从先往后计算self attention的时候,attention的权重只有自己和自己之前的。就是说保证字符只能看到自己和自己之前的。word_2的mask就相当于是反向的,第一个字符就能看到所有的字符。
  word_1 的 mask为[[0,-10^9, -10^9, -10^9], [0,0,-10^9, -10^9], [0,0,0,-10^9], [0,0,0,0]],word_2的mask就是为[[0,0,0,0],[0,0,0,-10^9], [0,0, -10^9, -10^9], [0,-10^9, -10^9, -10^9]], qk计算权值之后,mask掉的部分就加上-10^9,这样后面计算softmax 的时候,就相当于不计算mask掉的部分。
  二者通过四层transformer之后,gsrm_feature_2会在最后的位置补零,选择[1:],获得的特征就是字符2 到最后一个字符加上一个结尾符。

+
predict
+
predict
+
predict
+
predict
<SOS>_embedding
char_2_embedding
char_1
char_1_embedding
char_3_embedding
char_2
.................
..................
....................
char_n-1_embedding
<EOS>_embedding
char_n

  gsrm_feature_1 [b,max_length,c] + gsrm_feature_2 [b,max_length,c] 得到gsrm_feature,根据这个feature来预测字符。相当于起始符和第二个字符的embedding相加来预测第一个字符,结束符和倒数第二个字符的特征来预测最后一个字符。

vfsd

  gsrm_feature 和 pvam_feature在维度2concat起来,dim2全连接恢复到c。使用sigmoid计算出attention_map,之后这个attention_map*pvam_faatures + (1-attention_map)*gsrm_features得到vsfd_out

loss

pvam_loss+vsfd_loss*2+gsrm_loss*0.15

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值