test_set_bool_attr.py 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#   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.

import paddle.fluid as fluid
import unittest


class TestAttrSet(unittest.TestCase):
    def test_set_bool_attr(self):
        x = fluid.layers.data(name='x', shape=[3, 7, 3, 7], dtype='float32')
        param_attr = fluid.ParamAttr(
            name='batch_norm_w',
            initializer=fluid.initializer.Constant(value=1.0))
        bias_attr = fluid.ParamAttr(
            name='batch_norm_b',
            initializer=fluid.initializer.Constant(value=0.0))
        bn = fluid.layers.batch_norm(
            input=x, param_attr=param_attr, bias_attr=bias_attr)
        block = fluid.default_main_program().desc.block(0)
        op = block.op(0)
        before_type = op.attr_type('is_test')
        op._set_attr('is_test', True)
        after_type = op.attr_type('is_test')
        self.assertEqual(before_type, after_type)


if __name__ == '__main__':
    unittest.main()