1

I want to convert my pyTorch model(.pth) to ONNX. This is my code.

import torch
import torchvision
dummy_input = torch.randn(1,3,224,224,device = "cuda")
model = torch.load("/home/selfsup/moco/r50_v2/epoch_200.pth")
torch.onnx.export(model,dummy_input,"LENet.onnx",verbose = True)

However, I get an error saying that.

Traceback (most recent call last):
  File "tengine_convert.py", line 5, in <module>
    torch.onnx.export(model,dummy_input,"LENet.onnx",verbose = True)
  File "/home/anaconda3/lib/python3.6/site-packages/torch/onnx/__init__.py", line 320, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "/home/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 111, in export
    custom_opsets=custom_opsets, use_external_data_format=use_external_data_format)
  File "/home/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 709, in _export
    with select_model_mode_for_export(model, training):
  File "/home/anaconda3/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 42, in select_model_mode_for_export
    is_originally_training = model.training
AttributeError: 'dict' object has no attribute 'training'

Why is this?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
frye
  • 11
  • 1

0 Answers0