Incubator-mxnet: How to save graph.viz in mxnet

Created on 23 Jun 2017  路  7Comments  路  Source: apache/incubator-mxnet

Hi, I want to save the graph visualization of the model in R.
I tried
graph.viz(symbol). it is able to show a network structure in my rstudio panel. But I can only save it as a webpage. However, this webpage cannot be opened in Firefox or Chrome. What are some ways to visualize network and save it when using R?
Thanks.

R

Most helpful comment

require(visNetwork)
g<-graph.viz(model$symbol,type='vis')
visSave(g, 'network.html' , selfcontained = TRUE)

This is the closest thing to save the network. If you have a better solution please let me know.

All 7 comments

@lichen11 The graph.viz is using DiagrammeR to visualize the network, you can find how to save the figure from http://rich-iannone.github.io/DiagrammeR/io.html

Please also see #775

Looks like that exporting is not supported yet by export_graph. See https://github.com/rich-iannone/DiagrammeR/issues/207 and code snippet:

library(DiagrammeR)
g<-graph.viz(model$symbol)
export_graph(g,file_name = "pic.png",file_type = "png")

Error in export_graph(g, file_name = "pic.png", file_type = "png") :
The graph object is not valid.

require(visNetwork)
g<-graph.viz(model$symbol,type='vis')
visSave(g, 'network.html' , selfcontained = TRUE)

This is the closest thing to save the network. If you have a better solution please let me know.

@kimtang @lichen11 Maybe you can try the code below:

library(mxnet)

data <- mx.symbol.Variable("data")
fc1 <- mx.symbol.FullyConnected(data, name="fc1", num_hidden=128)
act1 <- mx.symbol.Activation(fc1, name="relu1", act_type="relu")
fc2 <- mx.symbol.FullyConnected(act1, name="fc2", num_hidden=64)
act2 <- mx.symbol.Activation(fc2, name="relu2", act_type="relu")
fc3 <- mx.symbol.FullyConnected(act2, name="fc3", num_hidden=10)
softmax <- mx.symbol.SoftmaxOutput(fc3, name="sm")

library(DiagrammeRsvg)

res <- export_svg(graph.viz(softmax))
res <- charToRaw(res)
library(rsvg)
res <- rsvg(res, height = 5000)
library(png)
writePNG(res, "test.png")

Thank you very much! One follow-up question: are we able to save the network structure as a horizontal figure? I tried res <- rsvg(t(res), width = 5000), but didn't work.

@lichen11 after res <- rsvg(res, height = 5000), res is just a 3d array. The 3rd dim is the RGB value.

You can just rotate it and write it into a png file.

Was this page helpful?
0 / 5 - 0 ratings