Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
b626aa3e
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b626aa3e
编写于
8月 28, 2020
作者:
T
tink2123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
formate code
上级
91f6f243
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
23 deletion
+10
-23
ppocr/data/rec/dataset_traversal.py
ppocr/data/rec/dataset_traversal.py
+1
-0
ppocr/modeling/heads/self_attention/model.py
ppocr/modeling/heads/self_attention/model.py
+9
-23
未找到文件。
ppocr/data/rec/dataset_traversal.py
浏览文件 @
b626aa3e
...
@@ -257,6 +257,7 @@ class SimpleReader(object):
...
@@ -257,6 +257,7 @@ class SimpleReader(object):
norm_img
=
process_image_srn
(
norm_img
=
process_image_srn
(
img
=
img
,
img
=
img
,
image_shape
=
self
.
image_shape
,
image_shape
=
self
.
image_shape
,
char_ops
=
self
.
char_ops
,
num_heads
=
self
.
num_heads
,
num_heads
=
self
.
num_heads
,
max_text_length
=
self
.
max_text_length
)
max_text_length
=
self
.
max_text_length
)
else
:
else
:
...
...
ppocr/modeling/heads/self_attention/model.py
浏览文件 @
b626aa3e
...
@@ -4,9 +4,6 @@ import numpy as np
...
@@ -4,9 +4,6 @@ import numpy as np
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
import
paddle.fluid.layers
as
layers
# Set seed for CE
dropout_seed
=
None
encoder_data_input_fields
=
(
encoder_data_input_fields
=
(
"src_word"
,
"src_word"
,
"src_pos"
,
"src_pos"
,
...
@@ -186,10 +183,7 @@ def multi_head_attention(queries,
...
@@ -186,10 +183,7 @@ def multi_head_attention(queries,
weights
=
layers
.
softmax
(
product
)
weights
=
layers
.
softmax
(
product
)
if
dropout_rate
:
if
dropout_rate
:
weights
=
layers
.
dropout
(
weights
=
layers
.
dropout
(
weights
,
weights
,
dropout_prob
=
dropout_rate
,
seed
=
None
,
is_test
=
False
)
dropout_prob
=
dropout_rate
,
seed
=
dropout_seed
,
is_test
=
False
)
out
=
layers
.
matmul
(
weights
,
v
)
out
=
layers
.
matmul
(
weights
,
v
)
return
out
return
out
...
@@ -221,7 +215,7 @@ def positionwise_feed_forward(x, d_inner_hid, d_hid, dropout_rate):
...
@@ -221,7 +215,7 @@ def positionwise_feed_forward(x, d_inner_hid, d_hid, dropout_rate):
act
=
"relu"
)
act
=
"relu"
)
if
dropout_rate
:
if
dropout_rate
:
hidden
=
layers
.
dropout
(
hidden
=
layers
.
dropout
(
hidden
,
dropout_prob
=
dropout_rate
,
seed
=
dropout_seed
,
is_test
=
False
)
hidden
,
dropout_prob
=
dropout_rate
,
seed
=
None
,
is_test
=
False
)
out
=
layers
.
fc
(
input
=
hidden
,
size
=
d_hid
,
num_flatten_dims
=
2
)
out
=
layers
.
fc
(
input
=
hidden
,
size
=
d_hid
,
num_flatten_dims
=
2
)
return
out
return
out
...
@@ -245,10 +239,7 @@ def pre_post_process_layer(prev_out, out, process_cmd, dropout_rate=0.):
...
@@ -245,10 +239,7 @@ def pre_post_process_layer(prev_out, out, process_cmd, dropout_rate=0.):
elif
cmd
==
"d"
:
# add dropout
elif
cmd
==
"d"
:
# add dropout
if
dropout_rate
:
if
dropout_rate
:
out
=
layers
.
dropout
(
out
=
layers
.
dropout
(
out
,
out
,
dropout_prob
=
dropout_rate
,
seed
=
None
,
is_test
=
False
)
dropout_prob
=
dropout_rate
,
seed
=
dropout_seed
,
is_test
=
False
)
return
out
return
out
...
@@ -272,9 +263,8 @@ def prepare_encoder(
...
@@ -272,9 +263,8 @@ def prepare_encoder(
This module is used at the bottom of the encoder stacks.
This module is used at the bottom of the encoder stacks.
"""
"""
src_word_emb
=
src_word
# layers.concat(res,axis=1)
src_word_emb
=
src_word
src_word_emb
=
layers
.
cast
(
src_word_emb
,
'float32'
)
src_word_emb
=
layers
.
cast
(
src_word_emb
,
'float32'
)
# print("src_word_emb",src_word_emb)
src_word_emb
=
layers
.
scale
(
x
=
src_word_emb
,
scale
=
src_emb_dim
**
0.5
)
src_word_emb
=
layers
.
scale
(
x
=
src_word_emb
,
scale
=
src_emb_dim
**
0.5
)
src_pos_enc
=
layers
.
embedding
(
src_pos_enc
=
layers
.
embedding
(
...
@@ -285,7 +275,7 @@ def prepare_encoder(
...
@@ -285,7 +275,7 @@ def prepare_encoder(
src_pos_enc
.
stop_gradient
=
True
src_pos_enc
.
stop_gradient
=
True
enc_input
=
src_word_emb
+
src_pos_enc
enc_input
=
src_word_emb
+
src_pos_enc
return
layers
.
dropout
(
return
layers
.
dropout
(
enc_input
,
dropout_prob
=
dropout_rate
,
seed
=
dropout_seed
,
enc_input
,
dropout_prob
=
dropout_rate
,
seed
=
None
,
is_test
=
False
)
if
dropout_rate
else
enc_input
is_test
=
False
)
if
dropout_rate
else
enc_input
...
@@ -310,7 +300,7 @@ def prepare_decoder(src_word,
...
@@ -310,7 +300,7 @@ def prepare_decoder(src_word,
param_attr
=
fluid
.
ParamAttr
(
param_attr
=
fluid
.
ParamAttr
(
name
=
word_emb_param_name
,
name
=
word_emb_param_name
,
initializer
=
fluid
.
initializer
.
Normal
(
0.
,
src_emb_dim
**-
0.5
)))
initializer
=
fluid
.
initializer
.
Normal
(
0.
,
src_emb_dim
**-
0.5
)))
# print("target_word_emb",src_word_emb)
src_word_emb
=
layers
.
scale
(
x
=
src_word_emb
,
scale
=
src_emb_dim
**
0.5
)
src_word_emb
=
layers
.
scale
(
x
=
src_word_emb
,
scale
=
src_emb_dim
**
0.5
)
src_pos_enc
=
layers
.
embedding
(
src_pos_enc
=
layers
.
embedding
(
src_pos
,
src_pos
,
...
@@ -320,7 +310,7 @@ def prepare_decoder(src_word,
...
@@ -320,7 +310,7 @@ def prepare_decoder(src_word,
src_pos_enc
.
stop_gradient
=
True
src_pos_enc
.
stop_gradient
=
True
enc_input
=
src_word_emb
+
src_pos_enc
enc_input
=
src_word_emb
+
src_pos_enc
return
layers
.
dropout
(
return
layers
.
dropout
(
enc_input
,
dropout_prob
=
dropout_rate
,
seed
=
dropout_seed
,
enc_input
,
dropout_prob
=
dropout_rate
,
seed
=
None
,
is_test
=
False
)
if
dropout_rate
else
enc_input
is_test
=
False
)
if
dropout_rate
else
enc_input
...
@@ -465,12 +455,8 @@ def wrap_encoder(src_vocab_size,
...
@@ -465,12 +455,8 @@ def wrap_encoder(src_vocab_size,
img, src_pos, src_slf_attn_bias = enc_inputs
img, src_pos, src_slf_attn_bias = enc_inputs
img
img
"""
"""
if
enc_inputs
is
None
:
# This is used to implement independent encoder program in inference.
src_word
,
src_pos
,
src_slf_attn_bias
=
enc_inputs
#
src_word
,
src_pos
,
src_slf_attn_bias
=
make_all_inputs
(
encoder_data_input_fields
)
else
:
src_word
,
src_pos
,
src_slf_attn_bias
=
enc_inputs
#
enc_input
=
prepare_decoder
(
enc_input
=
prepare_decoder
(
src_word
,
src_word
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录