python2.7:Keras ReLU属性

2024-04-24 05:00:53 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用Keras时出现以下错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-10-9c662915c9d8> in <module>()
     22 
     23 # create an untrained neural network objects from the config file
---> 24 current_NN = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, (2,) + env.grid_shape,   env.action_size, config.HIDDEN_CNN_LAYERS)
     25 best_NN = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, (2,) +  env.grid_shape,   env.action_size, config.HIDDEN_CNN_LAYERS)
     26 

/home/ubuntu/workspace/model.py in __init__(self, reg_const, learning_rate, input_dim, output_dim, hidden_layers)
    112                 self.hidden_layers = hidden_layers
    113                 self.num_layers = len(hidden_layers)
--> 114                 self.model = self._build_model()
    115 
    116         def residual_layer(self, input_block, filters, kernel_size):

/home/ubuntu/workspace/model.py in _build_model(self)
    223                 main_input = Input(shape = self.input_dim, name = 'main_input')
    224 
--> 225                 x = self.conv_layer(main_input, self.hidden_layers[0]['filters'], self.hidden_layers[0]['kernel_size'])
    226 
    227                 if len(self.hidden_layers) > 1:

/home/ubuntu/workspace/model.py in conv_layer(self, x, filters, kernel_size)
    149 
    150                 x = BatchNormalization(axis=1)(x)
--> 151                 x = LeakyReLU()(x)
    152 
    153                 return (x)

/home/ubuntu/miniconda2/lib/python2.7/site-packages/keras/engine/topology.pyc in __call__(self, inputs, **kwargs)
    615 
    616             # Actually call the layer, collecting output(s), mask(s), and shape(s).
--> 617             output = self.call(inputs, **kwargs)
    618             output_mask = self.compute_mask(inputs, previous_mask)
    619 

/home/ubuntu/miniconda2/lib/python2.7/site-packages/keras/layers/advanced_activations.pyc in call(self, inputs)
     44 
     45     def call(self, inputs):
---> 46         return K.relu(inputs, alpha=self.alpha)
     47 
     48     def get_config(self):

/home/ubuntu/miniconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc in relu(x, alpha, max_value)
   2916     """
   2917     if alpha != 0.:
-> 2918         x = tf.nn.leaky_relu(x, alpha)
   2919     else:
   2920         x = tf.nn.relu(x)

AttributeError: 'module' object has no attribute 'leaky_relu'

我已经安装了Keras、Tensorflow和Theanos的所有最新版本,我使用的是python2.7版本。当我试图在Jupyter笔记本中运行代码时,会发生此错误。在


Tags: inselfalphaconfighomeinputsizemodel