From b2004fe58675b92bac449b4af613eb20332df91a Mon Sep 17 00:00:00 2001 From: WenmuZhou Date: Mon, 9 Nov 2020 18:29:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0resnet=20backbone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ppocr/modeling/backbones/det_resnet_vd.py | 13 ++++++++----- ppocr/modeling/backbones/rec_resnet_vd.py | 15 +++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ppocr/modeling/backbones/det_resnet_vd.py b/ppocr/modeling/backbones/det_resnet_vd.py index 6fa52716..3bb4a0d5 100644 --- a/ppocr/modeling/backbones/det_resnet_vd.py +++ b/ppocr/modeling/backbones/det_resnet_vd.py @@ -19,6 +19,7 @@ from __future__ import print_function import paddle from paddle import ParamAttr import paddle.nn as nn +import paddle.nn.functional as F __all__ = ["ResNet"] @@ -37,9 +38,9 @@ class ConvBNLayer(nn.Layer): super(ConvBNLayer, self).__init__() self.is_vd_mode = is_vd_mode - self._pool2d_avg = nn.AvgPool2d( + self._pool2d_avg = nn.AvgPool2D( kernel_size=2, stride=2, padding=0, ceil_mode=True) - self._conv = nn.Conv2d( + self._conv = nn.Conv2D( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, @@ -118,7 +119,8 @@ class BottleneckBlock(nn.Layer): short = inputs else: short = self.short(inputs) - y = paddle.elementwise_add(x=short, y=conv2, act='relu') + y = paddle.add(x=short, y=conv2) + y = F.relu(y) return y @@ -165,7 +167,8 @@ class BasicBlock(nn.Layer): short = inputs else: short = self.short(inputs) - y = paddle.elementwise_add(x=short, y=conv1, act='relu') + y = paddle.add(x=short, y=conv1) + y = F.relu(y) return y @@ -214,7 +217,7 @@ class ResNet(nn.Layer): stride=1, act='relu', name="conv1_3") - self.pool2d_max = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) + self.pool2d_max = nn.MaxPool2D(kernel_size=3, stride=2, padding=1) self.stages = [] self.out_channels = [] diff --git a/ppocr/modeling/backbones/rec_resnet_vd.py b/ppocr/modeling/backbones/rec_resnet_vd.py index 20b03c3d..6837ea0f 100644 --- a/ppocr/modeling/backbones/rec_resnet_vd.py +++ b/ppocr/modeling/backbones/rec_resnet_vd.py @@ -19,6 +19,7 @@ from __future__ import print_function import paddle from paddle import ParamAttr import paddle.nn as nn +import paddle.nn.functional as F __all__ = ["ResNet"] @@ -37,9 +38,9 @@ class ConvBNLayer(nn.Layer): super(ConvBNLayer, self).__init__() self.is_vd_mode = is_vd_mode - self._pool2d_avg = nn.AvgPool2d( + self._pool2d_avg = nn.AvgPool2D( kernel_size=stride, stride=stride, padding=0, ceil_mode=True) - self._conv = nn.Conv2d( + self._conv = nn.Conv2D( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, @@ -119,7 +120,8 @@ class BottleneckBlock(nn.Layer): short = inputs else: short = self.short(inputs) - y = paddle.elementwise_add(x=short, y=conv2, act='relu') + y = paddle.add(x=short, y=conv2) + y = F.relu(y) return y @@ -166,7 +168,8 @@ class BasicBlock(nn.Layer): short = inputs else: short = self.short(inputs) - y = paddle.elementwise_add(x=short, y=conv1, act='relu') + y = paddle.add(x=short, y=conv1) + y = F.relu(y) return y @@ -215,7 +218,7 @@ class ResNet(nn.Layer): stride=1, act='relu', name="conv1_3") - self.pool2d_max = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) + self.pool2d_max = nn.MaxPool2D(kernel_size=3, stride=2, padding=1) self.block_list = [] if layers >= 50: @@ -270,7 +273,7 @@ class ResNet(nn.Layer): shortcut = True self.block_list.append(basic_block) self.out_channels = num_filters[block] - self.out_pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0) + self.out_pool = nn.MaxPool2D(kernel_size=2, stride=2, padding=0) def forward(self, inputs): y = self.conv1_1(inputs) -- GitLab