How can I export model to ONNX so that I'll get intermediate layers' output as well as the layer? (I've seen a similar question that went unanswered here)
Consider I have a model, model. The model is a torch model and I'd like to have multiple outputs: the last layer as well as one of the intermediate layers: specifically, one of the convolutions that happens in the process.
import torch
import onnx
device = 'cpu'
dummy_input = torch.randn(1, 3, 320, 320).to(device)
input_key_name = 'input'
output_key_name = 'output'
torch.onnx.export(model, dummy_input, model_output_name,
input_names=[input_key_name], output_names=[output_key_name])
My questions are:
- Is it possible to get multiple layers output? How?
- How would I know the output layer name I'm supposed to provide? Is it possible to use Netron to elucidate the names? (or other tools?)
Right now my code works correctly for the last layer, but I'm not sure how to go from here to get an additional layer as well.
