Skip to content

Commit 50c6885

Browse files
authored
Fix test_quantization_scale_pass by change the model, test=develop (#25710) (#25985)
1 parent 9742811 commit 50c6885

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

python/paddle/fluid/contrib/slim/tests/test_quantization_scale_pass.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,29 @@
3131
os.environ["CPU_NUM"] = "1"
3232

3333

34-
def residual_block(img, label, num=1):
35-
def conv_bn_layer(input,
36-
ch_out,
37-
filter_size,
38-
stride,
39-
padding,
40-
act='relu',
41-
bias_attr=False):
42-
tmp = fluid.layers.conv2d(
43-
input=input,
44-
filter_size=filter_size,
45-
num_filters=ch_out,
46-
stride=stride,
47-
padding=padding,
48-
act=None,
49-
bias_attr=bias_attr)
50-
return fluid.layers.batch_norm(input=tmp, act=act)
51-
52-
hidden = img
53-
for _ in six.moves.xrange(num):
54-
conv = conv_bn_layer(hidden, 20, 3, 1, 1, act=None, bias_attr=True)
55-
short = conv_bn_layer(hidden, 20, 1, 1, 0, act=None)
56-
hidden = fluid.layers.elementwise_add(x=conv, y=short, act='relu')
57-
fc = fluid.layers.fc(input=hidden, size=10, act='softmax')
58-
loss = fluid.layers.cross_entropy(input=fc, label=label)
59-
loss = fluid.layers.mean(loss)
60-
return loss
34+
def conv_net(img, label):
35+
conv_pool_1 = fluid.nets.simple_img_conv_pool(
36+
input=img,
37+
filter_size=5,
38+
num_filters=20,
39+
pool_size=2,
40+
pool_stride=2,
41+
pool_type='max',
42+
act="relu")
43+
conv_pool_1 = fluid.layers.batch_norm(conv_pool_1)
44+
conv_pool_2 = fluid.nets.simple_img_conv_pool(
45+
input=conv_pool_1,
46+
filter_size=5,
47+
num_filters=50,
48+
pool_size=2,
49+
pool_stride=2,
50+
pool_type='avg',
51+
act="relu")
52+
hidden = fluid.layers.fc(input=conv_pool_2, size=100, act='relu')
53+
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
54+
loss = fluid.layers.cross_entropy(input=prediction, label=label)
55+
avg_loss = fluid.layers.mean(loss)
56+
return avg_loss
6157

6258

6359
class TestQuantizationScalePass(unittest.TestCase):
@@ -76,7 +72,7 @@ def build_program(main, startup, is_test):
7672
name='image', shape=[1, 28, 28], dtype='float32')
7773
label = fluid.layers.data(
7874
name='label', shape=[1], dtype='int64')
79-
loss = residual_block(img, label, 1)
75+
loss = conv_net(img, label)
8076
if not is_test:
8177
opt = fluid.optimizer.Adam(learning_rate=0.0001)
8278
opt.minimize(loss)

0 commit comments

Comments
 (0)