87
$\begingroup$

When writing a paper / making a presentation about a topic which is about neural networks, one usually visualizes the networks architecture.

What are good / simple ways to visualize common architectures automatically?

$\endgroup$

15 Answers 15

30
$\begingroup$

I recently created a tool for drawing NN architectures and exporting SVG, called NN-SVG

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Download SVG doesn't work $\endgroup$ – image Jan 23 at 16:13
  • $\begingroup$ works for me 1/23/19. If you're still having an issue, please feel free to open an issue. $\endgroup$ – Alex Lenail Jan 23 at 23:28
  • 1
    $\begingroup$ this is the only right answer $\endgroup$ – ArtificiallyIntelligence Feb 23 at 15:52
  • $\begingroup$ awesome tool. However, I noticed that in AlexNet style, the dimensions of the Tensors were mistakenly represented (width and height dimensions) $\endgroup$ – FlySoFast Apr 29 at 16:01
26
$\begingroup$

Tensorflow, Keras, MXNet, PyTorch

If the neural network is given as a Tensorflow graph, then you can visualize this graph with TensorBoard.

Here is how the MNIST CNN looks like:

enter image description here

You can add names / scopes (like "dropout", "softmax", "fc1", "conv1", "conv2") yourself.

Interpretation

The following is only about the left graph. I ignore the 4 small graphs on the right half.

Each box is a layer with parameters that can be learned. For inference, information flows from bottom to the top. Ellipses are layers which do not contain learned parameters.

The color of the boxes does not have a meaning.

I'm not sure of the value of the dashed small boxes ("gradients", "Adam", "save").

$\endgroup$
  • $\begingroup$ it is good, I am trying to avoid the name like conv1, conv2 etc, I want to make all the name of conv later as CONV, How I will do?? $\endgroup$ – Sudip Das Mar 26 '18 at 13:03
  • $\begingroup$ +1. It's not only for TF though: MXNet and Pytorch have some support too $\endgroup$ – Jakub Bartczuk Jul 3 '18 at 16:08
  • $\begingroup$ @SudipDas You can add names in the code to the layers, which will show up as you plot it. $\endgroup$ – Ben Nov 27 '18 at 16:16
  • $\begingroup$ How I will show the name of each layer as "CONV", if I write it as "CONV" of each layer then I will get error, cause each layer should have a unique name as tf rules, BUT I want to know, is there any other way to overcome this problem?? @Ben $\endgroup$ – Sudip Das Nov 27 '18 at 16:22
  • 1
    $\begingroup$ @onof I fixed the link $\endgroup$ – Martin Thoma Sep 23 at 8:55
17
$\begingroup$

In Caffe you can use caffe/draw.py to draw the NetParameter protobuffer:

enter image description here

In Matlab, you can use view(net)

enter image description here

Keras.js:

enter image description here

$\endgroup$
12
$\begingroup$

There is an open source project called Netron

Netron is a viewer for neural network, deep learning and machine learning models.

Netron supports ONNX (.onnx, .pb), Keras (.h5, .keras), CoreML (.mlmodel) and TensorFlow Lite (.tflite). Netron has experimental support for Caffe (.caffemodel), Caffe2 (predict_net.pb), MXNet (-symbol.json), TensorFlow.js (model.json, .pb) and TensorFlow (.pb, .meta).

enter image description here

$\endgroup$
11
$\begingroup$

I would add ASCII visualizations using keras-sequential-ascii (disclaimer: I am the author).

A small network for CIFAR-10 (from this tutorial) would be:

       OPERATION           DATA DIMENSIONS   WEIGHTS(N)   WEIGHTS(%)

           Input   #####     32   32    3
          Conv2D    \|/  -------------------       896     2.1%
            relu   #####     30   30   32
    MaxPooling2D   Y max -------------------         0     0.0%
                   #####     15   15   32
          Conv2D    \|/  -------------------     18496    43.6%
            relu   #####     13   13   64
    MaxPooling2D   Y max -------------------         0     0.0%
                   #####      6    6   64
         Flatten   ||||| -------------------         0     0.0%
                   #####        2304
           Dense   XXXXX -------------------     23050    54.3%
         softmax   #####          10

