gnn icon indicating copy to clipboard operation
gnn copied to clipboard

Schema visualization tool

Open post2web opened this issue 2 years ago • 0 comments

Schemas can be complex and need visualization. A simple script could convert the schema to a networkx graph and generate an image with the graph visualization.

This can be a starting point:

import networkx as nx
import matplotlib.pyplot as plt


graph_schema = tfgnn.read_schema("schema.pbtxt")
graph = nx.DiGraph()

nodes = [
    name for name in graph_schema.node_sets.keys()
]
edges = [
    [e.source, e.target] for e in graph_schema.edge_sets.values()
]
edge_labels = {
    (e.source, e.target): name for name, e in graph_schema.edge_sets.items()
}

graph.add_nodes_from(nodes)
graph.add_edges_from(edges)

pos = nx.spring_layout(graph)

nx.draw(graph,
        pos=pos,
        node_size=1000,
        with_labels = True)

nx.draw_networkx_edge_labels(
    graph,
    pos=pos,
    edge_labels=edge_labels
)

plt.savefig("schema.png")

The above can generate a schema visualizations like this: Unknown

post2web avatar Feb 24 '23 04:02 post2web