diff --git a/paddle/gserver/tests/img_conv2_b.conf b/paddle/gserver/tests/img_conv2_b.conf deleted file mode 100644 index daea79e72f5c2530f7974ec9350e3b218915151e..0000000000000000000000000000000000000000 --- a/paddle/gserver/tests/img_conv2_b.conf +++ /dev/null @@ -1,36 +0,0 @@ -#edit-mode: -*- python -*- -# Copyright (c) 2016 Baidu, Inc. All Rights Reserved -# -# 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. - -from paddle.trainer_config_helpers import * - -settings(batch_size=10) -data = data_layer(name ="input", size=8*16*16) - -conv = img_conv_layer(input=data, filter_size=2, filter_size_y=2, - num_channels=8, - num_filters=16, stride=1, - bias_attr=True, - act=LinearActivation(), - layer_type="cudnn_conv") - -conv2 = img_conv_layer(input=data, filter_size=3, filter_size_y=3, - num_channels=8, - num_filters=16, stride=2, - bias_attr=True, - act=LinearActivation(), - groups=2, - layer_type="cudnn_conv") - -outputs(conv, conv2) diff --git a/paddle/gserver/tests/img_conv_a.conf b/paddle/gserver/tests/img_conv_a.conf index 940589ed9ac242d6a73a74c9be39fcaafe66b7be..20c89b875e84e10144e99cd1546146bfad8b057f 100644 --- a/paddle/gserver/tests/img_conv_a.conf +++ b/paddle/gserver/tests/img_conv_a.conf @@ -34,6 +34,7 @@ conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1, num_channels=8, num_filters=16, stride=1, bias_attr=True, - act=LinearActivation()) + act=LinearActivation(), + groups=2) outputs(concat, conv) diff --git a/paddle/gserver/tests/img_conv_b.conf b/paddle/gserver/tests/img_conv_b.conf index 8ca9c94541504d208b94f45bf71c8da440d18411..19b99c77fdebc45d1a8b1e071987386574b1acb2 100644 --- a/paddle/gserver/tests/img_conv_b.conf +++ b/paddle/gserver/tests/img_conv_b.conf @@ -24,7 +24,7 @@ proj2 = conv_projection(input=data, filter_size=1, filter_size_y=1, concat = concat_layer(input=[proj1, proj2], bias_attr=False, act=ReluActivation()) proj = conv_projection(input=data, filter_size=1, filter_size_y=1, - num_channels=8, num_filters=16, stride=1) + num_channels=8, num_filters=16, stride=1, groups=2) with mixed_layer(bias_attr=True, act=LinearActivation()) as conv: conv += proj diff --git a/paddle/gserver/tests/img_conv2_a.conf b/paddle/gserver/tests/img_conv_c.conf similarity index 58% rename from paddle/gserver/tests/img_conv2_a.conf rename to paddle/gserver/tests/img_conv_c.conf index cece09e5d58b97923713c5c00b1c927ef6eee7d8..fea332f6d1b2c9681c3b9d0bb3c15ea8b1895d24 100644 --- a/paddle/gserver/tests/img_conv2_a.conf +++ b/paddle/gserver/tests/img_conv_c.conf @@ -17,20 +17,27 @@ from paddle.trainer_config_helpers import * settings(batch_size=10) data = data_layer(name ="input", size=8*16*16) +conv1 = img_conv_layer(input=data, filter_size=1, filter_size_y=1, + num_channels=8, + num_filters=16, stride=1, + bias_attr=False, + act=ReluActivation(), + layer_type="exconv") +conv2 = img_conv_layer(input=data, filter_size=1, filter_size_y=1, + num_channels=8, + num_filters=16, stride=1, + bias_attr=False, + act=ReluActivation(), + layer_type="exconv") -conv = img_conv_layer(input=data, filter_size=2, filter_size_y=2, - num_channels=8, - num_filters=16, stride=1, - bias_attr=True, - act=LinearActivation(), - layer_type="exconv") +concat = concat_layer(input=[conv1, conv2]) -conv2 = img_conv_layer(input=data, filter_size=3, filter_size_y=3, +conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1, num_channels=8, - num_filters=16, stride=2, + num_filters=16, stride=1, bias_attr=True, act=LinearActivation(), groups=2, layer_type="exconv") - -outputs(conv, conv2) + +outputs(concat, conv) diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 4610c805a626f72884c265fdea142d0e36508fbe..55446ea824e30c08fa1fb2beb7e557be21565aea 100644 --- a/paddle/gserver/tests/test_LayerGrad.cpp +++ b/paddle/gserver/tests/test_LayerGrad.cpp @@ -166,9 +166,8 @@ TEST(Projection, scaling) { } } -#ifndef PADDLE_ONLY_CPU -TEST(Projection, conv) { - const int NUM_FILTERS = 16; +void testProjectionConv(size_t groups) { + const int NUM_FILTERS = 18; const int FILTER_SIZE = 2; const int FILTER_SIZE_Y = 3; const int CHANNELS = 3; @@ -186,7 +185,7 @@ TEST(Projection, conv) { conv->set_padding_y(1); conv->set_stride(2); conv->set_stride_y(2); - conv->set_groups(1); + conv->set_groups(groups); conv->set_filter_channels(conv->channels() / conv->groups()); conv->set_img_size(IMAGE_SIZE); int output_x = outputSize(conv->img_size(), @@ -206,7 +205,8 @@ TEST(Projection, conv) { testProjectionGrad( conf, INPUT_DATA, - /* parameterSize */ NUM_FILTERS * CHANNELS * FILTER_SIZE * FILTER_SIZE_Y, + /* parameterSize */ NUM_FILTERS * CHANNELS * FILTER_SIZE * FILTER_SIZE_Y + / groups, /* batchSize */ 100, true, false, @@ -214,51 +214,10 @@ TEST(Projection, conv) { true); } -TEST(Projection, conv2) { - const int NUM_FILTERS = 18; - const int FILTER_SIZE = 2; - const int FILTER_SIZE_Y = 3; - const int CHANNELS = 3; - const int IMAGE_SIZE = 16; - - ProjectionConfig conf; - conf.set_type("conv"); - conf.set_num_filters(NUM_FILTERS); - - ConvConfig* conv = conf.mutable_conv_conf(); - conv->set_filter_size(FILTER_SIZE); - conv->set_filter_size_y(FILTER_SIZE_Y); - conv->set_channels(CHANNELS); - conv->set_padding(0); - conv->set_padding_y(1); - conv->set_stride(2); - conv->set_stride_y(2); - conv->set_groups(3); - conv->set_filter_channels(conv->channels() / conv->groups()); - conv->set_img_size(IMAGE_SIZE); - int output_x = outputSize(conv->img_size(), - conv->filter_size(), - conv->padding(), - conv->stride(), - /* caffeMode */ true); - int output_y = outputSize(conv->img_size(), - conv->filter_size_y(), - conv->padding_y(), - conv->stride_y(), - /* caffeMode */ true); - conv->set_output_x(output_x); - conf.set_input_size(IMAGE_SIZE * IMAGE_SIZE * CHANNELS); - conf.set_output_size(output_x * output_y * NUM_FILTERS); - - testProjectionGrad( - conf, - INPUT_DATA, - /* parameterSize */ NUM_FILTERS * FILTER_SIZE * FILTER_SIZE_Y, - /* batchSize */ 100, - true, - false, - NUM_FILTERS, - true); +#ifndef PADDLE_ONLY_CPU +TEST(Projection, conv) { + testProjectionConv(1); + testProjectionConv(3); } #endif diff --git a/paddle/gserver/tests/test_NetworkCompare.cpp b/paddle/gserver/tests/test_NetworkCompare.cpp index 8d16c2373c27db2641716d41d898a865b6d1826a..71ed3bc4b6fb44a74868da2f95597c1967206bd4 100644 --- a/paddle/gserver/tests/test_NetworkCompare.cpp +++ b/paddle/gserver/tests/test_NetworkCompare.cpp @@ -256,9 +256,10 @@ TEST(Compare, img_conv) { FLAGS_use_gpu = useGpu; } +// Test cudnn_conv and exconv give the same result TEST(Compare, img_conv2) { - std::string config_file_a = "./gserver/tests/img_conv2_a.conf"; - std::string config_file_b = "./gserver/tests/img_conv2_b.conf"; + std::string config_file_a = "./gserver/tests/img_conv_a.conf"; + std::string config_file_b = "./gserver/tests/img_conv_c.conf"; bool useGpu = FLAGS_use_gpu; FLAGS_use_gpu = true; compareNetwork(config_file_a, config_file_b); diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index 9db42bf172a77ff0972107dd26eed3882bf5906e..10467e331d0915781ef832feab622196fcea44ab 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -698,7 +698,8 @@ class ConvProjection(Projection): ci = self.proj_conf.conv_conf.channels fh = self.proj_conf.conv_conf.filter_size fw = self.proj_conf.conv_conf.filter_size_y - return co * ci * fh * fw + gr = self.proj_conf.conv_conf.groups + return co * ci * fh * fw / gr def calc_bias_size(self): return self.proj_conf.num_filters