For VGG16 it would be:

       OPERATION           DATA DIMENSIONS   WEIGHTS(N)   WEIGHTS(%)

          Input   #####      3  224  224
     InputLayer     |   -------------------         0     0.0%
                  #####      3  224  224
  Convolution2D    \|/  -------------------      1792     0.0%
           relu   #####     64  224  224
  Convolution2D    \|/  -------------------     36928     0.0%
           relu   #####     64  224  224
   MaxPooling2D   Y max -------------------         0     0.0%
                  #####     64  112  112
  Convolution2D    \|/  -------------------     73856     0.1%
           relu   #####    128  112  112
  Convolution2D    \|/  -------------------    147584     0.1%
           relu   #####    128  112  112
   MaxPooling2D   Y max -------------------         0     0.0%
                  #####    128   56   56
  Convolution2D    \|/  -------------------    295168     0.2%
           relu   #####    256   56   56
  Convolution2D    \|/  -------------------    590080     0.4%
           relu   #####    256   56   56
  Convolution2D    \|/  -------------------    590080     0.4%
           relu   #####    256   56   56
   MaxPooling2D   Y max -------------------         0     0.0%
                  #####    256   28   28
  Convolution2D    \|/  -------------------   1180160     0.9%
           relu   #####    512   28   28
  Convolution2D    \|/  -------------------   2359808     1.7%
           relu   #####    512   28   28
  Convolution2D    \|/  -------------------   2359808     1.7%
           relu   #####    512   28   28
   MaxPooling2D   Y max -------------------         0     0.0%
                  #####    512   14   14
  Convolution2D    \|/  -------------------   2359808     1.7%
           relu   #####    512   14   14
  Convolution2D    \|/  -------------------   2359808     1.7%
           relu   #####    512   14   14
  Convolution2D    \|/  -------------------   2359808     1.7%
           relu   #####    512   14   14
   MaxPooling2D   Y max -------------------         0     0.0%
                  #####    512    7    7
        Flatten   ||||| -------------------         0     0.0%
                  #####       25088
          Dense   XXXXX ------------------- 102764544    74.3%
           relu   #####        4096
          Dense   XXXXX -------------------  16781312    12.1%
           relu   #####        4096
          Dense   XXXXX -------------------   4097000     3.0%
        softmax   #####        1000
$\endgroup$
10
$\begingroup$

Here is yet another way - dotnets, using Graphviz, heavily inspired by this post by Thiago G. Martins.

dotnets example

$\endgroup$
8
$\begingroup$

Keras

The keras.utils.vis_utils module provides utility functions to plot a Keras model (using graphviz)

The following shows a network model that the first hidden layer has 50 neurons and expects 104 input variables.

plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True)

enter image description here

$\endgroup$
  • $\begingroup$ Can I use it in LaTex compatible format? $\endgroup$ – xxx--- Jul 11 at 0:01
8
$\begingroup$

The Python package conx can visualize networks with activations with the function net.picture() to produce SVG, PNG, or PIL Images like this:

enter image description here

Conx is built on Keras, and can read in Keras' models. The colormap at each bank can be changed, and it can show all bank types.

More information can be found at: http://conx.readthedocs.io/en/latest/

$\endgroup$
6
$\begingroup$

I've been working on a drag-and-drop neural network visualizer (and more). Here's an example of a visualization for a LeNet-like architecture. A visualization of a LeNet-like architecture Models with fan-out and fan-in are also quite easily modeled. You can visit the website at https://math.mit.edu/ennui/

