Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

TypeError: 'GraphModule' object is not subscriptable (Access Weights for .onnx ML model in Pytorch)

$
0
0

I have a popular .onnx ML model for weather forecasting and am trying to convert this to PyTorch for finetuning. I use the following code to convert this:

import osimport numpy as npimport onnxfrom onnx import numpy_helperimport onnxruntime as ortfrom onnx2torch import convertmodel_24 = onnx.load('pangu_weather_24.onnx')tm = convert(model_24) #Convert onnx model to torch

From here, I want to access the weights of the model in the 'tm' object but I can't seem to find any resources online for this.

Trying to subscript it with tm[0] reveals the following error:

TypeError: 'GraphModule' object is not subscriptable

and the dict for this object via 'tm.dict' is even more confusing (pasted in the image).

The normal methods online for accessing a PyTorch weight matrix also reveal the same error that the graphmodule is not subscriptable


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>