Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
982926db
P
PaddleOCR
项目概览
s920243400
/
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看板
提交
982926db
编写于
7月 27, 2021
作者:
W
WenmuZhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fpn
上级
017ff26f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
104 addition
and
1 deletion
+104
-1
ppocr/modeling/necks/__init__.py
ppocr/modeling/necks/__init__.py
+2
-1
ppocr/modeling/necks/fpn.py
ppocr/modeling/necks/fpn.py
+102
-0
未找到文件。
ppocr/modeling/necks/__init__.py
浏览文件 @
982926db
...
@@ -22,7 +22,8 @@ def build_neck(config):
...
@@ -22,7 +22,8 @@ def build_neck(config):
from
.rnn
import
SequenceEncoder
from
.rnn
import
SequenceEncoder
from
.pg_fpn
import
PGFPN
from
.pg_fpn
import
PGFPN
from
.table_fpn
import
TableFPN
from
.table_fpn
import
TableFPN
support_dict
=
[
'DBFPN'
,
'EASTFPN'
,
'SASTFPN'
,
'SequenceEncoder'
,
'PGFPN'
,
'TableFPN'
]
from
.fpn
import
FPN
support_dict
=
[
'FPN'
,
'DBFPN'
,
'EASTFPN'
,
'SASTFPN'
,
'SequenceEncoder'
,
'PGFPN'
,
'TableFPN'
]
module_name
=
config
.
pop
(
'name'
)
module_name
=
config
.
pop
(
'name'
)
assert
module_name
in
support_dict
,
Exception
(
'neck only support {}'
.
format
(
assert
module_name
in
support_dict
,
Exception
(
'neck only support {}'
.
format
(
...
...
ppocr/modeling/necks/fpn.py
0 → 100644
浏览文件 @
982926db
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
paddle.nn
as
nn
import
paddle
import
math
import
paddle.nn.functional
as
F
class
Conv_BN_ReLU
(
nn
.
Layer
):
def
__init__
(
self
,
in_planes
,
out_planes
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
):
super
(
Conv_BN_ReLU
,
self
).
__init__
()
self
.
conv
=
nn
.
Conv2D
(
in_planes
,
out_planes
,
kernel_size
=
kernel_size
,
stride
=
stride
,
padding
=
padding
,
bias_attr
=
False
)
self
.
bn
=
nn
.
BatchNorm2D
(
out_planes
,
momentum
=
0.1
)
self
.
relu
=
nn
.
ReLU
()
for
m
in
self
.
sublayers
():
if
isinstance
(
m
,
nn
.
Conv2D
):
n
=
m
.
_kernel_size
[
0
]
*
m
.
_kernel_size
[
1
]
*
m
.
_out_channels
m
.
weight
=
paddle
.
create_parameter
(
shape
=
m
.
weight
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Normal
(
0
,
math
.
sqrt
(
2.
/
n
)))
elif
isinstance
(
m
,
nn
.
BatchNorm2D
):
m
.
weight
=
paddle
.
create_parameter
(
shape
=
m
.
weight
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Constant
(
1.0
))
m
.
bias
=
paddle
.
create_parameter
(
shape
=
m
.
bias
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Constant
(
0.0
))
def
forward
(
self
,
x
):
return
self
.
relu
(
self
.
bn
(
self
.
conv
(
x
)))
class
FPN
(
nn
.
Layer
):
def
__init__
(
self
,
in_channels
,
out_channels
):
super
(
FPN
,
self
).
__init__
()
# Top layer
self
.
toplayer_
=
Conv_BN_ReLU
(
in_channels
[
3
],
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
# Lateral layers
self
.
latlayer1_
=
Conv_BN_ReLU
(
in_channels
[
2
],
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
latlayer2_
=
Conv_BN_ReLU
(
in_channels
[
1
],
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
latlayer3_
=
Conv_BN_ReLU
(
in_channels
[
0
],
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
# Smooth layers
self
.
smooth1_
=
Conv_BN_ReLU
(
out_channels
,
out_channels
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
smooth2_
=
Conv_BN_ReLU
(
out_channels
,
out_channels
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
smooth3_
=
Conv_BN_ReLU
(
out_channels
,
out_channels
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
out_channels
=
out_channels
*
4
for
m
in
self
.
sublayers
():
if
isinstance
(
m
,
nn
.
Conv2D
):
n
=
m
.
_kernel_size
[
0
]
*
m
.
_kernel_size
[
1
]
*
m
.
_out_channels
m
.
weight
=
paddle
.
create_parameter
(
shape
=
m
.
weight
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Normal
(
0
,
math
.
sqrt
(
2.
/
n
)))
elif
isinstance
(
m
,
nn
.
BatchNorm2D
):
m
.
weight
=
paddle
.
create_parameter
(
shape
=
m
.
weight
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Constant
(
1.0
))
m
.
bias
=
paddle
.
create_parameter
(
shape
=
m
.
bias
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Constant
(
0.0
))
def
_upsample
(
self
,
x
,
y
,
scale
=
1
):
_
,
_
,
H
,
W
=
y
.
shape
return
F
.
upsample
(
x
,
size
=
(
H
//
scale
,
W
//
scale
),
mode
=
'bilinear'
)
def
_upsample_add
(
self
,
x
,
y
):
_
,
_
,
H
,
W
=
y
.
shape
return
F
.
upsample
(
x
,
size
=
(
H
,
W
),
mode
=
'bilinear'
)
+
y
def
forward
(
self
,
x
):
f2
,
f3
,
f4
,
f5
=
x
p5
=
self
.
toplayer_
(
f5
)
f4
=
self
.
latlayer1_
(
f4
)
p4
=
self
.
_upsample_add
(
p5
,
f4
)
p4
=
self
.
smooth1_
(
p4
)
f3
=
self
.
latlayer2_
(
f3
)
p3
=
self
.
_upsample_add
(
p4
,
f3
)
p3
=
self
.
smooth2_
(
p3
)
f2
=
self
.
latlayer3_
(
f2
)
p2
=
self
.
_upsample_add
(
p3
,
f2
)
p2
=
self
.
smooth3_
(
p2
)
p3
=
self
.
_upsample
(
p3
,
p2
)
p4
=
self
.
_upsample
(
p4
,
p2
)
p5
=
self
.
_upsample
(
p5
,
p2
)
fuse
=
paddle
.
concat
([
p2
,
p3
,
p4
,
p5
],
axis
=
1
)
return
fuse
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录