$\endgroup$
  • $\begingroup$ my browser keeps crashing when press Train $\endgroup$ – datdinhquoc Sep 25 at 4:25
  • 1
    $\begingroup$ Thanks for checking it out. Yes, this bug just popped up recently and seems to be a result of some recent changes to WebGL on Chrome. Everything should work on Firefox. I'll update you when I know more. $\endgroup$ – Jesse Sep 25 at 20:19
  • $\begingroup$ tks, your visualiser is amazing, looks greater than tf playground :) $\endgroup$ – datdinhquoc Sep 26 at 1:50
  • 1
    $\begingroup$ Thank you! Let me know if you have issues or ideas. We have fun things like code generation too! $\endgroup$ – Jesse Sep 26 at 16:01
5
$\begingroup$

In R, nnet does not come with a plot function, but code for that is provided here.

Alternatively, you can use the more recent and IMHO better package called neuralnet which features a plot.neuralnet function, so you can just do:

data(infert, package="datasets")
plot(neuralnet(case~parity+induced+spontaneous, infert))

neuralnet

neuralnet is not used as much as nnet because nnet is much older and is shipped with r-cran. But neuralnet has more training algorithms, including resilient backpropagation which is lacking even in packages like Tensorflow, and is much more robust to hyperparameter choices, and has more features overall.

$\endgroup$
4
$\begingroup$

There are some novel alternative efforts on neural network visualization.

Please see these articles:

Stunning 'AI brain scans' reveal what machines see as they learn new skills

Inside an AI 'brain' - What does machine learning look like?

These approaches are more oriented towards visualizing neural network operation, however, NN architecture is also somewhat visible on the resulting diagrams.

Examples:

enter image description here

enter image description here

enter image description here

enter image description here

$\endgroup$
  • 22
    $\begingroup$ Please explain what we see here. It looks beautiful, but I don't understand how the fancy images support understanding the operation of the network. $\endgroup$ – Martin Thoma Mar 27 '18 at 17:15
  • $\begingroup$ I don't like your derogatory usage of "fancy images" term. @Martin $\endgroup$ – VividD Mar 27 '18 at 17:25
  • 9
    $\begingroup$ I didn't mean to attack you, but your overly defensive answer without actually answering my question speaks for itself. - I added an "interpretation" part to the "lego boxes" diagram. $\endgroup$ – Martin Thoma Mar 28 '18 at 7:29
  • 1
    $\begingroup$ By the way: The second link is dead. $\endgroup$ – Martin Thoma Mar 28 '18 at 7:37
  • 4
    $\begingroup$ @MartinThoma It's clearly data art, not data viz (vide lisacharlotterost.github.io/2015/12/19/…). $\endgroup$ – Piotr Migdal Apr 2 '18 at 14:04
3
$\begingroup$

Not per se nifty for papers, but very useful for showing people who don't know a lot of about neural networks what their topology may look like. This Javascript library (Neataptic) lets you visualise your network:

enter image description here

$\endgroup$
3
$\begingroup$

You can read the popular paper Understanding Neural Networks Through Deep Visualization which discusses visualization of convolutional nets. Its implementation not only displays each layer but also depicts the activations, weights, deconvolutions and many other things that are deeply discussed in the paper. It's code is in caffe'. The interesting part is that you can replace the pre-trained model with your own.

$\endgroup$
3
$\begingroup$

Tensorspace-JS is a fantastic tool for 3d visualization of network architecture:

enter image description here

https://tensorspace.org/

and here is a nice post about how to write a program:

https://medium.freecodecamp.org/tensorspace-js-a-way-to-3d-visualize-neural-networks-in-browsers-2c0afd7648a8

$\endgroup$
  • $\begingroup$ Could you provide a link to this tool? $\endgroup$ – Piotr Migdal Jan 25 at 14:34
  • 1
    $\begingroup$ @PiotrMigdal I updated the answer. $\endgroup$ – Ali Mirzaei Jan 26 at 14:43
1
$\begingroup$

Netscope is my everyday tool for Caffe models.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.