Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why plot_model in Keras does not plot the model correctly?

I want to visualize my neural net. Therefore, I use from tensorflow.keras.utils import plot_model and use it like this:

    model = Sequential()
    model.add(Dense(8, activation="relu"))
    model.add(Dense(1))
    plot_model(model, to_file="model.png", show_shapes=True)

But, when I open the graphic, it looks like this:

enter image description here

What is wrong with my code? I do not see any error.

like image 456
toom Avatar asked Apr 15 '20 11:04

toom


1 Answers

The reason is that the model has not been built because it does not know its input shape. Either specify the input shape of the model on the first layer using input_shape (or input_dim) argument, or alternatively start fitting the model on some data by calling fit method (so the input shape could be automatically inferred). Also, as mentioned by @xdurch0 in the comments section, another option is to call build method of the model and pass it the input shape as argument.

like image 56
today Avatar answered Oct 07 '22 07:10

today