test_set_bool_attr.py 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#   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.

15

16 17
import unittest

18
import paddle
19 20
import paddle.fluid as fluid

21 22 23

class TestAttrSet(unittest.TestCase):
    def test_set_bool_attr(self):
G
GGBond8488 已提交
24 25 26
        x = paddle.static.data(
            name='x', shape=[-1, 3, 7, 3, 7], dtype='float32'
        )
27 28
        param_attr = fluid.ParamAttr(
            name='batch_norm_w',
29 30
            initializer=fluid.initializer.Constant(value=1.0),
        )
31 32
        bias_attr = fluid.ParamAttr(
            name='batch_norm_b',
33 34
            initializer=fluid.initializer.Constant(value=0.0),
        )
35
        bn = paddle.static.nn.batch_norm(
36 37
            input=x, param_attr=param_attr, bias_attr=bias_attr
        )
38 39 40 41 42 43 44 45 46 47
        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()