Skip to content

Commit 09a5b8b

Browse files
author
wangyang59
committed
consolidate img_conv.conf in test_NetworkCompare
1 parent 0e78171 commit 09a5b8b

File tree

7 files changed

+34
-101
lines changed

7 files changed

+34
-101
lines changed

paddle/gserver/tests/img_conv2_b.conf

Lines changed: 0 additions & 36 deletions
This file was deleted.

paddle/gserver/tests/img_conv_a.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1,
3434
num_channels=8,
3535
num_filters=16, stride=1,
3636
bias_attr=True,
37-
act=LinearActivation())
37+
act=LinearActivation(),
38+
groups=2)
3839

3940
outputs(concat, conv)

paddle/gserver/tests/img_conv_b.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ proj2 = conv_projection(input=data, filter_size=1, filter_size_y=1,
2424
concat = concat_layer(input=[proj1, proj2], bias_attr=False, act=ReluActivation())
2525

2626
proj = conv_projection(input=data, filter_size=1, filter_size_y=1,
27-
num_channels=8, num_filters=16, stride=1)
27+
num_channels=8, num_filters=16, stride=1, groups=2)
2828

2929
with mixed_layer(bias_attr=True, act=LinearActivation()) as conv:
3030
conv += proj
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,27 @@ from paddle.trainer_config_helpers import *
1717

1818
settings(batch_size=10)
1919
data = data_layer(name ="input", size=8*16*16)
20+
conv1 = img_conv_layer(input=data, filter_size=1, filter_size_y=1,
21+
num_channels=8,
22+
num_filters=16, stride=1,
23+
bias_attr=False,
24+
act=ReluActivation(),
25+
layer_type="exconv")
26+
conv2 = img_conv_layer(input=data, filter_size=1, filter_size_y=1,
27+
num_channels=8,
28+
num_filters=16, stride=1,
29+
bias_attr=False,
30+
act=ReluActivation(),
31+
layer_type="exconv")
2032

21-
conv = img_conv_layer(input=data, filter_size=2, filter_size_y=2,
22-
num_channels=8,
23-
num_filters=16, stride=1,
24-
bias_attr=True,
25-
act=LinearActivation(),
26-
layer_type="exconv")
33+
concat = concat_layer(input=[conv1, conv2])
2734

28-
conv2 = img_conv_layer(input=data, filter_size=3, filter_size_y=3,
35+
conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1,
2936
num_channels=8,
30-
num_filters=16, stride=2,
37+
num_filters=16, stride=1,
3138
bias_attr=True,
3239
act=LinearActivation(),
3340
groups=2,
3441
layer_type="exconv")
35-
36-
outputs(conv, conv2)
42+
43+
outputs(concat, conv)

paddle/gserver/tests/test_LayerGrad.cpp

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ TEST(Projection, scaling) {
166166
}
167167
}
168168

169-
#ifndef PADDLE_ONLY_CPU
170-
TEST(Projection, conv) {
171-
const int NUM_FILTERS = 16;
169+
void testProjectionConv(size_t groups) {
170+
const int NUM_FILTERS = 18;
172171
const int FILTER_SIZE = 2;
173172
const int FILTER_SIZE_Y = 3;
174173
const int CHANNELS = 3;
@@ -186,7 +185,7 @@ TEST(Projection, conv) {
186185
conv->set_padding_y(1);
187186
conv->set_stride(2);
188187
conv->set_stride_y(2);
189-
conv->set_groups(1);
188+
conv->set_groups(groups);
190189
conv->set_filter_channels(conv->channels() / conv->groups());
191190
conv->set_img_size(IMAGE_SIZE);
192191
int output_x = outputSize(conv->img_size(),
@@ -206,59 +205,19 @@ TEST(Projection, conv) {
206205
testProjectionGrad(
207206
conf,
208207
INPUT_DATA,
209-
/* parameterSize */ NUM_FILTERS * CHANNELS * FILTER_SIZE * FILTER_SIZE_Y,
208+
/* parameterSize */ NUM_FILTERS * CHANNELS * FILTER_SIZE * FILTER_SIZE_Y
209+
/ groups,
210210
/* batchSize */ 100,
211211
true,
212212
false,
213213
NUM_FILTERS,
214214
true);
215215
}
216216

217-
TEST(Projection, conv2) {
218-
const int NUM_FILTERS = 18;
219-
const int FILTER_SIZE = 2;
220-
const int FILTER_SIZE_Y = 3;
221-
const int CHANNELS = 3;
222-
const int IMAGE_SIZE = 16;
223-
224-
ProjectionConfig conf;
225-
conf.set_type("conv");
226-
conf.set_num_filters(NUM_FILTERS);
227-
228-
ConvConfig* conv = conf.mutable_conv_conf();
229-
conv->set_filter_size(FILTER_SIZE);
230-
conv->set_filter_size_y(FILTER_SIZE_Y);
231-
conv->set_channels(CHANNELS);
232-
conv->set_padding(0);
233-
conv->set_padding_y(1);
234-
conv->set_stride(2);
235-
conv->set_stride_y(2);
236-
conv->set_groups(3);
237-
conv->set_filter_channels(conv->channels() / conv->groups());
238-
conv->set_img_size(IMAGE_SIZE);
239-
int output_x = outputSize(conv->img_size(),
240-
conv->filter_size(),
241-
conv->padding(),
242-
conv->stride(),
243-
/* caffeMode */ true);
244-
int output_y = outputSize(conv->img_size(),
245-
conv->filter_size_y(),
246-
conv->padding_y(),
247-
conv->stride_y(),
248-
/* caffeMode */ true);
249-
conv->set_output_x(output_x);
250-
conf.set_input_size(IMAGE_SIZE * IMAGE_SIZE * CHANNELS);
251-
conf.set_output_size(output_x * output_y * NUM_FILTERS);
252-
253-
testProjectionGrad(
254-
conf,
255-
INPUT_DATA,
256-
/* parameterSize */ NUM_FILTERS * FILTER_SIZE * FILTER_SIZE_Y,
257-
/* batchSize */ 100,
258-
true,
259-
false,
260-
NUM_FILTERS,
261-
true);
217+
#ifndef PADDLE_ONLY_CPU
218+
TEST(Projection, conv) {
219+
testProjectionConv(1);
220+
testProjectionConv(3);
262221
}
263222
#endif
264223

paddle/gserver/tests/test_NetworkCompare.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,10 @@ TEST(Compare, img_conv) {
256256
FLAGS_use_gpu = useGpu;
257257
}
258258

259+
// Test cudnn_conv and exconv give the same result
259260
TEST(Compare, img_conv2) {
260-
std::string config_file_a = "./gserver/tests/img_conv2_a.conf";
261-
std::string config_file_b = "./gserver/tests/img_conv2_b.conf";
261+
std::string config_file_a = "./gserver/tests/img_conv_a.conf";
262+
std::string config_file_b = "./gserver/tests/img_conv_c.conf";
262263
bool useGpu = FLAGS_use_gpu;
263264
FLAGS_use_gpu = true;
264265
compareNetwork(config_file_a, config_file_b);

python/paddle/trainer/config_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ def calc_parameter_size(self, input_size, output_size):
698698
ci = self.proj_conf.conv_conf.channels
699699
fh = self.proj_conf.conv_conf.filter_size
700700
fw = self.proj_conf.conv_conf.filter_size_y
701-
return co * ci * fh * fw
701+
gr = self.proj_conf.conv_conf.groups
702+
return co * ci * fh * fw / gr
702703

703704
def calc_bias_size(self):
704705
return self.proj_conf.num_filters

0 commit comments

Comments
 (0)