From 2f4bb7cc34c019cb39610c8876b95f7ac40c8b68 Mon Sep 17 00:00:00 2001 From: guosheng Date: Fri, 22 Sep 2017 21:00:47 +0800 Subject: [PATCH] Fix ResNet in models --- image_classification/resnet.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/image_classification/resnet.py b/image_classification/resnet.py index 5a9f2432..54a6da63 100644 --- a/image_classification/resnet.py +++ b/image_classification/resnet.py @@ -22,24 +22,24 @@ def conv_bn_layer(input, return paddle.layer.batch_norm(input=tmp, act=active_type) -def shortcut(input, ch_in, ch_out, stride): - if ch_in != ch_out: +def shortcut(input, ch_out, stride): + if input.num_filters != ch_out: return conv_bn_layer(input, ch_out, 1, stride, 0, paddle.activation.Linear()) else: return input -def basicblock(input, ch_in, ch_out, stride): - short = shortcut(input, ch_in, ch_out, stride) +def basicblock(input, ch_out, stride): + short = shortcut(input, ch_out, stride) conv1 = conv_bn_layer(input, ch_out, 3, stride, 1) conv2 = conv_bn_layer(conv1, ch_out, 3, 1, 1, paddle.activation.Linear()) return paddle.layer.addto( input=[short, conv2], act=paddle.activation.Relu()) -def bottleneck(input, ch_in, ch_out, stride): - short = shortcut(input, ch_in, ch_out * 4, stride) +def bottleneck(input, ch_out, stride): + short = shortcut(input, ch_out * 4, stride) conv1 = conv_bn_layer(input, ch_out, 1, stride, 0) conv2 = conv_bn_layer(conv1, ch_out, 3, 1, 1) conv3 = conv_bn_layer(conv2, ch_out * 4, 1, 1, 0, @@ -48,10 +48,10 @@ def bottleneck(input, ch_in, ch_out, stride): input=[short, conv3], act=paddle.activation.Relu()) -def layer_warp(block_func, input, ch_in, ch_out, count, stride): - conv = block_func(input, ch_in, ch_out, stride) +def layer_warp(block_func, input, ch_out, count, stride): + conv = block_func(input, ch_out, stride) for i in range(1, count): - conv = block_func(conv, ch_out, ch_out, 1) + conv = block_func(conv, ch_out, 1) return conv @@ -67,10 +67,10 @@ def resnet_imagenet(input, class_dim, depth=50): conv1 = conv_bn_layer( input, ch_in=3, ch_out=64, filter_size=7, stride=2, padding=3) pool1 = paddle.layer.img_pool(input=conv1, pool_size=3, stride=2) - res1 = layer_warp(block_func, pool1, 64, 64, stages[0], 1) - res2 = layer_warp(block_func, res1, 64, 128, stages[1], 2) - res3 = layer_warp(block_func, res2, 128, 256, stages[2], 2) - res4 = layer_warp(block_func, res3, 256, 512, stages[3], 2) + res1 = layer_warp(block_func, pool1, 64, stages[0], 1) + res2 = layer_warp(block_func, res1, 128, stages[1], 2) + res3 = layer_warp(block_func, res2, 256, stages[2], 2) + res4 = layer_warp(block_func, res3, 512, stages[3], 2) pool2 = paddle.layer.img_pool( input=res4, pool_size=7, stride=1, pool_type=paddle.pooling.Avg()) out = paddle.layer.fc( -- GitLab