Retrieve Module Constructor Parameters from a saved Pytorch-ONNX model

May I get some help to retrieve the constructor parameters (in_channels & out_channels) in nn.Conv2D from a saved Pytorch-ONNX model.


  1. Load a pre-trained Alex-Net model from troch-vision, and save it to ONNX model.
  2. Load the saved onnx model, and try to recover it back to a Pytorch model, but have difficulties to retrieve required information. For example, in conv operators, it has only 5 attributes (dilations, group, kernel_shape, pads, strides), the required parameters like in_channels and out_channels are missing.

My goal is to recover the model back from Onnx. Is there a way to retrieve enough information to achieve my goal? If no, is there a work-around?

I understand it is extremely similar to the existing issue “Importing Onnx model”, however I still want to raise this up, since from my point of view, the saved onnx model might lack adequate info to re-load by Pytorch itself and other frameworks.

Thanks in advance!