From c0b4cefdcbc8848cd573892df22d6434d35ba04b Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 9 Dec 2020 20:26:40 +0800 Subject: [PATCH] fix comments and transform to transforms --- configs/det/{ => ch_ppocr_v1.1}/ch_det_mv3_db.yml | 0 configs/det/{ => ch_ppocr_v1.1}/ch_det_res18_db.yml | 2 +- ppocr/modeling/architectures/base_model.py | 2 +- ppocr/modeling/backbones/det_mobilenet_v3.py | 5 +++-- ppocr/modeling/{transform => transforms}/__init__.py | 0 ppocr/modeling/{transform => transforms}/tps.py | 0 ppocr/postprocess/db_postprocess.py | 12 ++++++++---- 7 files changed, 13 insertions(+), 8 deletions(-) rename configs/det/{ => ch_ppocr_v1.1}/ch_det_mv3_db.yml (100%) rename configs/det/{ => ch_ppocr_v1.1}/ch_det_res18_db.yml (97%) rename ppocr/modeling/{transform => transforms}/__init__.py (100%) rename ppocr/modeling/{transform => transforms}/tps.py (100%) diff --git a/configs/det/ch_det_mv3_db.yml b/configs/det/ch_ppocr_v1.1/ch_det_mv3_db.yml similarity index 100% rename from configs/det/ch_det_mv3_db.yml rename to configs/det/ch_ppocr_v1.1/ch_det_mv3_db.yml diff --git a/configs/det/ch_det_res18_db.yml b/configs/det/ch_ppocr_v1.1/ch_det_res18_db.yml similarity index 97% rename from configs/det/ch_det_res18_db.yml rename to configs/det/ch_ppocr_v1.1/ch_det_res18_db.yml index 9c903fa4..e34d9449 100644 --- a/configs/det/ch_det_res18_db.yml +++ b/configs/det/ch_ppocr_v1.1/ch_det_res18_db.yml @@ -10,7 +10,7 @@ Global: # if pretrained_model is saved in static mode, load_static_weights must set to True load_static_weights: True cal_metric_during_train: False - pretrained_model: ./pretrain_models/MobileNetV3_large_x0_5_pretrained + pretrained_model: ./pretrain_models/ResNet18_vd_pretrained checkpoints: #./output/det_db_0.001_DiceLoss_256_pp_config_2.0b_4gpu/best_accuracy save_inference_dir: use_visualdl: False diff --git a/ppocr/modeling/architectures/base_model.py b/ppocr/modeling/architectures/base_model.py index 0c4fe650..ab44b53a 100644 --- a/ppocr/modeling/architectures/base_model.py +++ b/ppocr/modeling/architectures/base_model.py @@ -16,7 +16,7 @@ from __future__ import division from __future__ import print_function from paddle import nn -from ppocr.modeling.transform import build_transform +from ppocr.modeling.transforms import build_transform from ppocr.modeling.backbones import build_backbone from ppocr.modeling.necks import build_neck from ppocr.modeling.heads import build_head diff --git a/ppocr/modeling/backbones/det_mobilenet_v3.py b/ppocr/modeling/backbones/det_mobilenet_v3.py index d6b453d1..f97bcfca 100755 --- a/ppocr/modeling/backbones/det_mobilenet_v3.py +++ b/ppocr/modeling/backbones/det_mobilenet_v3.py @@ -111,6 +111,7 @@ class MobileNetV3(nn.Layer): i = 0 inplanes = make_divisible(inplanes * scale) for (k, exp, c, se, nl, s) in cfg: + se = se and not self.disable_se if s == 2 and i > 2: self.out_channels.append(inplanes) self.stages.append(nn.Sequential(*block_list)) @@ -231,7 +232,7 @@ class ResidualUnit(nn.Layer): if_act=True, act=act, name=name + "_depthwise") - if self.if_se and not self.disable_se: + if self.if_se: self.mid_se = SEModule(mid_channels, name=name + "_se") self.linear_conv = ConvBNLayer( in_channels=mid_channels, @@ -246,7 +247,7 @@ class ResidualUnit(nn.Layer): def forward(self, inputs): x = self.expand_conv(inputs) x = self.bottleneck_conv(x) - if self.if_se and not self.disable_se: + if self.if_se: x = self.mid_se(x) x = self.linear_conv(x) if self.if_shortcut: diff --git a/ppocr/modeling/transform/__init__.py b/ppocr/modeling/transforms/__init__.py similarity index 100% rename from ppocr/modeling/transform/__init__.py rename to ppocr/modeling/transforms/__init__.py diff --git a/ppocr/modeling/transform/tps.py b/ppocr/modeling/transforms/tps.py similarity index 100% rename from ppocr/modeling/transform/tps.py rename to ppocr/modeling/transforms/tps.py diff --git a/ppocr/postprocess/db_postprocess.py b/ppocr/postprocess/db_postprocess.py index dc27abd6..b0a67b01 100644 --- a/ppocr/postprocess/db_postprocess.py +++ b/ppocr/postprocess/db_postprocess.py @@ -33,13 +33,14 @@ class DBPostProcess(object): box_thresh=0.7, max_candidates=1000, unclip_ratio=2.0, + use_dilation=False, **kwargs): self.thresh = thresh self.box_thresh = box_thresh self.max_candidates = max_candidates self.unclip_ratio = unclip_ratio self.min_size = 3 - self.dilation_kernel = np.array([[1, 1], [1, 1]]) + self.dilation_kernel = None if not use_dilation else [[1, 1], [1, 1]] def boxes_from_bitmap(self, pred, _bitmap, dest_width, dest_height): ''' @@ -140,9 +141,12 @@ class DBPostProcess(object): boxes_batch = [] for batch_index in range(pred.shape[0]): height, width = shape_list[batch_index] - mask = cv2.dilate( - np.array(segmentation[batch_index]).astype(np.uint8), - self.dilation_kernel) + if self.dilation_kernel is not None: + mask = cv2.dilate( + np.array(segmentation[batch_index]).astype(np.uint8), + self.dilation_kernel) + else: + mask = segmentation[batch_index] boxes, scores = self.boxes_from_bitmap(pred[batch_index], mask, width, height)