Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras: display model shape in Jupyter Notebook

I have the following code which I used to view my Network architecture.

enter image description here

However, I also want to see the shape of each layer, so I tried to use the following:

from keras.utils import plot_model
#plot_model(model, show_shapes=True, show_layer_names=True, to_file='model.png')
plot_model(model, show_shapes=True, show_layer_names=True)

The output file 'model.png' looks fine. But I am unable to make it display in the Jupyter Notebook. Any idea what I missed? Thanks!

like image 935
Edamame Avatar asked Aug 08 '19 18:08

Edamame


People also ask

How do you plot models in Jupyter Notebook?

IPython kernel of Jupyter notebook is able to display plots of code in input cells. It works seamlessly with matplotlib library. The inline option with the %matplotlib magic function renders the plot out cell even if show() function of plot object is not called.

How does keras define input shape?

Input Shape In A Keras Layer In a Keras layer, the input shape is generally the shape of the input data provided to the Keras model while training. The model cannot know the shape of the training data. The shape of other tensors(layers) is computed automatically.

How do you plot a model?

plot_model() is a generic plot-function, which accepts many model-objects, like lm , glm , lme , lmerMod etc. plot_model() allows to create various plot tyes, which can be defined via the type -argument. The default is type = "fe" , which means that fixed effects (model coefficients) are plotted.

How to set the input shape in keras model?

To use the dataset in our model, we need to set the input shape in the first layer of our Keras model using the parameter “ input_shape ” so that it matches the shape of the dataset. I hope that this tutorial helped you in understanding the Keras input shapes efficiently. Thank you.

What is the use of show_shapes in keras?

model: A Keras model instance to_file: File name of the plot image. show_shapes: whether to display shape information. show_dtype: whether to display layer dtypes. show_layer_names: whether to display layer names.

How to plot a network model in keras?

The plot_model () function in Keras will create a plot of your network. This function takes a few useful arguments: model: (required) The model that you wish to plot. to_file: (required) The name of the file to which to save the plot. show_shapes: (optional, defaults to False) Whether or not to show the output shapes of each layer.

What is the Keras functional API for deep learning?

The Keras functional API helps create models that are more flexible in comparison to models created using sequential API. The functional API can work with models that have non-linear topology, can share layers and work with multiple inputs and outputs. A deep learning model is usually a directed acyclic graph (DAG) that contains multiple layers.


1 Answers

since the resulting image is not a svg file anymore you should replace SVG with Image use

from IPython.display import Image 
... 

plot_model(model, show_shapes=True, show_layer_names=True, to_file='model.png')
Image('model.png')
like image 98
alexey Avatar answered Sep 22 '22 03:09

alexey