AttributeError: module 'keras.engine' has no attribute 'input_layer'

落花浮王杯 提交于 2019-12-13 03:53:11

问题


I am trying to use google colab!

But I keep running into the problem with keras where it says: AttributeError: module 'keras.engine' has no attribute 'input_layer'

However, checking their github library, there is a input_layer.py within keras/engine.

Also, this works locally, just not on google colab.

Any ideas?


回答1:


The above import works on your local device because you are not using any hardware accelerator (GPU) on your local device. I do not know the reason as to why this import does not work on GPU runtimes. Here are two workarounds for this.

  1. Change the Colab runtime to None and this import will work fine.
  2. I looked at the code of input_layer and found that it has a Input (function) and InputLayer (class). So, If you do not want to change the runtime, you need to refactor things.

Remove

from keras.engine import input_layer.InputLayer
from keras.engine import input_layer.Input

to

from keras.layers import InputLayer, Input

I wish both do the same thing




回答2:


I have the same problem with google colab. The error I am getting is:

module 'tensorflow._api.v1.keras' has no attribute 'engine'.

Here is my code:

 import tensorflow as tf
 from tensorflow import keras
 from keras import backend as K

 def reinitLayers(model):
     session = K.get_session()
     for layer in model.layers: 
         if isinstance(layer,keras.engine.network.Network):
             reinitLayers(layer)
....

However there exist keras.engine: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python/keras/engine



来源:https://stackoverflow.com/questions/51186448/attributeerror-module-keras-engine-has-no-attribute-input-layer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!