Created by: songyouwei
dygraph.PRelu
Python API类型检查增强
当此动态图API在静态图下运行时:
检查input类型是否为Variable 检查数据类型是否为float32 异常情况示例如下:
import paddle.fluid as fluid
import numpy as np
layer = fluid.PRelu(
mode='all',
param_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(1.0)))
# the input must be Variable.
x0 = fluid.create_lod_tensor(
np.array([-1, 3, 5, 5]), [[1, 1, 1, 1]], fluid.CPUPlace())
layer(x0)
# TypeError: The type of 'input' in PRelu must be <class 'paddle.fluid.framework.Variable'>, but received <class 'paddle.fluid.core_avx.LoDTensor'>.
data_t = fluid.data(name="input", shape=[5, 200, 100, 100], dtype="float64")
layer(data_t)
# TypeError: The data type of 'input' in PRelu must be ['float32'], but received float64.