【发布时间】:2021-05-26 02:13:44
【问题描述】:
我正在尝试在 tensorflow 2.4.1 中实现 PReLU 激活,如此处How to implement PReLU activation in Tensorflow?
出现以下错误
ValueError: Variable alpha already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
这是我的代码
def prelu(_x):
alphas = tf.compat.v1.get_variable('alpha', _x.get_shape()[-1],
initializer=tf.constant_initializer(0.0), dtype=tf.float32)
pos = tf.nn.relu(_x)
neg = alphas * (_x - abs(_x)) * 0.5
return pos + neg
感谢任何帮助。
注意:
我不想使用层接口 tf.keras.layers.PReLU,因为它不能作为参数传递给 conv2D,如下所示
Conv2D(filters, (3, 3), padding='same', activation='prelu')
【问题讨论】:
-
代码是为 TF1 编写的,我尝试将其迁移到 TF2 并出现上述错误?
标签: tensorflow keras deep-learning activation-function