環境
Mac Mojave
Python3.7.3
https://keras.io/ja/visualization/
を参考にしたがエラーが発生してしまう。
Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work
Failed to import `pydot`. Please install `pydot`. For example with `pip install pydot'
Failed to import `pydot`. Please install `pydot`. For example with `pip install pydot'
kerasをインストールするだけでは恐らく足りない。
brew install graphviz
pip install pydot_ng
pip install pydot_ng
pip3 install pydot_ng
ではうまくかなかった。import keras
import pydot_ng as pydot
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
keras.utils.vis_utils.pydot = pydot
# model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(units=256, input_shape=(784,)))
model.add(Activation('relu'))
model.add(Dense(units=100))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy'])
#Visualize Model
SVG(model_to_dot(model).create(prog='dot', format='svg'))
https://github.com/ninomae-makoto/keras/blob/master/07_visualizedModel/cnn.ipynb
にサンプルソースをおいている。
参考
https://www.mathgram.xyz/entry/keras/graph
https://github.com/XifengGuo/CapsNet-Keras/issues/69