Plotting an architecture of Tensorflow Keras model by plot_model()
To plot the architecture flow of Tensorflow Keras model by using plot_model() function, two packages should be installed: graphviz and pydot.
To install these packages, type the following commands in the anaconda prompt.
1 2 | pip install graphviz pip install pydot | cs |
In the Jupyter notebook, we can use plot_model() function to draw an architecture of the following Keras model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | from keras import layers, models from keras.utils.vis_utils import plot_model #1. Modeling model = models.Sequential() model.add(layers.Dense(128, activation='relu', input_shape=(256,), name='HiddenLayer01')) model.add(layers.Dense(64 , activation='relu', name='HiddenLayer02')) model.add(layers.Dense(32 , activation='relu', name='HiddenLayer03')) model.add(layers.Dense(1 , activation='softmax',name='OuputLayer')) model.compile(loss='categorical_crossentropy', optimizer = 'adam', metrics=['accuracy']) #2. Visualizing plot_model(model, show_shapes=True, to_file='model.png') | cs |
As expected, we can get the following visualization.
If you happen to encounter an error regarding the installation, one of possible solution is to use the following conda command in the anaconda prompt.
1 | conda install graphviz | cs |
No comments:
Post a Comment