模块对象没有属性relu

时间:2018-02-22 13:50:25

标签: python keras

我正在尝试运行来自here的代码,这是使用keras python的Generative Adversarial Networks的实现。我按照说明安装了所有要求。然后我尝试运行DCGAN的代码。但是,似乎存在库的兼容性问题。我在运行代码时收到以下消息:

  

AttributeError:' module'对象没有属性' leaky_relu'

File "main.py", line 176, in <module>
dcgan = DCGAN()
File "main.py", line 25, in __init__
self.discriminator = self.build_discriminator()
File "main.py", line 84, in build_discriminator
model.add(LeakyReLU(alpha=0.2))
File "/opt/libraries/anaconda2/lib/python2.7/site-packages/keras/models.py", line 492, in add
output_tensor = layer(self.outputs[0])
File "/opt/libraries/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 617, in __call__
output = self.call(inputs, **kwargs)
File "/opt/libraries/anaconda2/lib/python2.7/site-packages/keras/layers/advanced_activations.py", line 46, in call
return K.relu(inputs, alpha=self.alpha)
File "/opt/libraries/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2918, in relu
x = tf.nn.leaky_relu(x, alpha)

我在使用keras Version: 2.1.3而张量流Version: 1.2.1 和Theano Version: 1.0.1+40.g757b4d5

我知道为什么会收到这个问题?

修改

错误位于build_discriminator中的第84行:

function:`model.add(LeakyReLU(alpha=0.2))`

1 个答案:

答案 0 :(得分:3)

根据this answerleaky_relu已添加到版本1.4的tensorflow。所以你可能想检查你的tensorflow安装是否至少是1.4版本。