Skip to content

Commit 1c58e27

Browse files
author
wangyang59
committed
fixed a bug in parse_conv in config_parser.py
1 parent af7a50c commit 1c58e27

File tree

2 files changed

+188
-5
lines changed

2 files changed

+188
-5
lines changed

python/paddle/trainer/config_parser.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ def __init__(
649649

650650
parse_conv(conv_conf,
651651
input_layer_name,
652-
self.proj_conf.conv_conf)
652+
self.proj_conf.conv_conf,
653+
num_filters)
653654
# TODO: support rectangle input
654655
self.proj_conf.output_size = (self.proj_conf.conv_conf.output_x ** 2) * num_filters
655656

@@ -730,7 +731,8 @@ def __init__(
730731

731732
parse_conv(conv_conf,
732733
MakeLayerNameInSubmodel(input_layer_names[0]),
733-
self.operator_conf.conv_conf)
734+
self.operator_conf.conv_conf,
735+
num_filters)
734736
self.operator_conf.output_size = (self.operator_conf.conv_conf.output_x ** 2) * num_filters
735737

736738
config_assert(len(input_layer_names) == 2, "Conv is binary operator")
@@ -1097,7 +1099,7 @@ def parse_norm(norm, input_layer_name, norm_conf):
10971099
caffe_mode: compute the output size using floor instead of ceil,
10981100
which is consistent of caffe and CuDNN's convention.
10991101
'''
1100-
def parse_conv(conv, input_layer_name, conv_conf, trans=False):
1102+
def parse_conv(conv, input_layer_name, conv_conf, num_filters, trans=False):
11011103
conv_conf.filter_size = conv.filter_size
11021104
conv_conf.filter_size_y = conv.filter_size_y
11031105
conv_conf.channels = conv.channels
@@ -1106,10 +1108,11 @@ def parse_conv(conv, input_layer_name, conv_conf, trans=False):
11061108
conv_conf.stride = conv.stride
11071109
conv_conf.stride_y = conv.stride_y
11081110
conv_conf.groups = conv.groups
1109-
conv_conf.filter_channels = conv.channels / conv.groups
11101111
conv_conf.caffe_mode = conv.caffe_mode
11111112

11121113
if not trans:
1114+
conv_conf.filter_channels = conv.channels / conv.groups
1115+
11131116
img_pixels = g_layer_map[input_layer_name].size / conv.channels
11141117
print('channels=%d size=%d'%(conv.channels,
11151118
g_layer_map[input_layer_name].size))
@@ -1123,6 +1126,8 @@ def parse_conv(conv, input_layer_name, conv_conf, trans=False):
11231126
conv_conf.img_size, conv_conf.filter_size,
11241127
conv_conf.padding, conv_conf.stride, conv_conf.caffe_mode)
11251128
else:
1129+
conv_conf.filter_channels = num_filters / conv.groups
1130+
11261131
outputSize = g_layer_map[input_layer_name].size / conv.channels
11271132
print('channels=%d size=%d'%(conv.channels,
11281133
g_layer_map[input_layer_name].size))
@@ -1616,7 +1621,8 @@ def __init__(
16161621
parse_conv(
16171622
self.inputs[input_index].conv,
16181623
input_layer.name,
1619-
self.config.inputs[input_index].conv_conf)
1624+
self.config.inputs[input_index].conv_conf,
1625+
num_filters)
16201626
conv_conf = self.config.inputs[input_index].conv_conf
16211627
psize = self.calc_parameter_size(conv_conf)
16221628
print("output size for %s is %d " % (name, conv_conf.output_x))
@@ -1676,6 +1682,7 @@ def __init__(
16761682
self.inputs[input_index].conv,
16771683
input_layer.name,
16781684
self.config.inputs[input_index].conv_conf,
1685+
num_filters,
16791686
trans=True)
16801687
conv_conf = self.config.inputs[input_index].conv_conf
16811688
psize = self.calc_parameter_size(conv_conf)
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
type: "nn"
2+
layers {
3+
name: "image"
4+
type: "data"
5+
size: 51529
6+
active_type: ""
7+
}
8+
layers {
9+
name: "__conv_0__"
10+
type: "exconvt"
11+
size: 4194304
12+
active_type: ""
13+
inputs {
14+
input_layer_name: "image"
15+
input_parameter_name: "___conv_0__.w0"
16+
conv_conf {
17+
filter_size: 32
18+
channels: 1
19+
stride: 1
20+
padding: 1
21+
groups: 1
22+
filter_channels: 64
23+
output_x: 227
24+
img_size: 256
25+
caffe_mode: true
26+
filter_size_y: 32
27+
padding_y: 1
28+
stride_y: 1
29+
}
30+
}
31+
bias_parameter_name: "___conv_0__.wbias"
32+
num_filters: 64
33+
shared_biases: true
34+
}
35+
layers {
36+
name: "__batch_norm_0__"
37+
type: "batch_norm"
38+
size: 4194304
39+
active_type: "relu"
40+
inputs {
41+
input_layer_name: "__conv_0__"
42+
input_parameter_name: "___batch_norm_0__.w0"
43+
image_conf {
44+
channels: 64
45+
img_size: 256
46+
}
47+
}
48+
inputs {
49+
input_layer_name: "__conv_0__"
50+
input_parameter_name: "___batch_norm_0__.w1"
51+
}
52+
inputs {
53+
input_layer_name: "__conv_0__"
54+
input_parameter_name: "___batch_norm_0__.w2"
55+
}
56+
bias_parameter_name: "___batch_norm_0__.wbias"
57+
moving_average_fraction: 0.9
58+
}
59+
layers {
60+
name: "__crmnorm_0__"
61+
type: "norm"
62+
size: 4194304
63+
active_type: ""
64+
inputs {
65+
input_layer_name: "__batch_norm_0__"
66+
norm_conf {
67+
norm_type: "cmrnorm-projection"
68+
channels: 64
69+
size: 32
70+
scale: 0.0004
71+
pow: 0.75
72+
output_x: 256
73+
img_size: 256
74+
blocked: false
75+
}
76+
}
77+
}
78+
layers {
79+
name: "__pool_0__"
80+
type: "pool"
81+
size: 3240000
82+
active_type: ""
83+
inputs {
84+
input_layer_name: "__conv_0__"
85+
pool_conf {
86+
pool_type: "max-projection"
87+
channels: 64
88+
size_x: 32
89+
stride: 1
90+
output_x: 225
91+
img_size: 256
92+
padding: 0
93+
size_y: 32
94+
stride_y: 1
95+
output_y: 225
96+
img_size_y: 256
97+
padding_y: 0
98+
}
99+
}
100+
}
101+
parameters {
102+
name: "___conv_0__.w0"
103+
size: 65536
104+
initial_mean: 0.0
105+
initial_std: 0.0441941738242
106+
initial_strategy: 0
107+
initial_smart: false
108+
}
109+
parameters {
110+
name: "___conv_0__.wbias"
111+
size: 64
112+
initial_mean: 0.0
113+
initial_std: 0.0
114+
dims: 64
115+
dims: 1
116+
initial_strategy: 0
117+
initial_smart: false
118+
}
119+
parameters {
120+
name: "___batch_norm_0__.w0"
121+
size: 64
122+
initial_mean: 1.0
123+
initial_std: 0.0
124+
initial_strategy: 0
125+
initial_smart: false
126+
}
127+
parameters {
128+
name: "___batch_norm_0__.w1"
129+
size: 64
130+
initial_mean: 0.0
131+
initial_std: 0.0
132+
dims: 1
133+
dims: 64
134+
initial_strategy: 0
135+
initial_smart: false
136+
is_static: true
137+
is_shared: true
138+
}
139+
parameters {
140+
name: "___batch_norm_0__.w2"
141+
size: 64
142+
initial_mean: 0.0
143+
initial_std: 0.0
144+
dims: 1
145+
dims: 64
146+
initial_strategy: 0
147+
initial_smart: false
148+
is_static: true
149+
is_shared: true
150+
}
151+
parameters {
152+
name: "___batch_norm_0__.wbias"
153+
size: 64
154+
initial_mean: 0.0
155+
initial_std: 0.0
156+
dims: 1
157+
dims: 64
158+
initial_strategy: 0
159+
initial_smart: false
160+
}
161+
input_layer_names: "image"
162+
output_layer_names: "__pool_0__"
163+
output_layer_names: "__crmnorm_0__"
164+
sub_models {
165+
name: "root"
166+
layer_names: "image"
167+
layer_names: "__conv_0__"
168+
layer_names: "__batch_norm_0__"
169+
layer_names: "__crmnorm_0__"
170+
layer_names: "__pool_0__"
171+
input_layer_names: "image"
172+
output_layer_names: "__pool_0__"
173+
output_layer_names: "__crmnorm_0__"
174+
is_recurrent_layer_group: false
175+
}
176+

0 commit comments

Comments
 (0)