How to convert DOT graph to ASCII

The GraphViz DOT is a super-simple language that makes it very easy to create graphs and export them to various graphical formats. However, there are situations where you want to generate an ASCII graph. For example, to embed a flowchart or digraph in source code or documentation. GraphViz provides no exporter that can output an ASCII graph.

Thankfully, I found that this can be achieved using a Perl module called Graph::Easy. It can use GraphViz to understand your DOT file and then convert that to an elegant ASCII graph.

Here is how to use that:

  • We need to install the Graph::Easy module from CPAN. Make sure you have CPANMinus already installed, as described here. We install the Graph module like this:
$ sudo cpanm Graph::Easy
  • The Graph::Easy module installs a graph-easy program which we use to convert DOT graph to ASCII:

$ graph-easy life.dot

Tried with: Perl 5.22 and CPAN 1.61

How to visualize Caffe Net using GraphViz

The network architecture of Convolutional Neural Networks (CNN) can be heavily layered and complex. Viewing the network visually is a great way to get a sense of its architecture. Since the network is a graph, it is easy to visualize this using GraphViz.

Caffe requires its Net to be in the Google ProtoBuf format. It also provides a draw_net.py script that can be used to output the graph to all the formats supported by GraphViz.

  • From the Caffe root directory, you can export a .prototxt model file as a graph to a PNG image file:
$ python/draw_net.py foo.prototxt foo.png

Possible output formats include PNG, PDF, DOT and others supported by GraphViz.

  • By default, the net layers are drawn from left-to-right. I prefer to visualize a CNN in top-to-bottom fashion:
$ python/draw_net.py --rankdir TB foo.prototxt foo.png
  • I prefer to interact with the graph visualization, which is a bit difficult with an image file. So, I prefer to export to DOT format file and play with it using XDot:
$ python/draw_net.py foo.prototxt foo.dot
$ xdot foo.dot

Tried with: Ubuntu 14.04

How to convert dot file to image format

The dot file is a textual file format used to represent graphs. The dot program, which ships with GraphViz, can be used to convert the dot file into file formats that help visualize the graph. Some of the supported output file formats include PNG, PS and Dia.

For example, to convert to PNG:

$ dot foo.dot -Tpng -o foo.png

Tried with: GraphViz 2.26.3-10ubuntu1 and Ubuntu 12.04 LTS

How to visualize package dependencies in Ubuntu

Dependency graph of the package of the nano editor.
Dependency graph of the package of the nano editor.

In the Ubuntu package system, a package is dependent on many other packages and there can be other packages that are dependent on it. Thus, the Ubuntu package system is a huge complicated directed graph, with the packages as vertices and dependencies as directed edges.

It would be nice to sometimes to visually see the dependency graph of a package. That is, to see the graph of all packages that a given package is dependent on.

This can be done easily by using debtree. It can be easily installed from the Ubuntu repositories by using the package name debtree.

When invoked with the name of an installed package, it outputs its dependency graph to the standard output in the Dot format. This output can be redirected to a Dot file. I prefer to open this Dot file using Dot viewers like xdot to see the graph visually.

For example, to get the dependency graph of the package of the nano editor and view it:

$ debtree nano > nano.dot
$ xdot nano.dot

Thanks to the folks who answered my question on Ask Ubuntu.

Tried with: Ubuntu 12.04 LTS

How to view DOT file using XDot

Dot is a text format used to describe directed graphs. It is used by Graphviz and other tools that deal with graphs. There are many tools that can be used to view a dot file visually as a directed graph. The simplest of these tools is XDot.

  • It can installed easily:
$ sudo apt install xdot
  • Open any DOT file:
$ xdot foo.dot

You can zoom in and out on the graph to understand its architecture.

Tried with: xdot 0.4-2 and Ubuntu 12.04 LTS