问题
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.
- Change the Colab runtime to None and this import will work fine.
- 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