Search code examples
mxnet

How to store MXNet graph visualization as image in a file?


According to this page, MXNet computation graph can be visualized using mx.viz.plot_network(net).

But that only works on Jupyter notebook. How do I do it without Jupyter notebook? Is it possible to save the visualization as a image in a file?


Solution

  • mx.viz.plot_network returns a graphviz.dot.Digraph object and it can be rendered to file like any other Digraph object.

    Here is an example:

    # Store the Digraph in a variable
    graph = mx.viz.plot_network(net)
    
    # Pick an image format from this list: http://www.graphviz.org/doc/info/output.html
    graph.format = 'png'
    
    # Choose a filename and render the image.
    graph.render('graph')
    

    Above code will render the graph in 'graph.png' in the current directory.