Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a neural network architecture be visualized with Keras?

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.

like image 621
Martin Thoma Avatar asked Jul 18 '16 16:07

Martin Thoma


People also ask

How do I visualize a neural network in Keras?

Visualizing a Neural Network using Keras Library It can be a great way to visualize the model architecture and share it with your audience while presenting. The Keras library allows for visualization of the neural networks using the plot_model command.

How do you visualize a neural network?

ANN Visualizer is a python library that enables us to visualize an Artificial Neural Network using just a single line of code. It is used to work with Keras and makes use of python's graphviz library to create a neat and presentable graph of the neural network you're building.

How do I show model in Keras?

Visualize ModelThe 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.


1 Answers

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.

like image 137
sietschie Avatar answered Sep 22 '22 17:09

sietschie