提交 f347d6e4 编写于 作者: T tensor-tang

add repeated fc relu unit test

test=develop
上级 99010e6e
...@@ -120,7 +120,7 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> { ...@@ -120,7 +120,7 @@ class FusionRepeatedFCReluKernel : public framework::OpKernel<T> {
int m = i_dims[0]; int m = i_dims[0];
int n = w_dims[1]; int n = w_dims[1];
int k = w_dims[0]; int k = w_dims[0];
relus[i - 1]->Resize({m, n}); relus[i]->Resize({m, n});
fc_relu(relus[i - 1]->data<T>(), weights[i]->data<T>(), fc_relu(relus[i - 1]->data<T>(), weights[i]->data<T>(),
biases[i]->data<T>(), relus[i]->mutable_data<T>(place), m, n, k); biases[i]->data<T>(), relus[i]->mutable_data<T>(place), m, n, k);
} }
......
# Copyright (c) 2018 PaddlePaddle Authors. 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 __future__ import print_function
import unittest
import numpy as np
from op_test import OpTest
from test_fc_op import fc_refer, MatrixGenerate
class TestFusionRepeatedFCReluOp(OpTest):
def setUp(self):
self.bs = 3
self.ic = 9
self.oc = [2, 4, 3]
assert len(self.oc) > 1, 'Should larger than 1'
self.set_conf()
self.op_type = 'fusion_repeated_fc_relu'
sz = len(self.oc)
ics = [self.ic] + self.oc[0:sz - 1]
assert len(ics) == len(self.oc)
weights = []
biases = []
outs = []
i = 0
matrix = MatrixGenerate(self.bs, ics[i], self.oc[i], 1, 1)
inp = np.reshape(matrix.input, [self.bs, ics[i]])
weights.append(('W_{0}'.format(i), np.reshape(matrix.weights,
[ics[i], self.oc[i]])))
biases.append(('B_{0}'.format(i), matrix.bias))
outs.append(
np.reshape(
np.maximum(fc_refer(matrix, True), 0), [self.bs, self.oc[i]]))
for i in range(sz - 1):
matrix = MatrixGenerate(self.bs, ics[i + 1], self.oc[i + 1], 1, 1)
matrix.input = np.reshape(outs[i], [self.bs, ics[i + 1], 1, 1])
out = fc_refer(matrix, True)
weights.append(
('W_{0}'.format(i + 1),
np.reshape(matrix.weights, [ics[i + 1], self.oc[i + 1]])))
biases.append(('B_{0}'.format(i + 1), matrix.bias))
outs.append(
np.reshape(np.maximum(out, 0), [self.bs, self.oc[i + 1]]))
relu_outs = []
for i in range(sz - 1):
relu_outs.append(('ReluOut_{0}'.format(i), outs[i]))
self.inputs = {
'X': inp,
'W': weights,
'Bias': biases,
}
self.outputs = {'Out': outs[-1], 'ReluOut': relu_outs}
def test_check_output(self):
self.check_output()
def set_conf(self):
pass
class TestFusionRepeatedFCReluOpBS1(TestFusionRepeatedFCReluOp):
def set_conf(self):
self.bs = 1
self.oc = [4, 2, 7, 5]
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册