Hi!
I have a problem with plot_model, which does not show my input layer on the plot.
Here is the code:
`from keras import models
from keras import layers
from keras.utils import plot_model
neural_network = models.Sequential()
neural_network.add(layers.Dense(units = 20,input_shape = (10,), activation = 'relu'))
neural_network.add(layers.Dense(units = 20, activation = 'sigmoid'))
neural_network.compile(loss = 'categorical_crossentropy', optimizer = 'sgd', metrics = ["accuracy"])
plot_model(neural_network, show_shapes=True, show_layer_names=True, to_file="neural_network.png")`
And it gives something like this:

I found it's caused by omitting the first layer in Sequential in a637960fab61b66848a36e6a5caf0204c155af01
You can plot the model without using Sequential or remove the following lines in keras/engine/sequential.py
@property
def layers(self):
# Historically, `sequential.layers` only returns layers that were added
# via `add`, and omits the auto-generated `InputLayer`
# that comes at the bottom of the stack.
if self._layers and isinstance(self._layers[0], InputLayer):
return self._layers[1:]
return self._layers
Thank you.
This may not be closed as this issue still exist. I only offered a temp solution. I'm not sure what's the historical reason we have to omits the InputLayer in the Sequential model.
I still have this issue.
(base) C:WINDOWSsystem32>python -c "import keras; print(keras.__version__)"
Using TensorFlow backend.
2.2.2
Edit:
Tested with 2.2.3, still same error.
I have this same issue.
Same issue
Same issue in tensorflow.keras. This also goes away if you use the functional API.
I submitted https://github.com/tensorflow/tensorflow/pull/24637 to fix this issue in tf.keras. Apparently it is already fixed in keras-team/keras. It's a trivial change (just one character added):
In the definition of model_to_dot() (in [tensorflow/python/]keras/utils/vis_utils.py), replace layers = model.layers with layers = model._layers.
Hi, I am still very confused about getting this problem fixed! I am using keras = 2.2.4 on windows 10 Please, how do I define the input layer in the keras model to be visible in my plot_model function?
I would be so glad if someone helps.
Many thanks!
Alex
In the definition of model_to_dot() (in [tensorflow/python/]keras/utils/vis_utils.py), replace layers = model.layers with layers = model._layers
does not work for me
I solved the issue by upgrading to Keras 2.3.1
Most helpful comment
I found it's caused by omitting the first layer in Sequential in a637960fab61b66848a36e6a5caf0204c155af01
You can plot the model without using Sequential or remove the following lines in
keras/engine/sequential.py