Viewers
SimpleGraph
- class nnabla.experimental.viewers.SimpleGraph(format='png', verbose=False, fname_color_map=None, vname_color_map=None)[source]
Simple Graph with GraphViz.
Example:
import nnabla as nn import nnabla.functions as F import nnabla.parametric_functions as PF import nnabla.experimental.viewers as V # Model definition def network(image, test=False): h = image h /= 255.0 h = PF.convolution(h, 16, kernel=(3, 3), pad=(1, 1), name="conv") h = PF.batch_normalization(h, name="bn", batch_stat=not test) h = F.relu(h) pred = PF.affine(h, 10, name='fc') return pred # Model image = nn.Variable([4, 3, 32, 32]) pred = network(image, test=False) # Graph Viewer graph = V.SimpleGraph(verbose=False) graph.view(pred) graph.save(pred, "sample_grpah")
If the parameters are module-scoped, for example, the
pred
comes from a module output, parameters should be obtained beforehand then passed to view():Example:
import nnabla as nn import nnabla.functions as F from nnabla.core.modules import ConvBn import nnabla.experimental.viewers as V class TSTNetNormal(nn.Module): def __init__(self): self.conv_bn_1 = ConvBn(1) self.conv_bn_2 = ConvBn(1) def call(self, x1, x2): y1 = self.conv_bn_1(x1) y2 = self.conv_bn_2(x2) y = F.concatenate(y1, y2, axis=1) return y tnd = TSTNetNormal() v1 = nn.Variable((4, 3, 32, 32)) v2 = nn.Variable((4, 3, 32, 32)) ya = tnd(v1, v2) graph = V.SimpleGraph(verbose=False) graph.view(ya, params=tnd.get_parameters(grad_only=False))
- create_graphviz_digraph(vleaf, params=None, format=None)[source]
Create a
graphviz.Digraph
object given the leaf variable of a computation graph.One of nice things of getting
Digraph
directly is that the drawn graph can be displayed inline in a Jupyter notebook as described in Graphviz documentation.- Parameters:
vleaf (
nnabla.Variable
) – End variable. All variables and functions which can be traversed from this variable are shown in the reuslt.params (dict) – The parameters dictionary, it can be obtained by nn.get_parameters().
format (str) – Force overwrite
format
('pdf', 'png', ...)
) configuration.
Returns: graphviz.Digraph
- save(vleaf, fpath, cleanup=False, format=None)[source]
Save the graph to a given file path.
- Parameters:
vleaf (
nnabla.Variable
) – End variable. All variables and functions which can be traversed from this variable are shown in the reuslt.fpath (
str
) – The file path used to save.cleanup (
bool
) – Clean up the source file after rendering. Default is False.format (str) – Force overwrite
format
('pdf', 'png', ...)
) configuration.
- view(vleaf, fpath=None, cleanup=True, format=None, params=None)[source]
View the graph.
- Parameters:
vleaf (
nnabla.Variable
) – End variable. All variables and functions which can be traversed from this variable are shown in the reuslt.fpath (
str
) – The file path used to save.cleanup (
bool
) – Clean up the source file after rendering. Default is True.format (str) – Force overwrite
format
('pdf', 'png', ...)
) configuration.params (dict) – Parameter dictionary, which can be obtained by get_parameters() function. Default is None. If params is None, global parameters are obtained.