Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
142b5e9d
P
PaddleOCR
项目概览
weixin_41840029
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
142b5e9d
编写于
6月 27, 2022
作者:
W
wangjingyeye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add db++
上级
961dca72
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
111 addition
and
8 deletion
+111
-8
ppocr/data/imaug/operators.py
ppocr/data/imaug/operators.py
+7
-0
ppocr/modeling/backbones/__init__.py
ppocr/modeling/backbones/__init__.py
+3
-2
ppocr/modeling/backbones/det_resnet_vd.py
ppocr/modeling/backbones/det_resnet_vd.py
+7
-5
ppocr/modeling/necks/db_fpn.py
ppocr/modeling/necks/db_fpn.py
+59
-1
ppocr/optimizer/learning_rate.py
ppocr/optimizer/learning_rate.py
+35
-0
未找到文件。
ppocr/data/imaug/operators.py
浏览文件 @
142b5e9d
...
...
@@ -238,9 +238,12 @@ class DetResizeForTest(object):
def
__init__
(
self
,
**
kwargs
):
super
(
DetResizeForTest
,
self
).
__init__
()
self
.
resize_type
=
0
self
.
keep_ratio
=
False
if
'image_shape'
in
kwargs
:
self
.
image_shape
=
kwargs
[
'image_shape'
]
self
.
resize_type
=
1
if
'keep_ratio'
in
kwargs
:
######
self
.
keep_ratio
=
kwargs
[
'keep_ratio'
]
#######
elif
'limit_side_len'
in
kwargs
:
self
.
limit_side_len
=
kwargs
[
'limit_side_len'
]
self
.
limit_type
=
kwargs
.
get
(
'limit_type'
,
'min'
)
...
...
@@ -270,6 +273,10 @@ class DetResizeForTest(object):
def
resize_image_type1
(
self
,
img
):
resize_h
,
resize_w
=
self
.
image_shape
ori_h
,
ori_w
=
img
.
shape
[:
2
]
# (h, w, c)
if
self
.
keep_ratio
:
########
resize_w
=
ori_w
*
resize_h
/
ori_h
N
=
math
.
ceil
(
resize_w
/
32
)
resize_w
=
N
*
32
ratio_h
=
float
(
resize_h
)
/
ori_h
ratio_w
=
float
(
resize_w
)
/
ori_w
img
=
cv2
.
resize
(
img
,
(
int
(
resize_w
),
int
(
resize_h
)))
...
...
ppocr/modeling/backbones/__init__.py
浏览文件 @
142b5e9d
...
...
@@ -18,9 +18,10 @@ __all__ = ["build_backbone"]
def
build_backbone
(
config
,
model_type
):
if
model_type
==
"det"
or
model_type
==
"table"
:
from
.det_mobilenet_v3
import
MobileNetV3
from
.det_resnet_vd
import
ResNet
from
.det_resnet
import
ResNet
from
.det_resnet_vd
import
ResNet_vd
from
.det_resnet_vd_sast
import
ResNet_SAST
support_dict
=
[
"MobileNetV3"
,
"ResNet"
,
"ResNet_SAST"
]
support_dict
=
[
"MobileNetV3"
,
"ResNet"
,
"ResNet_
vd"
,
"ResNet_
SAST"
]
elif
model_type
==
"rec"
or
model_type
==
"cls"
:
from
.rec_mobilenet_v3
import
MobileNetV3
from
.rec_resnet_vd
import
ResNet
...
...
ppocr/modeling/backbones/det_resnet_vd.py
浏览文件 @
142b5e9d
...
...
@@ -25,7 +25,7 @@ from paddle.vision.ops import DeformConv2D
from
paddle.regularizer
import
L2Decay
from
paddle.nn.initializer
import
Normal
,
Constant
,
XavierUniform
__all__
=
[
"ResNet"
]
__all__
=
[
"ResNet
_vd"
,
"ConvBNLayer"
,
"DeformableConvV2
"
]
class
DeformableConvV2
(
nn
.
Layer
):
...
...
@@ -104,6 +104,7 @@ class ConvBNLayer(nn.Layer):
kernel_size
,
stride
=
1
,
groups
=
1
,
dcn_groups
=
1
,
is_vd_mode
=
False
,
act
=
None
,
is_dcn
=
False
):
...
...
@@ -128,7 +129,7 @@ class ConvBNLayer(nn.Layer):
kernel_size
=
kernel_size
,
stride
=
stride
,
padding
=
(
kernel_size
-
1
)
//
2
,
groups
=
2
,
#groups,
groups
=
dcn_groups
,
#groups,
bias_attr
=
False
)
self
.
_batch_norm
=
nn
.
BatchNorm
(
out_channels
,
act
=
act
)
...
...
@@ -162,7 +163,8 @@ class BottleneckBlock(nn.Layer):
kernel_size
=
3
,
stride
=
stride
,
act
=
'relu'
,
is_dcn
=
is_dcn
)
is_dcn
=
is_dcn
,
dcn_groups
=
2
)
self
.
conv2
=
ConvBNLayer
(
in_channels
=
out_channels
,
out_channels
=
out_channels
*
4
,
...
...
@@ -238,14 +240,14 @@ class BasicBlock(nn.Layer):
return
y
class
ResNet
(
nn
.
Layer
):
class
ResNet
_vd
(
nn
.
Layer
):
def
__init__
(
self
,
in_channels
=
3
,
layers
=
50
,
dcn_stage
=
None
,
out_indices
=
None
,
**
kwargs
):
super
(
ResNet
,
self
).
__init__
()
super
(
ResNet
_vd
,
self
).
__init__
()
self
.
layers
=
layers
supported_layers
=
[
18
,
34
,
50
,
101
,
152
,
200
]
...
...
ppocr/modeling/necks/db_fpn.py
浏览文件 @
142b5e9d
...
...
@@ -105,9 +105,10 @@ class DSConv(nn.Layer):
class
DBFPN
(
nn
.
Layer
):
def
__init__
(
self
,
in_channels
,
out_channels
,
**
kwargs
):
def
__init__
(
self
,
in_channels
,
out_channels
,
use_asf
=
None
,
**
kwargs
):
super
(
DBFPN
,
self
).
__init__
()
self
.
out_channels
=
out_channels
self
.
use_asf
=
use_asf
weight_attr
=
paddle
.
nn
.
initializer
.
KaimingUniform
()
self
.
in2_conv
=
nn
.
Conv2D
(
...
...
@@ -163,6 +164,9 @@ class DBFPN(nn.Layer):
weight_attr
=
ParamAttr
(
initializer
=
weight_attr
),
bias_attr
=
False
)
if
self
.
use_asf
:
self
.
asf
=
ASFBlock
(
self
.
out_channels
,
self
.
out_channels
//
4
)
def
forward
(
self
,
x
):
c2
,
c3
,
c4
,
c5
=
x
...
...
@@ -187,6 +191,10 @@ class DBFPN(nn.Layer):
p3
=
F
.
upsample
(
p3
,
scale_factor
=
2
,
mode
=
"nearest"
,
align_mode
=
1
)
fuse
=
paddle
.
concat
([
p5
,
p4
,
p3
,
p2
],
axis
=
1
)
if
self
.
use_asf
:
fuse
=
self
.
asf
(
fuse
,
[
p5
,
p4
,
p3
,
p2
])
return
fuse
...
...
@@ -356,3 +364,53 @@ class LKPAN(nn.Layer):
fuse
=
paddle
.
concat
([
p5
,
p4
,
p3
,
p2
],
axis
=
1
)
return
fuse
class
ASFBlock
(
nn
.
Layer
):
def
__init__
(
self
,
in_channels
,
inter_channels
,
out_features_num
=
4
):
super
(
ASFBlock
,
self
).
__init__
()
weight_attr
=
paddle
.
nn
.
initializer
.
KaimingUniform
()
self
.
in_channels
=
in_channels
self
.
inter_channels
=
inter_channels
self
.
out_features_num
=
out_features_num
self
.
conv
=
nn
.
Conv2D
(
in_channels
,
inter_channels
,
3
,
padding
=
1
)
self
.
attention_block_1
=
nn
.
Sequential
(
#Nx1xHxW
nn
.
Conv2D
(
1
,
1
,
3
,
bias_attr
=
False
,
padding
=
1
,
weight_attr
=
ParamAttr
(
initializer
=
weight_attr
)),
nn
.
ReLU
(),
nn
.
Conv2D
(
1
,
1
,
1
,
bias_attr
=
False
,
weight_attr
=
ParamAttr
(
initializer
=
weight_attr
)),
nn
.
Sigmoid
())
self
.
attention_block_2
=
nn
.
Sequential
(
nn
.
Conv2D
(
inter_channels
,
out_features_num
,
1
,
bias_attr
=
False
,
weight_attr
=
ParamAttr
(
initializer
=
weight_attr
)),
nn
.
Sigmoid
())
def
forward
(
self
,
fuse_features
,
features_list
):
fuse_features
=
self
.
conv
(
fuse_features
)
attention_scores
=
self
.
attention_block_1
(
paddle
.
mean
(
fuse_features
,
axis
=
1
,
keepdim
=
True
))
+
fuse_features
attention_scores
=
self
.
attention_block_2
(
attention_scores
)
assert
len
(
features_list
)
==
self
.
out_features_num
out_list
=
[]
for
i
in
range
(
self
.
out_features_num
):
out_list
.
append
(
attention_scores
[:,
i
:
i
+
1
]
*
features_list
[
i
])
return
paddle
.
concat
(
out_list
,
axis
=
1
)
ppocr/optimizer/learning_rate.py
浏览文件 @
142b5e9d
...
...
@@ -308,3 +308,38 @@ class Const(object):
end_lr
=
self
.
learning_rate
,
last_epoch
=
self
.
last_epoch
)
return
learning_rate
class
DecayLearningRate
(
object
):
"""
DecayLearningRate learning rate decay
new_lr = (lr - end_lr) * (1 - epoch/decay_steps)**power + end_lr
Args:
learning_rate(float): initial learning rate
step_each_epoch(int): steps each epoch
epochs(int): total training epochs
factor(float): Power of polynomial, should greater than 0.0 to get learning rate decay. Default: 0.9
end_lr(float): The minimum final learning rate. Default: 0.0.
"""
def
__init__
(
self
,
learning_rate
,
step_each_epoch
,
epochs
,
factor
=
0.9
,
end_lr
=
0
,
**
kwargs
):
super
(
DecayLearningRate
,
self
).
__init__
()
self
.
learning_rate
=
learning_rate
self
.
epochs
=
epochs
+
1
self
.
factor
=
factor
self
.
end_lr
=
0
self
.
decay_steps
=
step_each_epoch
*
epochs
def
__call__
(
self
):
learning_rate
=
lr
.
PolynomialDecay
(
learning_rate
=
self
.
learning_rate
,
decay_steps
=
self
.
decay_steps
,
power
=
self
.
factor
,
end_lr
=
self
.
end_lr
)
return
learning_rate
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录