pyxllib 0.3.96__py3-none-any.whl → 0.3.197__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyxllib/algo/geo.py +12 -0
- pyxllib/algo/intervals.py +1 -1
- pyxllib/algo/matcher.py +78 -0
- pyxllib/algo/pupil.py +187 -19
- pyxllib/algo/specialist.py +2 -1
- pyxllib/algo/stat.py +38 -2
- {pyxlpr → pyxllib/autogui}/__init__.py +1 -1
- pyxllib/autogui/activewin.py +246 -0
- pyxllib/autogui/all.py +9 -0
- pyxllib/{ext/autogui → autogui}/autogui.py +40 -11
- pyxllib/autogui/uiautolib.py +362 -0
- pyxllib/autogui/wechat.py +827 -0
- pyxllib/autogui/wechat_msg.py +421 -0
- pyxllib/autogui/wxautolib.py +84 -0
- pyxllib/cv/slidercaptcha.py +137 -0
- pyxllib/data/echarts.py +123 -12
- pyxllib/data/jsonlib.py +89 -0
- pyxllib/data/pglib.py +514 -30
- pyxllib/data/sqlite.py +231 -4
- pyxllib/ext/JLineViewer.py +14 -1
- pyxllib/ext/drissionlib.py +277 -0
- pyxllib/ext/kq5034lib.py +0 -1594
- pyxllib/ext/robustprocfile.py +497 -0
- pyxllib/ext/unixlib.py +6 -5
- pyxllib/ext/utools.py +108 -95
- pyxllib/ext/webhook.py +32 -14
- pyxllib/ext/wjxlib.py +88 -0
- pyxllib/ext/wpsapi.py +124 -0
- pyxllib/ext/xlwork.py +9 -0
- pyxllib/ext/yuquelib.py +1003 -71
- pyxllib/file/docxlib.py +1 -1
- pyxllib/file/libreoffice.py +165 -0
- pyxllib/file/movielib.py +9 -0
- pyxllib/file/packlib/__init__.py +112 -75
- pyxllib/file/pdflib.py +1 -1
- pyxllib/file/pupil.py +1 -1
- pyxllib/file/specialist/dirlib.py +1 -1
- pyxllib/file/specialist/download.py +10 -3
- pyxllib/file/specialist/filelib.py +266 -55
- pyxllib/file/xlsxlib.py +205 -50
- pyxllib/file/xlsyncfile.py +341 -0
- pyxllib/prog/cachetools.py +64 -0
- pyxllib/prog/filelock.py +42 -0
- pyxllib/prog/multiprogs.py +940 -0
- pyxllib/prog/newbie.py +9 -2
- pyxllib/prog/pupil.py +129 -60
- pyxllib/prog/specialist/__init__.py +176 -2
- pyxllib/prog/specialist/bc.py +5 -2
- pyxllib/prog/specialist/browser.py +11 -2
- pyxllib/prog/specialist/datetime.py +68 -0
- pyxllib/prog/specialist/tictoc.py +12 -13
- pyxllib/prog/specialist/xllog.py +5 -5
- pyxllib/prog/xlosenv.py +7 -0
- pyxllib/text/airscript.js +744 -0
- pyxllib/text/charclasslib.py +17 -5
- pyxllib/text/jiebalib.py +6 -3
- pyxllib/text/jinjalib.py +32 -0
- pyxllib/text/jsa_ai_prompt.md +271 -0
- pyxllib/text/jscode.py +159 -4
- pyxllib/text/nestenv.py +1 -1
- pyxllib/text/newbie.py +12 -0
- pyxllib/text/pupil/common.py +26 -0
- pyxllib/text/specialist/ptag.py +2 -2
- pyxllib/text/templates/echart_base.html +11 -0
- pyxllib/text/templates/highlight_code.html +17 -0
- pyxllib/text/templates/latex_editor.html +103 -0
- pyxllib/text/xmllib.py +76 -14
- pyxllib/xl.py +2 -1
- pyxllib-0.3.197.dist-info/METADATA +48 -0
- pyxllib-0.3.197.dist-info/RECORD +126 -0
- {pyxllib-0.3.96.dist-info → pyxllib-0.3.197.dist-info}/WHEEL +1 -2
- pyxllib/ext/autogui/__init__.py +0 -8
- pyxllib-0.3.96.dist-info/METADATA +0 -51
- pyxllib-0.3.96.dist-info/RECORD +0 -333
- pyxllib-0.3.96.dist-info/top_level.txt +0 -2
- pyxlpr/ai/__init__.py +0 -5
- pyxlpr/ai/clientlib.py +0 -1281
- pyxlpr/ai/specialist.py +0 -286
- pyxlpr/ai/torch_app.py +0 -172
- pyxlpr/ai/xlpaddle.py +0 -655
- pyxlpr/ai/xltorch.py +0 -705
- pyxlpr/data/__init__.py +0 -11
- pyxlpr/data/coco.py +0 -1325
- pyxlpr/data/datacls.py +0 -365
- pyxlpr/data/datasets.py +0 -200
- pyxlpr/data/gptlib.py +0 -1291
- pyxlpr/data/icdar/__init__.py +0 -96
- pyxlpr/data/icdar/deteval.py +0 -377
- pyxlpr/data/icdar/icdar2013.py +0 -341
- pyxlpr/data/icdar/iou.py +0 -340
- pyxlpr/data/icdar/rrc_evaluation_funcs_1_1.py +0 -463
- pyxlpr/data/imtextline.py +0 -473
- pyxlpr/data/labelme.py +0 -866
- pyxlpr/data/removeline.py +0 -179
- pyxlpr/data/specialist.py +0 -57
- pyxlpr/eval/__init__.py +0 -85
- pyxlpr/paddleocr.py +0 -776
- pyxlpr/ppocr/__init__.py +0 -15
- pyxlpr/ppocr/configs/rec/multi_language/generate_multi_language_configs.py +0 -226
- pyxlpr/ppocr/data/__init__.py +0 -135
- pyxlpr/ppocr/data/imaug/ColorJitter.py +0 -26
- pyxlpr/ppocr/data/imaug/__init__.py +0 -67
- pyxlpr/ppocr/data/imaug/copy_paste.py +0 -170
- pyxlpr/ppocr/data/imaug/east_process.py +0 -437
- pyxlpr/ppocr/data/imaug/gen_table_mask.py +0 -244
- pyxlpr/ppocr/data/imaug/iaa_augment.py +0 -114
- pyxlpr/ppocr/data/imaug/label_ops.py +0 -789
- pyxlpr/ppocr/data/imaug/make_border_map.py +0 -184
- pyxlpr/ppocr/data/imaug/make_pse_gt.py +0 -106
- pyxlpr/ppocr/data/imaug/make_shrink_map.py +0 -126
- pyxlpr/ppocr/data/imaug/operators.py +0 -433
- pyxlpr/ppocr/data/imaug/pg_process.py +0 -906
- pyxlpr/ppocr/data/imaug/randaugment.py +0 -143
- pyxlpr/ppocr/data/imaug/random_crop_data.py +0 -239
- pyxlpr/ppocr/data/imaug/rec_img_aug.py +0 -533
- pyxlpr/ppocr/data/imaug/sast_process.py +0 -777
- pyxlpr/ppocr/data/imaug/text_image_aug/__init__.py +0 -17
- pyxlpr/ppocr/data/imaug/text_image_aug/augment.py +0 -120
- pyxlpr/ppocr/data/imaug/text_image_aug/warp_mls.py +0 -168
- pyxlpr/ppocr/data/lmdb_dataset.py +0 -115
- pyxlpr/ppocr/data/pgnet_dataset.py +0 -104
- pyxlpr/ppocr/data/pubtab_dataset.py +0 -107
- pyxlpr/ppocr/data/simple_dataset.py +0 -372
- pyxlpr/ppocr/losses/__init__.py +0 -61
- pyxlpr/ppocr/losses/ace_loss.py +0 -52
- pyxlpr/ppocr/losses/basic_loss.py +0 -135
- pyxlpr/ppocr/losses/center_loss.py +0 -88
- pyxlpr/ppocr/losses/cls_loss.py +0 -30
- pyxlpr/ppocr/losses/combined_loss.py +0 -67
- pyxlpr/ppocr/losses/det_basic_loss.py +0 -208
- pyxlpr/ppocr/losses/det_db_loss.py +0 -80
- pyxlpr/ppocr/losses/det_east_loss.py +0 -63
- pyxlpr/ppocr/losses/det_pse_loss.py +0 -149
- pyxlpr/ppocr/losses/det_sast_loss.py +0 -121
- pyxlpr/ppocr/losses/distillation_loss.py +0 -272
- pyxlpr/ppocr/losses/e2e_pg_loss.py +0 -140
- pyxlpr/ppocr/losses/kie_sdmgr_loss.py +0 -113
- pyxlpr/ppocr/losses/rec_aster_loss.py +0 -99
- pyxlpr/ppocr/losses/rec_att_loss.py +0 -39
- pyxlpr/ppocr/losses/rec_ctc_loss.py +0 -44
- pyxlpr/ppocr/losses/rec_enhanced_ctc_loss.py +0 -70
- pyxlpr/ppocr/losses/rec_nrtr_loss.py +0 -30
- pyxlpr/ppocr/losses/rec_sar_loss.py +0 -28
- pyxlpr/ppocr/losses/rec_srn_loss.py +0 -47
- pyxlpr/ppocr/losses/table_att_loss.py +0 -109
- pyxlpr/ppocr/metrics/__init__.py +0 -44
- pyxlpr/ppocr/metrics/cls_metric.py +0 -45
- pyxlpr/ppocr/metrics/det_metric.py +0 -82
- pyxlpr/ppocr/metrics/distillation_metric.py +0 -73
- pyxlpr/ppocr/metrics/e2e_metric.py +0 -86
- pyxlpr/ppocr/metrics/eval_det_iou.py +0 -274
- pyxlpr/ppocr/metrics/kie_metric.py +0 -70
- pyxlpr/ppocr/metrics/rec_metric.py +0 -75
- pyxlpr/ppocr/metrics/table_metric.py +0 -50
- pyxlpr/ppocr/modeling/architectures/__init__.py +0 -32
- pyxlpr/ppocr/modeling/architectures/base_model.py +0 -88
- pyxlpr/ppocr/modeling/architectures/distillation_model.py +0 -60
- pyxlpr/ppocr/modeling/backbones/__init__.py +0 -54
- pyxlpr/ppocr/modeling/backbones/det_mobilenet_v3.py +0 -268
- pyxlpr/ppocr/modeling/backbones/det_resnet_vd.py +0 -246
- pyxlpr/ppocr/modeling/backbones/det_resnet_vd_sast.py +0 -285
- pyxlpr/ppocr/modeling/backbones/e2e_resnet_vd_pg.py +0 -265
- pyxlpr/ppocr/modeling/backbones/kie_unet_sdmgr.py +0 -186
- pyxlpr/ppocr/modeling/backbones/rec_mobilenet_v3.py +0 -138
- pyxlpr/ppocr/modeling/backbones/rec_mv1_enhance.py +0 -258
- pyxlpr/ppocr/modeling/backbones/rec_nrtr_mtb.py +0 -48
- pyxlpr/ppocr/modeling/backbones/rec_resnet_31.py +0 -210
- pyxlpr/ppocr/modeling/backbones/rec_resnet_aster.py +0 -143
- pyxlpr/ppocr/modeling/backbones/rec_resnet_fpn.py +0 -307
- pyxlpr/ppocr/modeling/backbones/rec_resnet_vd.py +0 -286
- pyxlpr/ppocr/modeling/heads/__init__.py +0 -54
- pyxlpr/ppocr/modeling/heads/cls_head.py +0 -52
- pyxlpr/ppocr/modeling/heads/det_db_head.py +0 -118
- pyxlpr/ppocr/modeling/heads/det_east_head.py +0 -121
- pyxlpr/ppocr/modeling/heads/det_pse_head.py +0 -37
- pyxlpr/ppocr/modeling/heads/det_sast_head.py +0 -128
- pyxlpr/ppocr/modeling/heads/e2e_pg_head.py +0 -253
- pyxlpr/ppocr/modeling/heads/kie_sdmgr_head.py +0 -206
- pyxlpr/ppocr/modeling/heads/multiheadAttention.py +0 -163
- pyxlpr/ppocr/modeling/heads/rec_aster_head.py +0 -393
- pyxlpr/ppocr/modeling/heads/rec_att_head.py +0 -202
- pyxlpr/ppocr/modeling/heads/rec_ctc_head.py +0 -88
- pyxlpr/ppocr/modeling/heads/rec_nrtr_head.py +0 -826
- pyxlpr/ppocr/modeling/heads/rec_sar_head.py +0 -402
- pyxlpr/ppocr/modeling/heads/rec_srn_head.py +0 -280
- pyxlpr/ppocr/modeling/heads/self_attention.py +0 -406
- pyxlpr/ppocr/modeling/heads/table_att_head.py +0 -246
- pyxlpr/ppocr/modeling/necks/__init__.py +0 -32
- pyxlpr/ppocr/modeling/necks/db_fpn.py +0 -111
- pyxlpr/ppocr/modeling/necks/east_fpn.py +0 -188
- pyxlpr/ppocr/modeling/necks/fpn.py +0 -138
- pyxlpr/ppocr/modeling/necks/pg_fpn.py +0 -314
- pyxlpr/ppocr/modeling/necks/rnn.py +0 -92
- pyxlpr/ppocr/modeling/necks/sast_fpn.py +0 -284
- pyxlpr/ppocr/modeling/necks/table_fpn.py +0 -110
- pyxlpr/ppocr/modeling/transforms/__init__.py +0 -28
- pyxlpr/ppocr/modeling/transforms/stn.py +0 -135
- pyxlpr/ppocr/modeling/transforms/tps.py +0 -308
- pyxlpr/ppocr/modeling/transforms/tps_spatial_transformer.py +0 -156
- pyxlpr/ppocr/optimizer/__init__.py +0 -61
- pyxlpr/ppocr/optimizer/learning_rate.py +0 -228
- pyxlpr/ppocr/optimizer/lr_scheduler.py +0 -49
- pyxlpr/ppocr/optimizer/optimizer.py +0 -160
- pyxlpr/ppocr/optimizer/regularizer.py +0 -52
- pyxlpr/ppocr/postprocess/__init__.py +0 -55
- pyxlpr/ppocr/postprocess/cls_postprocess.py +0 -33
- pyxlpr/ppocr/postprocess/db_postprocess.py +0 -234
- pyxlpr/ppocr/postprocess/east_postprocess.py +0 -143
- pyxlpr/ppocr/postprocess/locality_aware_nms.py +0 -200
- pyxlpr/ppocr/postprocess/pg_postprocess.py +0 -52
- pyxlpr/ppocr/postprocess/pse_postprocess/__init__.py +0 -15
- pyxlpr/ppocr/postprocess/pse_postprocess/pse/__init__.py +0 -29
- pyxlpr/ppocr/postprocess/pse_postprocess/pse/setup.py +0 -14
- pyxlpr/ppocr/postprocess/pse_postprocess/pse_postprocess.py +0 -118
- pyxlpr/ppocr/postprocess/rec_postprocess.py +0 -654
- pyxlpr/ppocr/postprocess/sast_postprocess.py +0 -355
- pyxlpr/ppocr/tools/__init__.py +0 -14
- pyxlpr/ppocr/tools/eval.py +0 -83
- pyxlpr/ppocr/tools/export_center.py +0 -77
- pyxlpr/ppocr/tools/export_model.py +0 -129
- pyxlpr/ppocr/tools/infer/predict_cls.py +0 -151
- pyxlpr/ppocr/tools/infer/predict_det.py +0 -300
- pyxlpr/ppocr/tools/infer/predict_e2e.py +0 -169
- pyxlpr/ppocr/tools/infer/predict_rec.py +0 -414
- pyxlpr/ppocr/tools/infer/predict_system.py +0 -204
- pyxlpr/ppocr/tools/infer/utility.py +0 -629
- pyxlpr/ppocr/tools/infer_cls.py +0 -83
- pyxlpr/ppocr/tools/infer_det.py +0 -134
- pyxlpr/ppocr/tools/infer_e2e.py +0 -122
- pyxlpr/ppocr/tools/infer_kie.py +0 -153
- pyxlpr/ppocr/tools/infer_rec.py +0 -146
- pyxlpr/ppocr/tools/infer_table.py +0 -107
- pyxlpr/ppocr/tools/program.py +0 -596
- pyxlpr/ppocr/tools/test_hubserving.py +0 -117
- pyxlpr/ppocr/tools/train.py +0 -163
- pyxlpr/ppocr/tools/xlprog.py +0 -748
- pyxlpr/ppocr/utils/EN_symbol_dict.txt +0 -94
- pyxlpr/ppocr/utils/__init__.py +0 -24
- pyxlpr/ppocr/utils/dict/ar_dict.txt +0 -117
- pyxlpr/ppocr/utils/dict/arabic_dict.txt +0 -162
- pyxlpr/ppocr/utils/dict/be_dict.txt +0 -145
- pyxlpr/ppocr/utils/dict/bg_dict.txt +0 -140
- pyxlpr/ppocr/utils/dict/chinese_cht_dict.txt +0 -8421
- pyxlpr/ppocr/utils/dict/cyrillic_dict.txt +0 -163
- pyxlpr/ppocr/utils/dict/devanagari_dict.txt +0 -167
- pyxlpr/ppocr/utils/dict/en_dict.txt +0 -63
- pyxlpr/ppocr/utils/dict/fa_dict.txt +0 -136
- pyxlpr/ppocr/utils/dict/french_dict.txt +0 -136
- pyxlpr/ppocr/utils/dict/german_dict.txt +0 -143
- pyxlpr/ppocr/utils/dict/hi_dict.txt +0 -162
- pyxlpr/ppocr/utils/dict/it_dict.txt +0 -118
- pyxlpr/ppocr/utils/dict/japan_dict.txt +0 -4399
- pyxlpr/ppocr/utils/dict/ka_dict.txt +0 -153
- pyxlpr/ppocr/utils/dict/korean_dict.txt +0 -3688
- pyxlpr/ppocr/utils/dict/latin_dict.txt +0 -185
- pyxlpr/ppocr/utils/dict/mr_dict.txt +0 -153
- pyxlpr/ppocr/utils/dict/ne_dict.txt +0 -153
- pyxlpr/ppocr/utils/dict/oc_dict.txt +0 -96
- pyxlpr/ppocr/utils/dict/pu_dict.txt +0 -130
- pyxlpr/ppocr/utils/dict/rs_dict.txt +0 -91
- pyxlpr/ppocr/utils/dict/rsc_dict.txt +0 -134
- pyxlpr/ppocr/utils/dict/ru_dict.txt +0 -125
- pyxlpr/ppocr/utils/dict/ta_dict.txt +0 -128
- pyxlpr/ppocr/utils/dict/table_dict.txt +0 -277
- pyxlpr/ppocr/utils/dict/table_structure_dict.txt +0 -2759
- pyxlpr/ppocr/utils/dict/te_dict.txt +0 -151
- pyxlpr/ppocr/utils/dict/ug_dict.txt +0 -114
- pyxlpr/ppocr/utils/dict/uk_dict.txt +0 -142
- pyxlpr/ppocr/utils/dict/ur_dict.txt +0 -137
- pyxlpr/ppocr/utils/dict/xi_dict.txt +0 -110
- pyxlpr/ppocr/utils/dict90.txt +0 -90
- pyxlpr/ppocr/utils/e2e_metric/Deteval.py +0 -574
- pyxlpr/ppocr/utils/e2e_metric/polygon_fast.py +0 -83
- pyxlpr/ppocr/utils/e2e_utils/extract_batchsize.py +0 -87
- pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_fast.py +0 -457
- pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_slow.py +0 -592
- pyxlpr/ppocr/utils/e2e_utils/pgnet_pp_utils.py +0 -162
- pyxlpr/ppocr/utils/e2e_utils/visual.py +0 -162
- pyxlpr/ppocr/utils/en_dict.txt +0 -95
- pyxlpr/ppocr/utils/gen_label.py +0 -81
- pyxlpr/ppocr/utils/ic15_dict.txt +0 -36
- pyxlpr/ppocr/utils/iou.py +0 -54
- pyxlpr/ppocr/utils/logging.py +0 -69
- pyxlpr/ppocr/utils/network.py +0 -84
- pyxlpr/ppocr/utils/ppocr_keys_v1.txt +0 -6623
- pyxlpr/ppocr/utils/profiler.py +0 -110
- pyxlpr/ppocr/utils/save_load.py +0 -150
- pyxlpr/ppocr/utils/stats.py +0 -72
- pyxlpr/ppocr/utils/utility.py +0 -80
- pyxlpr/ppstructure/__init__.py +0 -13
- pyxlpr/ppstructure/predict_system.py +0 -187
- pyxlpr/ppstructure/table/__init__.py +0 -13
- pyxlpr/ppstructure/table/eval_table.py +0 -72
- pyxlpr/ppstructure/table/matcher.py +0 -192
- pyxlpr/ppstructure/table/predict_structure.py +0 -136
- pyxlpr/ppstructure/table/predict_table.py +0 -221
- pyxlpr/ppstructure/table/table_metric/__init__.py +0 -16
- pyxlpr/ppstructure/table/table_metric/parallel.py +0 -51
- pyxlpr/ppstructure/table/table_metric/table_metric.py +0 -247
- pyxlpr/ppstructure/table/tablepyxl/__init__.py +0 -13
- pyxlpr/ppstructure/table/tablepyxl/style.py +0 -283
- pyxlpr/ppstructure/table/tablepyxl/tablepyxl.py +0 -118
- pyxlpr/ppstructure/utility.py +0 -71
- pyxlpr/xlai.py +0 -10
- /pyxllib/{ext/autogui → autogui}/virtualkey.py +0 -0
- {pyxllib-0.3.96.dist-info → pyxllib-0.3.197.dist-info/licenses}/LICENSE +0 -0
@@ -1,314 +0,0 @@
|
|
1
|
-
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
from __future__ import absolute_import
|
16
|
-
from __future__ import division
|
17
|
-
from __future__ import print_function
|
18
|
-
|
19
|
-
import paddle
|
20
|
-
from paddle import nn
|
21
|
-
import paddle.nn.functional as F
|
22
|
-
from paddle import ParamAttr
|
23
|
-
|
24
|
-
|
25
|
-
class ConvBNLayer(nn.Layer):
|
26
|
-
def __init__(self,
|
27
|
-
in_channels,
|
28
|
-
out_channels,
|
29
|
-
kernel_size,
|
30
|
-
stride=1,
|
31
|
-
groups=1,
|
32
|
-
is_vd_mode=False,
|
33
|
-
act=None,
|
34
|
-
name=None):
|
35
|
-
super(ConvBNLayer, self).__init__()
|
36
|
-
|
37
|
-
self.is_vd_mode = is_vd_mode
|
38
|
-
self._pool2d_avg = nn.AvgPool2D(
|
39
|
-
kernel_size=2, stride=2, padding=0, ceil_mode=True)
|
40
|
-
self._conv = nn.Conv2D(
|
41
|
-
in_channels=in_channels,
|
42
|
-
out_channels=out_channels,
|
43
|
-
kernel_size=kernel_size,
|
44
|
-
stride=stride,
|
45
|
-
padding=(kernel_size - 1) // 2,
|
46
|
-
groups=groups,
|
47
|
-
weight_attr=ParamAttr(name=name + "_weights"),
|
48
|
-
bias_attr=False)
|
49
|
-
if name == "conv1":
|
50
|
-
bn_name = "bn_" + name
|
51
|
-
else:
|
52
|
-
bn_name = "bn" + name[3:]
|
53
|
-
self._batch_norm = nn.BatchNorm(
|
54
|
-
out_channels,
|
55
|
-
act=act,
|
56
|
-
param_attr=ParamAttr(name=bn_name + '_scale'),
|
57
|
-
bias_attr=ParamAttr(bn_name + '_offset'),
|
58
|
-
moving_mean_name=bn_name + '_mean',
|
59
|
-
moving_variance_name=bn_name + '_variance',
|
60
|
-
use_global_stats=False)
|
61
|
-
|
62
|
-
def forward(self, inputs):
|
63
|
-
y = self._conv(inputs)
|
64
|
-
y = self._batch_norm(y)
|
65
|
-
return y
|
66
|
-
|
67
|
-
|
68
|
-
class DeConvBNLayer(nn.Layer):
|
69
|
-
def __init__(self,
|
70
|
-
in_channels,
|
71
|
-
out_channels,
|
72
|
-
kernel_size=4,
|
73
|
-
stride=2,
|
74
|
-
padding=1,
|
75
|
-
groups=1,
|
76
|
-
if_act=True,
|
77
|
-
act=None,
|
78
|
-
name=None):
|
79
|
-
super(DeConvBNLayer, self).__init__()
|
80
|
-
|
81
|
-
self.if_act = if_act
|
82
|
-
self.act = act
|
83
|
-
self.deconv = nn.Conv2DTranspose(
|
84
|
-
in_channels=in_channels,
|
85
|
-
out_channels=out_channels,
|
86
|
-
kernel_size=kernel_size,
|
87
|
-
stride=stride,
|
88
|
-
padding=padding,
|
89
|
-
groups=groups,
|
90
|
-
weight_attr=ParamAttr(name=name + '_weights'),
|
91
|
-
bias_attr=False)
|
92
|
-
self.bn = nn.BatchNorm(
|
93
|
-
num_channels=out_channels,
|
94
|
-
act=act,
|
95
|
-
param_attr=ParamAttr(name="bn_" + name + "_scale"),
|
96
|
-
bias_attr=ParamAttr(name="bn_" + name + "_offset"),
|
97
|
-
moving_mean_name="bn_" + name + "_mean",
|
98
|
-
moving_variance_name="bn_" + name + "_variance",
|
99
|
-
use_global_stats=False)
|
100
|
-
|
101
|
-
def forward(self, x):
|
102
|
-
x = self.deconv(x)
|
103
|
-
x = self.bn(x)
|
104
|
-
return x
|
105
|
-
|
106
|
-
|
107
|
-
class PGFPN(nn.Layer):
|
108
|
-
def __init__(self, in_channels, **kwargs):
|
109
|
-
super(PGFPN, self).__init__()
|
110
|
-
num_inputs = [2048, 2048, 1024, 512, 256]
|
111
|
-
num_outputs = [256, 256, 192, 192, 128]
|
112
|
-
self.out_channels = 128
|
113
|
-
self.conv_bn_layer_1 = ConvBNLayer(
|
114
|
-
in_channels=3,
|
115
|
-
out_channels=32,
|
116
|
-
kernel_size=3,
|
117
|
-
stride=1,
|
118
|
-
act=None,
|
119
|
-
name='FPN_d1')
|
120
|
-
self.conv_bn_layer_2 = ConvBNLayer(
|
121
|
-
in_channels=64,
|
122
|
-
out_channels=64,
|
123
|
-
kernel_size=3,
|
124
|
-
stride=1,
|
125
|
-
act=None,
|
126
|
-
name='FPN_d2')
|
127
|
-
self.conv_bn_layer_3 = ConvBNLayer(
|
128
|
-
in_channels=256,
|
129
|
-
out_channels=128,
|
130
|
-
kernel_size=3,
|
131
|
-
stride=1,
|
132
|
-
act=None,
|
133
|
-
name='FPN_d3')
|
134
|
-
self.conv_bn_layer_4 = ConvBNLayer(
|
135
|
-
in_channels=32,
|
136
|
-
out_channels=64,
|
137
|
-
kernel_size=3,
|
138
|
-
stride=2,
|
139
|
-
act=None,
|
140
|
-
name='FPN_d4')
|
141
|
-
self.conv_bn_layer_5 = ConvBNLayer(
|
142
|
-
in_channels=64,
|
143
|
-
out_channels=64,
|
144
|
-
kernel_size=3,
|
145
|
-
stride=1,
|
146
|
-
act='relu',
|
147
|
-
name='FPN_d5')
|
148
|
-
self.conv_bn_layer_6 = ConvBNLayer(
|
149
|
-
in_channels=64,
|
150
|
-
out_channels=128,
|
151
|
-
kernel_size=3,
|
152
|
-
stride=2,
|
153
|
-
act=None,
|
154
|
-
name='FPN_d6')
|
155
|
-
self.conv_bn_layer_7 = ConvBNLayer(
|
156
|
-
in_channels=128,
|
157
|
-
out_channels=128,
|
158
|
-
kernel_size=3,
|
159
|
-
stride=1,
|
160
|
-
act='relu',
|
161
|
-
name='FPN_d7')
|
162
|
-
self.conv_bn_layer_8 = ConvBNLayer(
|
163
|
-
in_channels=128,
|
164
|
-
out_channels=128,
|
165
|
-
kernel_size=1,
|
166
|
-
stride=1,
|
167
|
-
act=None,
|
168
|
-
name='FPN_d8')
|
169
|
-
|
170
|
-
self.conv_h0 = ConvBNLayer(
|
171
|
-
in_channels=num_inputs[0],
|
172
|
-
out_channels=num_outputs[0],
|
173
|
-
kernel_size=1,
|
174
|
-
stride=1,
|
175
|
-
act=None,
|
176
|
-
name="conv_h{}".format(0))
|
177
|
-
self.conv_h1 = ConvBNLayer(
|
178
|
-
in_channels=num_inputs[1],
|
179
|
-
out_channels=num_outputs[1],
|
180
|
-
kernel_size=1,
|
181
|
-
stride=1,
|
182
|
-
act=None,
|
183
|
-
name="conv_h{}".format(1))
|
184
|
-
self.conv_h2 = ConvBNLayer(
|
185
|
-
in_channels=num_inputs[2],
|
186
|
-
out_channels=num_outputs[2],
|
187
|
-
kernel_size=1,
|
188
|
-
stride=1,
|
189
|
-
act=None,
|
190
|
-
name="conv_h{}".format(2))
|
191
|
-
self.conv_h3 = ConvBNLayer(
|
192
|
-
in_channels=num_inputs[3],
|
193
|
-
out_channels=num_outputs[3],
|
194
|
-
kernel_size=1,
|
195
|
-
stride=1,
|
196
|
-
act=None,
|
197
|
-
name="conv_h{}".format(3))
|
198
|
-
self.conv_h4 = ConvBNLayer(
|
199
|
-
in_channels=num_inputs[4],
|
200
|
-
out_channels=num_outputs[4],
|
201
|
-
kernel_size=1,
|
202
|
-
stride=1,
|
203
|
-
act=None,
|
204
|
-
name="conv_h{}".format(4))
|
205
|
-
|
206
|
-
self.dconv0 = DeConvBNLayer(
|
207
|
-
in_channels=num_outputs[0],
|
208
|
-
out_channels=num_outputs[0 + 1],
|
209
|
-
name="dconv_{}".format(0))
|
210
|
-
self.dconv1 = DeConvBNLayer(
|
211
|
-
in_channels=num_outputs[1],
|
212
|
-
out_channels=num_outputs[1 + 1],
|
213
|
-
act=None,
|
214
|
-
name="dconv_{}".format(1))
|
215
|
-
self.dconv2 = DeConvBNLayer(
|
216
|
-
in_channels=num_outputs[2],
|
217
|
-
out_channels=num_outputs[2 + 1],
|
218
|
-
act=None,
|
219
|
-
name="dconv_{}".format(2))
|
220
|
-
self.dconv3 = DeConvBNLayer(
|
221
|
-
in_channels=num_outputs[3],
|
222
|
-
out_channels=num_outputs[3 + 1],
|
223
|
-
act=None,
|
224
|
-
name="dconv_{}".format(3))
|
225
|
-
self.conv_g1 = ConvBNLayer(
|
226
|
-
in_channels=num_outputs[1],
|
227
|
-
out_channels=num_outputs[1],
|
228
|
-
kernel_size=3,
|
229
|
-
stride=1,
|
230
|
-
act='relu',
|
231
|
-
name="conv_g{}".format(1))
|
232
|
-
self.conv_g2 = ConvBNLayer(
|
233
|
-
in_channels=num_outputs[2],
|
234
|
-
out_channels=num_outputs[2],
|
235
|
-
kernel_size=3,
|
236
|
-
stride=1,
|
237
|
-
act='relu',
|
238
|
-
name="conv_g{}".format(2))
|
239
|
-
self.conv_g3 = ConvBNLayer(
|
240
|
-
in_channels=num_outputs[3],
|
241
|
-
out_channels=num_outputs[3],
|
242
|
-
kernel_size=3,
|
243
|
-
stride=1,
|
244
|
-
act='relu',
|
245
|
-
name="conv_g{}".format(3))
|
246
|
-
self.conv_g4 = ConvBNLayer(
|
247
|
-
in_channels=num_outputs[4],
|
248
|
-
out_channels=num_outputs[4],
|
249
|
-
kernel_size=3,
|
250
|
-
stride=1,
|
251
|
-
act='relu',
|
252
|
-
name="conv_g{}".format(4))
|
253
|
-
self.convf = ConvBNLayer(
|
254
|
-
in_channels=num_outputs[4],
|
255
|
-
out_channels=num_outputs[4],
|
256
|
-
kernel_size=1,
|
257
|
-
stride=1,
|
258
|
-
act=None,
|
259
|
-
name="conv_f{}".format(4))
|
260
|
-
|
261
|
-
def forward(self, x):
|
262
|
-
c0, c1, c2, c3, c4, c5, c6 = x
|
263
|
-
# FPN_Down_Fusion
|
264
|
-
f = [c0, c1, c2]
|
265
|
-
g = [None, None, None]
|
266
|
-
h = [None, None, None]
|
267
|
-
h[0] = self.conv_bn_layer_1(f[0])
|
268
|
-
h[1] = self.conv_bn_layer_2(f[1])
|
269
|
-
h[2] = self.conv_bn_layer_3(f[2])
|
270
|
-
|
271
|
-
g[0] = self.conv_bn_layer_4(h[0])
|
272
|
-
g[1] = paddle.add(g[0], h[1])
|
273
|
-
g[1] = F.relu(g[1])
|
274
|
-
g[1] = self.conv_bn_layer_5(g[1])
|
275
|
-
g[1] = self.conv_bn_layer_6(g[1])
|
276
|
-
|
277
|
-
g[2] = paddle.add(g[1], h[2])
|
278
|
-
g[2] = F.relu(g[2])
|
279
|
-
g[2] = self.conv_bn_layer_7(g[2])
|
280
|
-
f_down = self.conv_bn_layer_8(g[2])
|
281
|
-
|
282
|
-
# FPN UP Fusion
|
283
|
-
f1 = [c6, c5, c4, c3, c2]
|
284
|
-
g = [None, None, None, None, None]
|
285
|
-
h = [None, None, None, None, None]
|
286
|
-
h[0] = self.conv_h0(f1[0])
|
287
|
-
h[1] = self.conv_h1(f1[1])
|
288
|
-
h[2] = self.conv_h2(f1[2])
|
289
|
-
h[3] = self.conv_h3(f1[3])
|
290
|
-
h[4] = self.conv_h4(f1[4])
|
291
|
-
|
292
|
-
g[0] = self.dconv0(h[0])
|
293
|
-
g[1] = paddle.add(g[0], h[1])
|
294
|
-
g[1] = F.relu(g[1])
|
295
|
-
g[1] = self.conv_g1(g[1])
|
296
|
-
g[1] = self.dconv1(g[1])
|
297
|
-
|
298
|
-
g[2] = paddle.add(g[1], h[2])
|
299
|
-
g[2] = F.relu(g[2])
|
300
|
-
g[2] = self.conv_g2(g[2])
|
301
|
-
g[2] = self.dconv2(g[2])
|
302
|
-
|
303
|
-
g[3] = paddle.add(g[2], h[3])
|
304
|
-
g[3] = F.relu(g[3])
|
305
|
-
g[3] = self.conv_g3(g[3])
|
306
|
-
g[3] = self.dconv3(g[3])
|
307
|
-
|
308
|
-
g[4] = paddle.add(x=g[3], y=h[4])
|
309
|
-
g[4] = F.relu(g[4])
|
310
|
-
g[4] = self.conv_g4(g[4])
|
311
|
-
f_up = self.convf(g[4])
|
312
|
-
f_common = paddle.add(f_down, f_up)
|
313
|
-
f_common = F.relu(f_common)
|
314
|
-
return f_common
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
from __future__ import absolute_import
|
16
|
-
from __future__ import division
|
17
|
-
from __future__ import print_function
|
18
|
-
|
19
|
-
from paddle import nn
|
20
|
-
|
21
|
-
from pyxlpr.ppocr.modeling.heads.rec_ctc_head import get_para_bias_attr
|
22
|
-
|
23
|
-
|
24
|
-
class Im2Seq(nn.Layer):
|
25
|
-
def __init__(self, in_channels, **kwargs):
|
26
|
-
super().__init__()
|
27
|
-
self.out_channels = in_channels
|
28
|
-
|
29
|
-
def forward(self, x):
|
30
|
-
B, C, H, W = x.shape
|
31
|
-
assert H == 1
|
32
|
-
x = x.squeeze(axis=2)
|
33
|
-
x = x.transpose([0, 2, 1]) # (NTC)(batch, width, channels)
|
34
|
-
return x
|
35
|
-
|
36
|
-
|
37
|
-
class EncoderWithRNN(nn.Layer):
|
38
|
-
def __init__(self, in_channels, hidden_size):
|
39
|
-
super(EncoderWithRNN, self).__init__()
|
40
|
-
self.out_channels = hidden_size * 2
|
41
|
-
self.lstm = nn.LSTM(
|
42
|
-
in_channels, hidden_size, direction='bidirectional', num_layers=2)
|
43
|
-
|
44
|
-
def forward(self, x):
|
45
|
-
x, _ = self.lstm(x)
|
46
|
-
return x
|
47
|
-
|
48
|
-
|
49
|
-
class EncoderWithFC(nn.Layer):
|
50
|
-
def __init__(self, in_channels, hidden_size):
|
51
|
-
super(EncoderWithFC, self).__init__()
|
52
|
-
self.out_channels = hidden_size
|
53
|
-
weight_attr, bias_attr = get_para_bias_attr(
|
54
|
-
l2_decay=0.00001, k=in_channels)
|
55
|
-
self.fc = nn.Linear(
|
56
|
-
in_channels,
|
57
|
-
hidden_size,
|
58
|
-
weight_attr=weight_attr,
|
59
|
-
bias_attr=bias_attr,
|
60
|
-
name='reduce_encoder_fea')
|
61
|
-
|
62
|
-
def forward(self, x):
|
63
|
-
x = self.fc(x)
|
64
|
-
return x
|
65
|
-
|
66
|
-
|
67
|
-
class SequenceEncoder(nn.Layer):
|
68
|
-
def __init__(self, in_channels, encoder_type, hidden_size=48, **kwargs):
|
69
|
-
super(SequenceEncoder, self).__init__()
|
70
|
-
self.encoder_reshape = Im2Seq(in_channels)
|
71
|
-
self.out_channels = self.encoder_reshape.out_channels
|
72
|
-
if encoder_type == 'reshape':
|
73
|
-
self.only_reshape = True
|
74
|
-
else:
|
75
|
-
support_encoder_dict = {
|
76
|
-
'reshape': Im2Seq,
|
77
|
-
'fc': EncoderWithFC,
|
78
|
-
'rnn': EncoderWithRNN
|
79
|
-
}
|
80
|
-
assert encoder_type in support_encoder_dict, '{} must in {}'.format(
|
81
|
-
encoder_type, support_encoder_dict.keys())
|
82
|
-
|
83
|
-
self.encoder = support_encoder_dict[encoder_type](
|
84
|
-
self.encoder_reshape.out_channels, hidden_size)
|
85
|
-
self.out_channels = self.encoder.out_channels
|
86
|
-
self.only_reshape = False
|
87
|
-
|
88
|
-
def forward(self, x):
|
89
|
-
x = self.encoder_reshape(x)
|
90
|
-
if not self.only_reshape:
|
91
|
-
x = self.encoder(x)
|
92
|
-
return x
|
@@ -1,284 +0,0 @@
|
|
1
|
-
# copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
from __future__ import absolute_import
|
16
|
-
from __future__ import division
|
17
|
-
from __future__ import print_function
|
18
|
-
|
19
|
-
import paddle
|
20
|
-
from paddle import nn
|
21
|
-
import paddle.nn.functional as F
|
22
|
-
from paddle import ParamAttr
|
23
|
-
|
24
|
-
|
25
|
-
class ConvBNLayer(nn.Layer):
|
26
|
-
def __init__(self,
|
27
|
-
in_channels,
|
28
|
-
out_channels,
|
29
|
-
kernel_size,
|
30
|
-
stride,
|
31
|
-
groups=1,
|
32
|
-
if_act=True,
|
33
|
-
act=None,
|
34
|
-
name=None):
|
35
|
-
super(ConvBNLayer, self).__init__()
|
36
|
-
self.if_act = if_act
|
37
|
-
self.act = act
|
38
|
-
self.conv = nn.Conv2D(
|
39
|
-
in_channels=in_channels,
|
40
|
-
out_channels=out_channels,
|
41
|
-
kernel_size=kernel_size,
|
42
|
-
stride=stride,
|
43
|
-
padding=(kernel_size - 1) // 2,
|
44
|
-
groups=groups,
|
45
|
-
weight_attr=ParamAttr(name=name + '_weights'),
|
46
|
-
bias_attr=False)
|
47
|
-
|
48
|
-
self.bn = nn.BatchNorm(
|
49
|
-
num_channels=out_channels,
|
50
|
-
act=act,
|
51
|
-
param_attr=ParamAttr(name="bn_" + name + "_scale"),
|
52
|
-
bias_attr=ParamAttr(name="bn_" + name + "_offset"),
|
53
|
-
moving_mean_name="bn_" + name + "_mean",
|
54
|
-
moving_variance_name="bn_" + name + "_variance")
|
55
|
-
|
56
|
-
def forward(self, x):
|
57
|
-
x = self.conv(x)
|
58
|
-
x = self.bn(x)
|
59
|
-
return x
|
60
|
-
|
61
|
-
|
62
|
-
class DeConvBNLayer(nn.Layer):
|
63
|
-
def __init__(self,
|
64
|
-
in_channels,
|
65
|
-
out_channels,
|
66
|
-
kernel_size,
|
67
|
-
stride,
|
68
|
-
groups=1,
|
69
|
-
if_act=True,
|
70
|
-
act=None,
|
71
|
-
name=None):
|
72
|
-
super(DeConvBNLayer, self).__init__()
|
73
|
-
self.if_act = if_act
|
74
|
-
self.act = act
|
75
|
-
self.deconv = nn.Conv2DTranspose(
|
76
|
-
in_channels=in_channels,
|
77
|
-
out_channels=out_channels,
|
78
|
-
kernel_size=kernel_size,
|
79
|
-
stride=stride,
|
80
|
-
padding=(kernel_size - 1) // 2,
|
81
|
-
groups=groups,
|
82
|
-
weight_attr=ParamAttr(name=name + '_weights'),
|
83
|
-
bias_attr=False)
|
84
|
-
self.bn = nn.BatchNorm(
|
85
|
-
num_channels=out_channels,
|
86
|
-
act=act,
|
87
|
-
param_attr=ParamAttr(name="bn_" + name + "_scale"),
|
88
|
-
bias_attr=ParamAttr(name="bn_" + name + "_offset"),
|
89
|
-
moving_mean_name="bn_" + name + "_mean",
|
90
|
-
moving_variance_name="bn_" + name + "_variance")
|
91
|
-
|
92
|
-
def forward(self, x):
|
93
|
-
x = self.deconv(x)
|
94
|
-
x = self.bn(x)
|
95
|
-
return x
|
96
|
-
|
97
|
-
|
98
|
-
class FPN_Up_Fusion(nn.Layer):
|
99
|
-
def __init__(self, in_channels):
|
100
|
-
super(FPN_Up_Fusion, self).__init__()
|
101
|
-
in_channels = in_channels[::-1]
|
102
|
-
out_channels = [256, 256, 192, 192, 128]
|
103
|
-
|
104
|
-
self.h0_conv = ConvBNLayer(in_channels[0], out_channels[0], 1, 1, act=None, name='fpn_up_h0')
|
105
|
-
self.h1_conv = ConvBNLayer(in_channels[1], out_channels[1], 1, 1, act=None, name='fpn_up_h1')
|
106
|
-
self.h2_conv = ConvBNLayer(in_channels[2], out_channels[2], 1, 1, act=None, name='fpn_up_h2')
|
107
|
-
self.h3_conv = ConvBNLayer(in_channels[3], out_channels[3], 1, 1, act=None, name='fpn_up_h3')
|
108
|
-
self.h4_conv = ConvBNLayer(in_channels[4], out_channels[4], 1, 1, act=None, name='fpn_up_h4')
|
109
|
-
|
110
|
-
self.g0_conv = DeConvBNLayer(out_channels[0], out_channels[1], 4, 2, act=None, name='fpn_up_g0')
|
111
|
-
|
112
|
-
self.g1_conv = nn.Sequential(
|
113
|
-
ConvBNLayer(out_channels[1], out_channels[1], 3, 1, act='relu', name='fpn_up_g1_1'),
|
114
|
-
DeConvBNLayer(out_channels[1], out_channels[2], 4, 2, act=None, name='fpn_up_g1_2')
|
115
|
-
)
|
116
|
-
self.g2_conv = nn.Sequential(
|
117
|
-
ConvBNLayer(out_channels[2], out_channels[2], 3, 1, act='relu', name='fpn_up_g2_1'),
|
118
|
-
DeConvBNLayer(out_channels[2], out_channels[3], 4, 2, act=None, name='fpn_up_g2_2')
|
119
|
-
)
|
120
|
-
self.g3_conv = nn.Sequential(
|
121
|
-
ConvBNLayer(out_channels[3], out_channels[3], 3, 1, act='relu', name='fpn_up_g3_1'),
|
122
|
-
DeConvBNLayer(out_channels[3], out_channels[4], 4, 2, act=None, name='fpn_up_g3_2')
|
123
|
-
)
|
124
|
-
|
125
|
-
self.g4_conv = nn.Sequential(
|
126
|
-
ConvBNLayer(out_channels[4], out_channels[4], 3, 1, act='relu', name='fpn_up_fusion_1'),
|
127
|
-
ConvBNLayer(out_channels[4], out_channels[4], 1, 1, act=None, name='fpn_up_fusion_2')
|
128
|
-
)
|
129
|
-
|
130
|
-
def _add_relu(self, x1, x2):
|
131
|
-
x = paddle.add(x=x1, y=x2)
|
132
|
-
x = F.relu(x)
|
133
|
-
return x
|
134
|
-
|
135
|
-
def forward(self, x):
|
136
|
-
f = x[2:][::-1]
|
137
|
-
h0 = self.h0_conv(f[0])
|
138
|
-
h1 = self.h1_conv(f[1])
|
139
|
-
h2 = self.h2_conv(f[2])
|
140
|
-
h3 = self.h3_conv(f[3])
|
141
|
-
h4 = self.h4_conv(f[4])
|
142
|
-
|
143
|
-
g0 = self.g0_conv(h0)
|
144
|
-
g1 = self._add_relu(g0, h1)
|
145
|
-
g1 = self.g1_conv(g1)
|
146
|
-
g2 = self.g2_conv(self._add_relu(g1, h2))
|
147
|
-
g3 = self.g3_conv(self._add_relu(g2, h3))
|
148
|
-
g4 = self.g4_conv(self._add_relu(g3, h4))
|
149
|
-
|
150
|
-
return g4
|
151
|
-
|
152
|
-
|
153
|
-
class FPN_Down_Fusion(nn.Layer):
|
154
|
-
def __init__(self, in_channels):
|
155
|
-
super(FPN_Down_Fusion, self).__init__()
|
156
|
-
out_channels = [32, 64, 128]
|
157
|
-
|
158
|
-
self.h0_conv = ConvBNLayer(in_channels[0], out_channels[0], 3, 1, act=None, name='fpn_down_h0')
|
159
|
-
self.h1_conv = ConvBNLayer(in_channels[1], out_channels[1], 3, 1, act=None, name='fpn_down_h1')
|
160
|
-
self.h2_conv = ConvBNLayer(in_channels[2], out_channels[2], 3, 1, act=None, name='fpn_down_h2')
|
161
|
-
|
162
|
-
self.g0_conv = ConvBNLayer(out_channels[0], out_channels[1], 3, 2, act=None, name='fpn_down_g0')
|
163
|
-
|
164
|
-
self.g1_conv = nn.Sequential(
|
165
|
-
ConvBNLayer(out_channels[1], out_channels[1], 3, 1, act='relu', name='fpn_down_g1_1'),
|
166
|
-
ConvBNLayer(out_channels[1], out_channels[2], 3, 2, act=None, name='fpn_down_g1_2')
|
167
|
-
)
|
168
|
-
|
169
|
-
self.g2_conv = nn.Sequential(
|
170
|
-
ConvBNLayer(out_channels[2], out_channels[2], 3, 1, act='relu', name='fpn_down_fusion_1'),
|
171
|
-
ConvBNLayer(out_channels[2], out_channels[2], 1, 1, act=None, name='fpn_down_fusion_2')
|
172
|
-
)
|
173
|
-
|
174
|
-
def forward(self, x):
|
175
|
-
f = x[:3]
|
176
|
-
h0 = self.h0_conv(f[0])
|
177
|
-
h1 = self.h1_conv(f[1])
|
178
|
-
h2 = self.h2_conv(f[2])
|
179
|
-
g0 = self.g0_conv(h0)
|
180
|
-
g1 = paddle.add(x=g0, y=h1)
|
181
|
-
g1 = F.relu(g1)
|
182
|
-
g1 = self.g1_conv(g1)
|
183
|
-
g2 = paddle.add(x=g1, y=h2)
|
184
|
-
g2 = F.relu(g2)
|
185
|
-
g2 = self.g2_conv(g2)
|
186
|
-
return g2
|
187
|
-
|
188
|
-
|
189
|
-
class Cross_Attention(nn.Layer):
|
190
|
-
def __init__(self, in_channels):
|
191
|
-
super(Cross_Attention, self).__init__()
|
192
|
-
self.theta_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act='relu', name='f_theta')
|
193
|
-
self.phi_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act='relu', name='f_phi')
|
194
|
-
self.g_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act='relu', name='f_g')
|
195
|
-
|
196
|
-
self.fh_weight_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act=None, name='fh_weight')
|
197
|
-
self.fh_sc_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act=None, name='fh_sc')
|
198
|
-
|
199
|
-
self.fv_weight_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act=None, name='fv_weight')
|
200
|
-
self.fv_sc_conv = ConvBNLayer(in_channels, in_channels, 1, 1, act=None, name='fv_sc')
|
201
|
-
|
202
|
-
self.f_attn_conv = ConvBNLayer(in_channels * 2, in_channels, 1, 1, act='relu', name='f_attn')
|
203
|
-
|
204
|
-
def _cal_fweight(self, f, shape):
|
205
|
-
f_theta, f_phi, f_g = f
|
206
|
-
#flatten
|
207
|
-
f_theta = paddle.transpose(f_theta, [0, 2, 3, 1])
|
208
|
-
f_theta = paddle.reshape(f_theta, [shape[0] * shape[1], shape[2], 128])
|
209
|
-
f_phi = paddle.transpose(f_phi, [0, 2, 3, 1])
|
210
|
-
f_phi = paddle.reshape(f_phi, [shape[0] * shape[1], shape[2], 128])
|
211
|
-
f_g = paddle.transpose(f_g, [0, 2, 3, 1])
|
212
|
-
f_g = paddle.reshape(f_g, [shape[0] * shape[1], shape[2], 128])
|
213
|
-
#correlation
|
214
|
-
f_attn = paddle.matmul(f_theta, paddle.transpose(f_phi, [0, 2, 1]))
|
215
|
-
#scale
|
216
|
-
f_attn = f_attn / (128**0.5)
|
217
|
-
f_attn = F.softmax(f_attn)
|
218
|
-
#weighted sum
|
219
|
-
f_weight = paddle.matmul(f_attn, f_g)
|
220
|
-
f_weight = paddle.reshape(
|
221
|
-
f_weight, [shape[0], shape[1], shape[2], 128])
|
222
|
-
return f_weight
|
223
|
-
|
224
|
-
def forward(self, f_common):
|
225
|
-
f_shape = paddle.shape(f_common)
|
226
|
-
# print('f_shape: ', f_shape)
|
227
|
-
|
228
|
-
f_theta = self.theta_conv(f_common)
|
229
|
-
f_phi = self.phi_conv(f_common)
|
230
|
-
f_g = self.g_conv(f_common)
|
231
|
-
|
232
|
-
######## horizon ########
|
233
|
-
fh_weight = self._cal_fweight([f_theta, f_phi, f_g],
|
234
|
-
[f_shape[0], f_shape[2], f_shape[3]])
|
235
|
-
fh_weight = paddle.transpose(fh_weight, [0, 3, 1, 2])
|
236
|
-
fh_weight = self.fh_weight_conv(fh_weight)
|
237
|
-
#short cut
|
238
|
-
fh_sc = self.fh_sc_conv(f_common)
|
239
|
-
f_h = F.relu(fh_weight + fh_sc)
|
240
|
-
|
241
|
-
######## vertical ########
|
242
|
-
fv_theta = paddle.transpose(f_theta, [0, 1, 3, 2])
|
243
|
-
fv_phi = paddle.transpose(f_phi, [0, 1, 3, 2])
|
244
|
-
fv_g = paddle.transpose(f_g, [0, 1, 3, 2])
|
245
|
-
fv_weight = self._cal_fweight([fv_theta, fv_phi, fv_g],
|
246
|
-
[f_shape[0], f_shape[3], f_shape[2]])
|
247
|
-
fv_weight = paddle.transpose(fv_weight, [0, 3, 2, 1])
|
248
|
-
fv_weight = self.fv_weight_conv(fv_weight)
|
249
|
-
#short cut
|
250
|
-
fv_sc = self.fv_sc_conv(f_common)
|
251
|
-
f_v = F.relu(fv_weight + fv_sc)
|
252
|
-
|
253
|
-
######## merge ########
|
254
|
-
f_attn = paddle.concat([f_h, f_v], axis=1)
|
255
|
-
f_attn = self.f_attn_conv(f_attn)
|
256
|
-
return f_attn
|
257
|
-
|
258
|
-
|
259
|
-
class SASTFPN(nn.Layer):
|
260
|
-
def __init__(self, in_channels, with_cab=False, **kwargs):
|
261
|
-
super(SASTFPN, self).__init__()
|
262
|
-
self.in_channels = in_channels
|
263
|
-
self.with_cab = with_cab
|
264
|
-
self.FPN_Down_Fusion = FPN_Down_Fusion(self.in_channels)
|
265
|
-
self.FPN_Up_Fusion = FPN_Up_Fusion(self.in_channels)
|
266
|
-
self.out_channels = 128
|
267
|
-
self.cross_attention = Cross_Attention(self.out_channels)
|
268
|
-
|
269
|
-
def forward(self, x):
|
270
|
-
#down fpn
|
271
|
-
f_down = self.FPN_Down_Fusion(x)
|
272
|
-
|
273
|
-
#up fpn
|
274
|
-
f_up = self.FPN_Up_Fusion(x)
|
275
|
-
|
276
|
-
#fusion
|
277
|
-
f_common = paddle.add(x=f_down, y=f_up)
|
278
|
-
f_common = F.relu(f_common)
|
279
|
-
|
280
|
-
if self.with_cab:
|
281
|
-
# print('enhence f_common with CAB.')
|
282
|
-
f_common = self.cross_attention(f_common)
|
283
|
-
|
284
|
-
return f_common
|