Reputation: 17617
I am using pybrain to build neural network. Sometimes a graphical representation of the situation would be very useful.
Is it possible to plot the structure of a neural network generated using pybrain?
Upvotes: 3
Views: 1065
Reputation: 3787
As was already mentioned, this answer How to visualize a neural network shows how to plot simple networks using pyplot.
Here is how to adapt this solution for PyBrain:
class PybrainNNVisualizer():
def __init__(self, neural_network):
"""
:type neural_network: Network
"""
self.neural_network = neural_network
def draw(self):
widest_layer = max([layer.dim for layer in self.neural_network.modules])
network = NeuralNetwork(widest_layer)
for layer in self.neural_network.modulesSorted:
if type(layer) is BiasUnit:
continue
network.add_layer(layer.dim)
network.draw()
Usage:
fnn = buildNetwork(4, 8, 1)
PybrainNNVisualizer(fnn).draw()
Full source code: https://github.com/AlexP11223/SimplePyBrainNeuralNeutwork/blob/master/nnvisualizer.py
Upvotes: 0
Reputation: 11
I think the original questioner was probably looking for something like this (as I am, though without the animation): http://www.codeproject.com/KB/dotnet/predictor/learn.gif
And I think this is more or less answered in this post: How to visualize a neural network
"More or less" because it would be nice to see the cell reference (A0, A1, A2, B0, etc, or whatever) inside each circle.
But I'm a total beginner in Python and in neural networks, feel free to correct me if I'm wrong.
Upvotes: 1