Visualize Neural Network Model using Netron

Netron is an open-source tool which allows to visualize neural network, deep learning and machine learning models. Netron allows to analyze model structure and ensure it matches your expected design. It supports a variety of frameworks and model formats.

Netron is a cross-platform tool which can be installed as Desktop application. It can be downloaded from releases page of the lutzroeder/netron repository. Choose the installer depending on your operating system (.exe for Windows , .dmg for macOS, .AppImage for Linux).

Also Netron can visualize models in the browser. In this tutorial we will show how you can install Netron as a Python server. We will create a model with Keras and TensorFlow 2.

Using pip package manager install tensorflow and netron from the command line.

pip install tensorflow
pip install netron

We created a simple model which consists of a sequence of one Flatten layer and two Dense layers. We saved model in HDF5 format (.h5 extension). We start a server by using netron.start() function.

from tensorflow import keras
import netron

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10, activation='softmax')
])

model.save('model.h5')

netron.start('model.h5')

Then it will open the browser with visualized model. By default, a model is served at http://localhost:8080.

Netron Browser Version

It’s also possible to generate SVG or PNG images of the models.

Export Model as SVG or PNG Image

Leave a Comment

Your email address will not be published. Required fields are marked *