forked from yang-zhang/deep-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keras_plot_model.py
43 lines (23 loc) · 958 Bytes
/
keras_plot_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding: utf-8
# In[6]:
import keras
import IPython
model = keras.models.Sequential()
model.add(keras.layers.Dense(3, activation='relu', input_dim=3))
model.add(keras.layers.Dense(5, activation='relu'))
model.add(keras.layers.Dense(2, activation='softmax'))
# Option-1
# In[7]:
keras.utils.plot_model(model, to_file='test_keras_plot_model.png', show_shapes=True)
IPython.display.Image("test_keras_plot_model.png")
# Option-2
# In[11]:
IPython.display.SVG(keras.utils.vis_utils.model_to_dot(model).create(prog='dot', format='svg'))
# In[12]:
def plot_keras_model(model, show_shapes=True, show_layer_names=True):
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
return SVG(model_to_dot(model, show_shapes=show_shapes, show_layer_names=show_layer_names).create(prog='dot', format='svg'))
# In[13]:
plot_keras_model(model, show_shapes=True, show_layer_names=False)
# https://keras.io/visualization/