Netron: A Visualizer for Machine Learning and Deep Learning Models

Netra Prasad Neupane
3 min readJun 12, 2023

--

While working in Machine Learning, we sometimes perform tests on pre-trained models trained by someone else. Occasionally, we only need to find the model's architecture for research purposes. But, to visualize model architecture we need to set up the framework the model is trained on. It becomes tedious to create different environments and set up the framework for each model we want to visualize. As AI researchers, we want to visualize architectures without setting up the whole framework.

fig: An architecture of Convolutional Neural Network

To address the above problem, There is an open-source library called Netron. Netron is a viewer for neural networks, deep learning and machine learning models. Netron supports ONNX, TensorFlow Lite, Caffe, Keras, Darknet, PaddlePaddle, ncnn, MNN, Core ML, RKNN, MXNet, MindSpore Lite, TNN, Barracuda, Tengine, CNTK, TensorFlow.js, Caffe2 and UFF.

We can install Netron in our own system, or use the online version available on https://netron.app/. Here I will explain, how you can install Netron in your system and visualize your machine-learning model.

Let’s start to set up Netron on our system. Install Netron in your environment using pip package manager.

pip install netron

Now, create a Python file named visualize_models.py. For demo purposes, Here I am using image_filter_cnn_3_3.h5, a simple Deep Learning model trained on Convolutional Neural Network(CNN).

import netron
netron.start("image_filter_cnn_3_3.h5")

Now, run visualize_models.py, it will start the localhost server in your default web browser at port 8080 i.e. http://localhost:8080. You will see a similar interface as the following.

In the left menu, you will get different options such as export as an image, zoom in and zoom out, show horizontal, show attributes etc. Try out the above options yourself that might be useful to you. Here, I have exported my model architecture as PNG. See, the architecture of the above model more clearly below.

From the above architecture, we clearly see the different layers and sizes of kernel used in each layer. The size of an input image is 64*64*3 in the above architecture. And input layer is followed by the number of convolutional layers, the activation layer, normalization, pooling and finally dense layer.

I hope that the above blog is helpful to visualize and understand the architecture of the ML/DL models more easily. If it is helpful to you, then please don’t forget to clap and share it with your friends. See you in the next blog…

References:

--

--

Netra Prasad Neupane

Machine Learning Engineer with expertise in Computer Vision, Deep Learning, NLP and Generative AI. https://www.linkedin.com/in/netraneupane/