Netron Evaluation

Checking out a network visualizer
Published

January 8, 2021

Netron is a visualizer for neural networks that supports many different formats. It can run from the configuration or saved models and produces flow chart visualisation of the networks.

I am going to see how easy it is to use to understand a model that I do know as well as a model that I do not. The images that it produces are quite large so I expect this to be an image heavy post.

Code
from pathlib import Path
import netron

ROBERTA_LARGE = (
    Path.home() / ".cache" / "huggingface" / "transformers" /
    "e16a2590deb9e6d73711d6e05bf27d832fa8c1162d807222e043ca650a556964.fc9576039592f026ad76a1c231b89aee8668488c671dfbe6616bab2ed298d730"
)

netron.start(
    file=str(ROBERTA_LARGE),
    browse=False,
    host='dl.matthew.lan'
)
Serving '/home/matthew/.cache/huggingface/transformers/e16a2590deb9e6d73711d6e05bf27d832fa8c1162d807222e043ca650a556964.fc9576039592f026ad76a1c231b89aee8668488c671dfbe6616bab2ed298d730' at http://dl.matthew.lan:8080
Code
netron.start?
Signature:
netron.start(
    file=None,
    log=False,
    browse=True,
    port=8080,
    host='localhost',
)
Docstring:
Start serving model file at host:port and open in web browser
Args:
    file (string): Model file to serve.
    log (bool, optional): Log details to console. Default: False
    browse (bool, optional): Launch web browser, Default: True
    port (int, optional): Port to serve. Default: 8080
    host (string, optional): Host to serve. Default: ''
File:      ~/.cache/pypoetry/virtualenvs/blog-HrtMnrOS-py3.8/lib/python3.8/site-packages/netron/server.py
Type:      function
Code
netron.stop(host="dl.matthew.lan")

Stopping http://dl.matthew.lan:8080

So not a great start. I can’t extract the images from it easily - it really really wants to launch a browser. It also doesn’t immediately visualise the file I provided. The huggingface transformer format does not load apparently.

Code
RESNET18 = (
    Path.home() / ".cache" / "torch" / "hub" / "checkpoints" / "resnet18-5c106cde.pth"
)

netron.start(
    file=str(ROBERTA_LARGE),
    browse=False,
    host='dl.matthew.lan'
)

Stopping http://dl.matthew.lan:8080
Serving '/home/matthew/.cache/huggingface/transformers/e16a2590deb9e6d73711d6e05bf27d832fa8c1162d807222e043ca650a556964.fc9576039592f026ad76a1c231b89aee8668488c671dfbe6616bab2ed298d730' at http://dl.matthew.lan:8080

I’ve exported the resnet18 onnx model to PNG and SVG, so lets see how they look.

resnet 18 png

They both look much the same except the PNG renders slightly nicer.

It would be great if it was possible to perform this export in pure python. I think that the project is entirely oriented around being a webserver so that is not really on the cards.


So I wanted to visualize the CLIP model from Open AI but unfortunately the tool does not support that yet. I get the error:

Error loading PyTorch model. Unsupported function ‘torch.arange’ in ‘ViT-B-32.pt’.

I’ve reported this to the project.

I’ve also tried loading some of the transformer models however they also fail. At this point I’m going to stop this evaluation.

It’s a promising tool and I want to check it out again in future.