How can a neural network architecture be visualized with Keras?

半腔热情 提交于 2020-02-19 14:56:53

问题


I tried the following:

#!/usr/bin/env python

import keras
from keras.models import model_from_yaml

model_file_path = 'model-301.yaml'
weights_file_path = 'model-301.hdf5'

# Load network
with open(model_file_path) as f:
    yaml_string = f.read()
model = model_from_yaml(yaml_string)
model.load_weights(weights_file_path)
model.compile(optimizer='adagrad', loss='binary_crossentropy')

# Visualize
from keras.utils.visualize_util import plot

However, this gives an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/moose/.local/lib/python2.7/site-packages/keras/utils/visualize_util.py", line 7, in <module>
    if not pydot.find_graphviz():
AttributeError: 'module' object has no attribute 'find_graphviz'

How can I fix this?

Note: The hdf5 and the YAML file can be found on Github.


回答1:


The problem is also referenced on the issues page of the keras project. You need to install a version of pydot <= 1.1.0 because the function find_graphviz was removed in version 1.2.0. Alternatively you could install pydot-ng instead, which is recommended by the keras developers.




回答2:


If you have not already installed pydot python package - try to install it. If you have pydot reinstallation should help with your problem.



来源:https://stackoverflow.com/questions/38442107/how-can-a-neural-network-architecture-be-visualized-with-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!