'How to add ArgMax to the end of ONNX model?

I have an ONNX model where I get the output as an 1xN array of probabilities. I want to add ArgMax to the end of the model so that I get the index instead.

I tried doing this using onnx.helper but was not able to find a good way to do it. I can create an ArgMax node using:

argmax = onnx.helper.make_node(
    'ArgMax',
    inputs=['inp'],
    outputs=['out'],
    axis=0,
    keepdims=0)

but how do I append this node to the end of the graph?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source