提交 09a5b8bd 编写于 作者: W wangyang59

consolidate img_conv.conf in test_NetworkCompare

上级 0e781718
#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)
......@@ -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)
......@@ -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
......
......@@ -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)
......@@ -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
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册