Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
c98c5dd1
Commit
c98c5dd1
authored
Nov 09, 2021
by
Leif
Browse files
Merge remote-tracking branch 'origin/dygraph' into dygraph
parents
063395ec
5ebf5d6e
Changes
77
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
248 additions
and
80 deletions
+248
-80
ppocr/data/imaug/make_shrink_map.py
ppocr/data/imaug/make_shrink_map.py
+17
-1
ppocr/data/imaug/random_crop_data.py
ppocr/data/imaug/random_crop_data.py
+17
-1
ppocr/data/imaug/sast_process.py
ppocr/data/imaug/sast_process.py
+4
-1
ppocr/data/imaug/text_image_aug/augment.py
ppocr/data/imaug/text_image_aug/augment.py
+4
-0
ppocr/data/imaug/text_image_aug/warp_mls.py
ppocr/data/imaug/text_image_aug/warp_mls.py
+5
-1
ppocr/losses/ace_loss.py
ppocr/losses/ace_loss.py
+4
-1
ppocr/losses/center_loss.py
ppocr/losses/center_loss.py
+3
-0
ppocr/losses/det_basic_loss.py
ppocr/losses/det_basic_loss.py
+5
-2
ppocr/losses/det_db_loss.py
ppocr/losses/det_db_loss.py
+4
-0
ppocr/losses/det_pse_loss.py
ppocr/losses/det_pse_loss.py
+4
-0
ppocr/modeling/backbones/rec_mv1_enhance.py
ppocr/modeling/backbones/rec_mv1_enhance.py
+2
-0
ppocr/modeling/backbones/rec_resnet_31.py
ppocr/modeling/backbones/rec_resnet_31.py
+69
-35
ppocr/modeling/backbones/rec_resnet_aster.py
ppocr/modeling/backbones/rec_resnet_aster.py
+4
-1
ppocr/modeling/heads/det_pse_head.py
ppocr/modeling/heads/det_pse_head.py
+11
-9
ppocr/modeling/heads/rec_aster_head.py
ppocr/modeling/heads/rec_aster_head.py
+4
-0
ppocr/modeling/heads/rec_att_head.py
ppocr/modeling/heads/rec_att_head.py
+1
-1
ppocr/modeling/heads/rec_sar_head.py
ppocr/modeling/heads/rec_sar_head.py
+19
-1
ppocr/modeling/necks/fpn.py
ppocr/modeling/necks/fpn.py
+63
-25
ppocr/modeling/transforms/stn.py
ppocr/modeling/transforms/stn.py
+4
-1
ppocr/modeling/transforms/tps.py
ppocr/modeling/transforms/tps.py
+4
-0
No files found.
ppocr/data/imaug/make_shrink_map.py
View file @
c98c5dd1
# -*- coding:utf-8 -*-
# copyright (c) 2020 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.
"""
This code is refer from:
https://github.com/WenmuZhou/DBNet.pytorch/blob/master/data_loader/modules/make_shrink_map.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
...
...
ppocr/data/imaug/random_crop_data.py
View file @
c98c5dd1
# -*- coding:utf-8 -*-
# copyright (c) 2020 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.
"""
This code is refer from:
https://github.com/WenmuZhou/DBNet.pytorch/blob/master/data_loader/modules/random_crop_data.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
...
...
ppocr/data/imaug/sast_process.py
View file @
c98c5dd1
...
...
@@ -11,7 +11,10 @@
#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.
"""
This part code is refered from:
https://github.com/songdejia/EAST/blob/master/data_utils.py
"""
import
math
import
cv2
import
numpy
as
np
...
...
ppocr/data/imaug/text_image_aug/augment.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/RubanSeven/Text-Image-Augmentation-python/blob/master/augment.py
"""
import
numpy
as
np
from
.warp_mls
import
WarpMLS
...
...
ppocr/data/imaug/text_image_aug/warp_mls.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/RubanSeven/Text-Image-Augmentation-python/blob/master/warp_mls.py
"""
import
numpy
as
np
...
...
ppocr/losses/ace_loss.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,9 @@
# 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.
# This code is refer from: https://github.com/viig99/LS-ACELoss
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
ppocr/losses/center_loss.py
View file @
c98c5dd1
...
...
@@ -12,6 +12,8 @@
#See the License for the specific language governing permissions and
#limitations under the License.
# This code is refer from: https://github.com/KaiyangZhou/pytorch-center-loss
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
@@ -27,6 +29,7 @@ class CenterLoss(nn.Layer):
"""
Reference: Wen et al. A Discriminative Feature Learning Approach for Deep Face Recognition. ECCV 2016.
"""
def
__init__
(
self
,
num_classes
=
6625
,
feat_dim
=
96
,
...
...
ppocr/losses/det_basic_loss.py
View file @
c98c5dd1
...
...
@@ -11,7 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/WenmuZhou/DBNet.pytorch/blob/master/models/losses/basic_loss.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
ppocr/losses/det_db_loss.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/WenmuZhou/DBNet.pytorch/blob/master/models/losses/DB_loss.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
...
...
ppocr/losses/det_pse_loss.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/whai362/PSENet/blob/python3/models/head/psenet_head.py
"""
import
paddle
from
paddle
import
nn
...
...
ppocr/modeling/backbones/rec_mv1_enhance.py
View file @
c98c5dd1
...
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# This code is refer from: https://github.com/PaddlePaddle/PaddleClas/blob/develop/ppcls/arch/backbone/legendary_models/pp_lcnet.py
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
ppocr/modeling/backbones/rec_resnet_31.py
View file @
c98c5dd1
# 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.
"""
This code is refer from:
https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/layers/conv_layer.py
https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/backbones/resnet31_ocr.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
@@ -18,12 +37,12 @@ def conv3x3(in_channel, out_channel, stride=1):
kernel_size
=
3
,
stride
=
stride
,
padding
=
1
,
bias_attr
=
False
)
bias_attr
=
False
)
class
BasicBlock
(
nn
.
Layer
):
expansion
=
1
def
__init__
(
self
,
in_channels
,
channels
,
stride
=
1
,
downsample
=
False
):
super
().
__init__
()
self
.
conv1
=
conv3x3
(
in_channels
,
channels
,
stride
)
...
...
@@ -34,9 +53,13 @@ class BasicBlock(nn.Layer):
self
.
downsample
=
downsample
if
downsample
:
self
.
downsample
=
nn
.
Sequential
(
nn
.
Conv2D
(
in_channels
,
channels
*
self
.
expansion
,
1
,
stride
,
bias_attr
=
False
),
nn
.
BatchNorm2D
(
channels
*
self
.
expansion
),
)
nn
.
Conv2D
(
in_channels
,
channels
*
self
.
expansion
,
1
,
stride
,
bias_attr
=
False
),
nn
.
BatchNorm2D
(
channels
*
self
.
expansion
),
)
else
:
self
.
downsample
=
nn
.
Sequential
()
self
.
stride
=
stride
...
...
@@ -69,6 +92,7 @@ class ResNet31(nn.Layer):
out_indices (None | Sequence[int]): Indices of output stages.
last_stage_pool (bool): If True, add `MaxPool2d` layer to last stage.
'''
def
__init__
(
self
,
in_channels
=
3
,
layers
=
[
1
,
2
,
5
,
3
],
...
...
@@ -83,41 +107,51 @@ class ResNet31(nn.Layer):
self
.
last_stage_pool
=
last_stage_pool
# conv 1 (Conv Conv)
self
.
conv1_1
=
nn
.
Conv2D
(
in_channels
,
channels
[
0
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv1_1
=
nn
.
Conv2D
(
in_channels
,
channels
[
0
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn1_1
=
nn
.
BatchNorm2D
(
channels
[
0
])
self
.
relu1_1
=
nn
.
ReLU
()
self
.
conv1_2
=
nn
.
Conv2D
(
channels
[
0
],
channels
[
1
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv1_2
=
nn
.
Conv2D
(
channels
[
0
],
channels
[
1
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn1_2
=
nn
.
BatchNorm2D
(
channels
[
1
])
self
.
relu1_2
=
nn
.
ReLU
()
# conv 2 (Max-pooling, Residual block, Conv)
self
.
pool2
=
nn
.
MaxPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
pool2
=
nn
.
MaxPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
block2
=
self
.
_make_layer
(
channels
[
1
],
channels
[
2
],
layers
[
0
])
self
.
conv2
=
nn
.
Conv2D
(
channels
[
2
],
channels
[
2
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv2
=
nn
.
Conv2D
(
channels
[
2
],
channels
[
2
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn2
=
nn
.
BatchNorm2D
(
channels
[
2
])
self
.
relu2
=
nn
.
ReLU
()
# conv 3 (Max-pooling, Residual block, Conv)
self
.
pool3
=
nn
.
MaxPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
pool3
=
nn
.
MaxPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
block3
=
self
.
_make_layer
(
channels
[
2
],
channels
[
3
],
layers
[
1
])
self
.
conv3
=
nn
.
Conv2D
(
channels
[
3
],
channels
[
3
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv3
=
nn
.
Conv2D
(
channels
[
3
],
channels
[
3
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn3
=
nn
.
BatchNorm2D
(
channels
[
3
])
self
.
relu3
=
nn
.
ReLU
()
# conv 4 (Max-pooling, Residual block, Conv)
self
.
pool4
=
nn
.
MaxPool2D
(
kernel_size
=
(
2
,
1
),
stride
=
(
2
,
1
),
padding
=
0
,
ceil_mode
=
True
)
self
.
pool4
=
nn
.
MaxPool2D
(
kernel_size
=
(
2
,
1
),
stride
=
(
2
,
1
),
padding
=
0
,
ceil_mode
=
True
)
self
.
block4
=
self
.
_make_layer
(
channels
[
3
],
channels
[
4
],
layers
[
2
])
self
.
conv4
=
nn
.
Conv2D
(
channels
[
4
],
channels
[
4
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv4
=
nn
.
Conv2D
(
channels
[
4
],
channels
[
4
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn4
=
nn
.
BatchNorm2D
(
channels
[
4
])
self
.
relu4
=
nn
.
ReLU
()
# conv 5 ((Max-pooling), Residual block, Conv)
self
.
pool5
=
None
if
self
.
last_stage_pool
:
self
.
pool5
=
nn
.
MaxPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
pool5
=
nn
.
MaxPool2D
(
kernel_size
=
2
,
stride
=
2
,
padding
=
0
,
ceil_mode
=
True
)
self
.
block5
=
self
.
_make_layer
(
channels
[
4
],
channels
[
5
],
layers
[
3
])
self
.
conv5
=
nn
.
Conv2D
(
channels
[
5
],
channels
[
5
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv5
=
nn
.
Conv2D
(
channels
[
5
],
channels
[
5
],
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn5
=
nn
.
BatchNorm2D
(
channels
[
5
])
self
.
relu5
=
nn
.
ReLU
()
...
...
@@ -135,14 +169,14 @@ class ResNet31(nn.Layer):
kernel_size
=
1
,
stride
=
1
,
bias_attr
=
False
),
nn
.
BatchNorm2D
(
output_channels
),
)
nn
.
BatchNorm2D
(
output_channels
),
)
layers
.
append
(
BasicBlock
(
input_channels
,
output_channels
,
downsample
=
downsample
))
layers
.
append
(
BasicBlock
(
input_channels
,
output_channels
,
downsample
=
downsample
))
input_channels
=
output_channels
return
nn
.
Sequential
(
*
layers
)
def
forward
(
self
,
x
):
x
=
self
.
conv1_1
(
x
)
x
=
self
.
bn1_1
(
x
)
...
...
@@ -166,7 +200,7 @@ class ResNet31(nn.Layer):
x
=
block_layer
(
x
)
x
=
conv_layer
(
x
)
x
=
bn_layer
(
x
)
x
=
relu_layer
(
x
)
x
=
relu_layer
(
x
)
outs
.
append
(
x
)
...
...
ppocr/modeling/backbones/rec_resnet_aster.py
View file @
c98c5dd1
...
...
@@ -11,7 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/ayumiymk/aster.pytorch/blob/master/lib/models/resnet_aster.py
"""
import
paddle
import
paddle.nn
as
nn
...
...
ppocr/modeling/heads/det_pse_head.py
View file @
c98c5dd1
# copyright (c) 202
0
PaddlePaddle Authors. All Rights Reserve.
# copyright (c) 202
1
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.
...
...
@@ -11,22 +11,24 @@
# 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.
"""
This code is refer from:
https://github.com/whai362/PSENet/blob/python3/models/head/psenet_head.py
"""
from
paddle
import
nn
class
PSEHead
(
nn
.
Layer
):
def
__init__
(
self
,
in_channels
,
hidden_dim
=
256
,
out_channels
=
7
,
**
kwargs
):
def
__init__
(
self
,
in_channels
,
hidden_dim
=
256
,
out_channels
=
7
,
**
kwargs
):
super
(
PSEHead
,
self
).
__init__
()
self
.
conv1
=
nn
.
Conv2D
(
in_channels
,
hidden_dim
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
conv1
=
nn
.
Conv2D
(
in_channels
,
hidden_dim
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
self
.
bn1
=
nn
.
BatchNorm2D
(
hidden_dim
)
self
.
relu1
=
nn
.
ReLU
()
self
.
conv2
=
nn
.
Conv2D
(
hidden_dim
,
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
conv2
=
nn
.
Conv2D
(
hidden_dim
,
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
def
forward
(
self
,
x
,
**
kwargs
):
out
=
self
.
conv1
(
x
)
...
...
ppocr/modeling/heads/rec_aster_head.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/ayumiymk/aster.pytorch/blob/master/lib/models/attention_recognition_head.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
ppocr/modeling/heads/rec_att_head.py
View file @
c98c5dd1
...
...
@@ -75,7 +75,7 @@ class AttentionHead(nn.Layer):
probs_step
,
axis
=
1
)],
axis
=
1
)
next_input
=
probs_step
.
argmax
(
axis
=
1
)
targets
=
next_input
probs
=
paddle
.
nn
.
functional
.
softmax
(
probs
,
axis
=
2
)
return
probs
...
...
ppocr/modeling/heads/rec_sar_head.py
View file @
c98c5dd1
# 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.
"""
This code is refer from:
https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/encoders/sar_encoder.py
https://github.com/open-mmlab/mmocr/blob/main/mmocr/models/textrecog/decoders/sar_decoder.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
@@ -275,7 +294,6 @@ class ParallelSARDecoder(BaseDecoder):
if
img_metas
is
not
None
and
self
.
mask
:
valid_ratios
=
img_metas
[
-
1
]
label
=
label
.
cuda
()
lab_embedding
=
self
.
embedding
(
label
)
# bsz * seq_len * emb_dim
out_enc
=
out_enc
.
unsqueeze
(
1
)
...
...
ppocr/modeling/necks/fpn.py
View file @
c98c5dd1
...
...
@@ -11,16 +11,31 @@
# 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.
"""
This code is refer from:
https://github.com/whai362/PSENet/blob/python3/models/neck/fpn.py
"""
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
):
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
,
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
()
...
...
@@ -28,46 +43,69 @@ class Conv_BN_ReLU(nn.Layer):
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
)))
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
))
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
)
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
.
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
.
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
)
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
.
smooth1_
=
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
.
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
)))
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'
,
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'
,
m
.
bias
=
paddle
.
create_parameter
(
shape
=
m
.
bias
.
shape
,
dtype
=
'float32'
,
default_initializer
=
paddle
.
nn
.
initializer
.
Constant
(
0.0
))
def
_upsample
(
self
,
x
,
scale
=
1
):
...
...
@@ -81,15 +119,15 @@ class FPN(nn.Layer):
p5
=
self
.
toplayer_
(
f5
)
f4
=
self
.
latlayer1_
(
f4
)
p4
=
self
.
_upsample_add
(
p5
,
f4
,
2
)
p4
=
self
.
_upsample_add
(
p5
,
f4
,
2
)
p4
=
self
.
smooth1_
(
p4
)
f3
=
self
.
latlayer2_
(
f3
)
p3
=
self
.
_upsample_add
(
p4
,
f3
,
2
)
p3
=
self
.
_upsample_add
(
p4
,
f3
,
2
)
p3
=
self
.
smooth2_
(
p3
)
f2
=
self
.
latlayer3_
(
f2
)
p2
=
self
.
_upsample_add
(
p3
,
f2
,
2
)
p2
=
self
.
_upsample_add
(
p3
,
f2
,
2
)
p2
=
self
.
smooth3_
(
p2
)
p3
=
self
.
_upsample
(
p3
,
2
)
...
...
ppocr/modeling/transforms/stn.py
View file @
c98c5dd1
...
...
@@ -11,7 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/ayumiymk/aster.pytorch/blob/master/lib/models/stn_head.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
ppocr/modeling/transforms/tps.py
View file @
c98c5dd1
...
...
@@ -11,6 +11,10 @@
# 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.
"""
This code is refer from:
https://github.com/clovaai/deep-text-recognition-benchmark/blob/master/modules/transformation.py
"""
from
__future__
import
absolute_import
from
__future__
import
division
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment