I found API get_num_inputs
but it returns the number of both inputs and all of the weights.
IMO getting number of “real” inputs might be useful for usual app level…
Any ways to distinguish between the number of inputs and params at runtime? Thanks in advance.
If there’s no way to achieve this, I suggest a new API or setting an option for get_num_inputs
Hi @kimjh12, the current get_num_inputs
API counts both model inputs and weights (details in this PR). I don’t have a good idea of getting the number of model inputs, but I guess you can count the nodes with "op": "null"
in the graph.json which you can generate by calling lib.get_graph_json()
. Not an ideal way to get it though…
I tried it but seems not working right for my model… which has only one input. Thx tho
>>> json.loads(lib.graph_json)["nodes"]
[{'op': 'null', 'name': 'sub_7', 'inputs': []},
{'op': 'null', 'name': 'p0', 'inputs': []},
{'op': 'null', 'name': 'p1', 'inputs': []},
{'op': 'tvm_op',
'name': 'fused_nn_conv2d_add_clip_29',
'attrs': {'num_outputs': '1',
'num_inputs': '3',
'flatten_data': '0',
'func_name': 'fused_nn_conv2d_add_clip_29'},
'inputs': [[0, 0, 0], [1, 0, 0], [2, 0, 0]]},
{'op': 'null', 'name': 'p2', 'inputs': []},
{'op': 'null', 'name': 'p3', 'inputs': []},
{'op': 'tvm_op',
'name': 'fused_nn_conv2d_add_clip_28',
'attrs': {'num_outputs': '1',
'num_inputs': '3',
'flatten_data': '0',
'func_name': 'fused_nn_conv2d_add_clip_28'},
'inputs': [[3, 0, 0], [4, 0, 0], [5, 0, 0]]},
{'op': 'null', 'name': 'p4', 'inputs': []},
{'op': 'null', 'name': 'p5', 'inputs': []},
...
Oh, I didn’t realize a null node can also be a param node. I don’t know how to get the number of model inputs then.