[Graph, Shape of Node] How to get the feature map shape of each node?

Hi,

I’ve located that the two parts of a NNVM graph:

  1. The computation graph structure
  2. The attribute map

Let me use the image classification example to illustrate my question here.
For each node of the graph, I could get the filter information through the ‘attrs’ member of Node, including filter size, number of channels, etc. I could also get the input feature map shapes of all nodes which are stored in the attribute map mentioned above. However, how could I get the feature map shape for a given node, like the way I get the filter information (have a connection of the attribute map with nodes in a graph)?

Thanks,
troore

If you just want to get the output shape for each node, you can do something like this:

    g = nnvm.compiler.graph_attr.set_shape_inputs(graph, {'data': data_shape})
    g = g.apply("InferShape")
    g_dict = json.loads(g.json())
    shape_list = g_dict['attrs']['shape'][1]
    node_map = g_dict["node_row_ptr"]
    # idx is your node index
    node_shape = shape_list[node_map[idx]]
2 Likes

Hi @kevinthesun, thanks so much for your tips. Let me double check if I’ve got your point.

From the code snippet, if we want to get the data shape of a given node, we must first get the whole map that stores shapes for all nodes in the graph, then we obtain the shape of the node we want to refer according to the index of the node. Is that right?

Yes. First we need to infer shape for a given input shape. Then we can get shape for each node in the graph.

1 Like

That’s clear. Thanks again!