Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
fb69a404
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看板
未验证
提交
fb69a404
编写于
6月 06, 2022
作者:
D
Double_V
提交者:
GitHub
6月 06, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6491 from tink2123/rm_fluid_2.5
replace fluid to paddle
上级
473a8116
ea85e23c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
21 addition
and
26 deletion
+21
-26
ppocr/losses/rec_aster_loss.py
ppocr/losses/rec_aster_loss.py
+2
-2
ppocr/losses/table_att_loss.py
ppocr/losses/table_att_loss.py
+12
-13
ppocr/modeling/backbones/kie_unet_sdmgr.py
ppocr/modeling/backbones/kie_unet_sdmgr.py
+1
-1
ppocr/modeling/backbones/rec_resnet_fpn.py
ppocr/modeling/backbones/rec_resnet_fpn.py
+0
-1
ppocr/modeling/heads/rec_srn_head.py
ppocr/modeling/heads/rec_srn_head.py
+0
-2
ppocr/modeling/heads/self_attention.py
ppocr/modeling/heads/self_attention.py
+6
-7
未找到文件。
ppocr/losses/rec_aster_loss.py
浏览文件 @
fb69a404
...
@@ -27,12 +27,12 @@ class CosineEmbeddingLoss(nn.Layer):
...
@@ -27,12 +27,12 @@ class CosineEmbeddingLoss(nn.Layer):
self
.
epsilon
=
1e-12
self
.
epsilon
=
1e-12
def
forward
(
self
,
x1
,
x2
,
target
):
def
forward
(
self
,
x1
,
x2
,
target
):
similarity
=
paddle
.
fluid
.
layers
.
reduce_
sum
(
similarity
=
paddle
.
sum
(
x1
*
x2
,
dim
=-
1
)
/
(
paddle
.
norm
(
x1
*
x2
,
dim
=-
1
)
/
(
paddle
.
norm
(
x1
,
axis
=-
1
)
*
paddle
.
norm
(
x1
,
axis
=-
1
)
*
paddle
.
norm
(
x2
,
axis
=-
1
)
+
self
.
epsilon
)
x2
,
axis
=-
1
)
+
self
.
epsilon
)
one_list
=
paddle
.
full_like
(
target
,
fill_value
=
1
)
one_list
=
paddle
.
full_like
(
target
,
fill_value
=
1
)
out
=
paddle
.
fluid
.
layers
.
reduce_
mean
(
out
=
paddle
.
mean
(
paddle
.
where
(
paddle
.
where
(
paddle
.
equal
(
target
,
one_list
),
1.
-
similarity
,
paddle
.
equal
(
target
,
one_list
),
1.
-
similarity
,
paddle
.
maximum
(
paddle
.
maximum
(
...
...
ppocr/losses/table_att_loss.py
浏览文件 @
fb69a404
...
@@ -19,7 +19,6 @@ from __future__ import print_function
...
@@ -19,7 +19,6 @@ from __future__ import print_function
import
paddle
import
paddle
from
paddle
import
nn
from
paddle
import
nn
from
paddle.nn
import
functional
as
F
from
paddle.nn
import
functional
as
F
from
paddle
import
fluid
class
TableAttentionLoss
(
nn
.
Layer
):
class
TableAttentionLoss
(
nn
.
Layer
):
def
__init__
(
self
,
structure_weight
,
loc_weight
,
use_giou
=
False
,
giou_weight
=
1.0
,
**
kwargs
):
def
__init__
(
self
,
structure_weight
,
loc_weight
,
use_giou
=
False
,
giou_weight
=
1.0
,
**
kwargs
):
...
@@ -36,13 +35,13 @@ class TableAttentionLoss(nn.Layer):
...
@@ -36,13 +35,13 @@ class TableAttentionLoss(nn.Layer):
:param bbox:[[x1,y1,x2,y2], [x1,y1,x2,y2],,,]
:param bbox:[[x1,y1,x2,y2], [x1,y1,x2,y2],,,]
:return: loss
:return: loss
'''
'''
ix1
=
fluid
.
layers
.
elementwise_max
(
preds
[:,
0
],
bbox
[:,
0
])
ix1
=
paddle
.
maximum
(
preds
[:,
0
],
bbox
[:,
0
])
iy1
=
fluid
.
layers
.
elementwise_max
(
preds
[:,
1
],
bbox
[:,
1
])
iy1
=
paddle
.
maximum
(
preds
[:,
1
],
bbox
[:,
1
])
ix2
=
fluid
.
layers
.
elementwise_min
(
preds
[:,
2
],
bbox
[:,
2
])
ix2
=
paddle
.
minimum
(
preds
[:,
2
],
bbox
[:,
2
])
iy2
=
fluid
.
layers
.
elementwise_min
(
preds
[:,
3
],
bbox
[:,
3
])
iy2
=
paddle
.
minimum
(
preds
[:,
3
],
bbox
[:,
3
])
iw
=
fluid
.
layers
.
clip
(
ix2
-
ix1
+
1e-3
,
0.
,
1e10
)
iw
=
paddle
.
clip
(
ix2
-
ix1
+
1e-3
,
0.
,
1e10
)
ih
=
fluid
.
layers
.
clip
(
iy2
-
iy1
+
1e-3
,
0.
,
1e10
)
ih
=
paddle
.
clip
(
iy2
-
iy1
+
1e-3
,
0.
,
1e10
)
# overlap
# overlap
inters
=
iw
*
ih
inters
=
iw
*
ih
...
@@ -55,12 +54,12 @@ class TableAttentionLoss(nn.Layer):
...
@@ -55,12 +54,12 @@ class TableAttentionLoss(nn.Layer):
# ious
# ious
ious
=
inters
/
uni
ious
=
inters
/
uni
ex1
=
fluid
.
layers
.
elementwise_min
(
preds
[:,
0
],
bbox
[:,
0
])
ex1
=
paddle
.
minimum
(
preds
[:,
0
],
bbox
[:,
0
])
ey1
=
fluid
.
layers
.
elementwise_min
(
preds
[:,
1
],
bbox
[:,
1
])
ey1
=
paddle
.
minimum
(
preds
[:,
1
],
bbox
[:,
1
])
ex2
=
fluid
.
layers
.
elementwise_max
(
preds
[:,
2
],
bbox
[:,
2
])
ex2
=
paddle
.
maximum
(
preds
[:,
2
],
bbox
[:,
2
])
ey2
=
fluid
.
layers
.
elementwise_max
(
preds
[:,
3
],
bbox
[:,
3
])
ey2
=
paddle
.
maximum
(
preds
[:,
3
],
bbox
[:,
3
])
ew
=
fluid
.
layers
.
clip
(
ex2
-
ex1
+
1e-3
,
0.
,
1e10
)
ew
=
paddle
.
clip
(
ex2
-
ex1
+
1e-3
,
0.
,
1e10
)
eh
=
fluid
.
layers
.
clip
(
ey2
-
ey1
+
1e-3
,
0.
,
1e10
)
eh
=
paddle
.
clip
(
ey2
-
ey1
+
1e-3
,
0.
,
1e10
)
# enclose erea
# enclose erea
enclose
=
ew
*
eh
+
eps
enclose
=
ew
*
eh
+
eps
...
...
ppocr/modeling/backbones/kie_unet_sdmgr.py
浏览文件 @
fb69a404
...
@@ -175,7 +175,7 @@ class Kie_backbone(nn.Layer):
...
@@ -175,7 +175,7 @@ class Kie_backbone(nn.Layer):
img
,
relations
,
texts
,
gt_bboxes
,
tag
,
img_size
)
img
,
relations
,
texts
,
gt_bboxes
,
tag
,
img_size
)
x
=
self
.
img_feat
(
img
)
x
=
self
.
img_feat
(
img
)
boxes
,
rois_num
=
self
.
bbox2roi
(
gt_bboxes
)
boxes
,
rois_num
=
self
.
bbox2roi
(
gt_bboxes
)
feats
=
paddle
.
fluid
.
layer
s
.
roi_align
(
feats
=
paddle
.
vision
.
op
s
.
roi_align
(
x
,
x
,
boxes
,
boxes
,
spatial_scale
=
1.0
,
spatial_scale
=
1.0
,
...
...
ppocr/modeling/backbones/rec_resnet_fpn.py
浏览文件 @
fb69a404
...
@@ -18,7 +18,6 @@ from __future__ import print_function
...
@@ -18,7 +18,6 @@ from __future__ import print_function
from
paddle
import
nn
,
ParamAttr
from
paddle
import
nn
,
ParamAttr
from
paddle.nn
import
functional
as
F
from
paddle.nn
import
functional
as
F
import
paddle.fluid
as
fluid
import
paddle
import
paddle
import
numpy
as
np
import
numpy
as
np
...
...
ppocr/modeling/heads/rec_srn_head.py
浏览文件 @
fb69a404
...
@@ -20,13 +20,11 @@ import math
...
@@ -20,13 +20,11 @@ import math
import
paddle
import
paddle
from
paddle
import
nn
,
ParamAttr
from
paddle
import
nn
,
ParamAttr
from
paddle.nn
import
functional
as
F
from
paddle.nn
import
functional
as
F
import
paddle.fluid
as
fluid
import
numpy
as
np
import
numpy
as
np
from
.self_attention
import
WrapEncoderForFeature
from
.self_attention
import
WrapEncoderForFeature
from
.self_attention
import
WrapEncoder
from
.self_attention
import
WrapEncoder
from
paddle.static
import
Program
from
paddle.static
import
Program
from
ppocr.modeling.backbones.rec_resnet_fpn
import
ResNetFPN
from
ppocr.modeling.backbones.rec_resnet_fpn
import
ResNetFPN
import
paddle.fluid.framework
as
framework
from
collections
import
OrderedDict
from
collections
import
OrderedDict
gradient_clip
=
10
gradient_clip
=
10
...
...
ppocr/modeling/heads/self_attention.py
浏览文件 @
fb69a404
...
@@ -22,7 +22,6 @@ import paddle
...
@@ -22,7 +22,6 @@ import paddle
from
paddle
import
ParamAttr
,
nn
from
paddle
import
ParamAttr
,
nn
from
paddle
import
nn
,
ParamAttr
from
paddle
import
nn
,
ParamAttr
from
paddle.nn
import
functional
as
F
from
paddle.nn
import
functional
as
F
import
paddle.fluid
as
fluid
import
numpy
as
np
import
numpy
as
np
gradient_clip
=
10
gradient_clip
=
10
...
@@ -288,10 +287,10 @@ class PrePostProcessLayer(nn.Layer):
...
@@ -288,10 +287,10 @@ class PrePostProcessLayer(nn.Layer):
"layer_norm_%d"
%
len
(
self
.
sublayers
()),
"layer_norm_%d"
%
len
(
self
.
sublayers
()),
paddle
.
nn
.
LayerNorm
(
paddle
.
nn
.
LayerNorm
(
normalized_shape
=
d_model
,
normalized_shape
=
d_model
,
weight_attr
=
fluid
.
ParamAttr
(
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Constant
(
1.
)),
initializer
=
paddle
.
nn
.
initializer
.
Constant
(
1.
)),
bias_attr
=
fluid
.
ParamAttr
(
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Constant
(
0.
)))))
initializer
=
paddle
.
nn
.
initializer
.
Constant
(
0.
)))))
elif
cmd
==
"d"
:
# add dropout
elif
cmd
==
"d"
:
# add dropout
self
.
functors
.
append
(
lambda
x
:
F
.
dropout
(
self
.
functors
.
append
(
lambda
x
:
F
.
dropout
(
x
,
p
=
dropout_rate
,
mode
=
"downscale_in_infer"
)
x
,
p
=
dropout_rate
,
mode
=
"downscale_in_infer"
)
...
@@ -324,7 +323,7 @@ class PrepareEncoder(nn.Layer):
...
@@ -324,7 +323,7 @@ class PrepareEncoder(nn.Layer):
def
forward
(
self
,
src_word
,
src_pos
):
def
forward
(
self
,
src_word
,
src_pos
):
src_word_emb
=
src_word
src_word_emb
=
src_word
src_word_emb
=
fluid
.
layers
.
cast
(
src_word_emb
,
'float32'
)
src_word_emb
=
paddle
.
cast
(
src_word_emb
,
'float32'
)
src_word_emb
=
paddle
.
scale
(
x
=
src_word_emb
,
scale
=
self
.
src_emb_dim
**
0.5
)
src_word_emb
=
paddle
.
scale
(
x
=
src_word_emb
,
scale
=
self
.
src_emb_dim
**
0.5
)
src_pos
=
paddle
.
squeeze
(
src_pos
,
axis
=-
1
)
src_pos
=
paddle
.
squeeze
(
src_pos
,
axis
=-
1
)
src_pos_enc
=
self
.
emb
(
src_pos
)
src_pos_enc
=
self
.
emb
(
src_pos
)
...
@@ -367,7 +366,7 @@ class PrepareDecoder(nn.Layer):
...
@@ -367,7 +366,7 @@ class PrepareDecoder(nn.Layer):
self
.
dropout_rate
=
dropout_rate
self
.
dropout_rate
=
dropout_rate
def
forward
(
self
,
src_word
,
src_pos
):
def
forward
(
self
,
src_word
,
src_pos
):
src_word
=
fluid
.
layers
.
cast
(
src_word
,
'int64'
)
src_word
=
paddle
.
cast
(
src_word
,
'int64'
)
src_word
=
paddle
.
squeeze
(
src_word
,
axis
=-
1
)
src_word
=
paddle
.
squeeze
(
src_word
,
axis
=-
1
)
src_word_emb
=
self
.
emb0
(
src_word
)
src_word_emb
=
self
.
emb0
(
src_word
)
src_word_emb
=
paddle
.
scale
(
x
=
src_word_emb
,
scale
=
self
.
src_emb_dim
**
0.5
)
src_word_emb
=
paddle
.
scale
(
x
=
src_word_emb
,
scale
=
self
.
src_emb_dim
**
0.5
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录