How to export onnx from pytorch model?

Hi all,

I would like to convert my pytorch model to onnx file but I got this error :

TypeError: conv2d() received an invalid combination of arguments - got (list, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:
(Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
didn’t match because some of the arguments have invalid types: (list, Parameter, Parameter, tuple, tuple, tuple, int)
*(Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
didn’t match because some of the arguments have invalid types: (list, Parameter, Parameter, tuple, tuple, tuple, int)

here’s my code :

import os
import DuelingDeepQNetwork as ddqn
import DuelingDDQNAgent as duelingddqnAgent
from cv2 import randn
import gym
import utils
import numpy as np
import matplotlib.pyplot as plt
import torch
import DuelingDDQNAgent as duelingddqnAgent
import DuelingDeepQNetwork as ddqn
model2=ddqn.DuelingDeepQNetwork(0.0001,6,[4,200,200],‘test’,‘checkpoint/’)
print(‘model2’,model2)
state_dict = torch.load(‘q_eval_ddqn_5000.pth’)
#model2.load_state_dict(state_dict)
model2.load_state_dict(state_dict[‘model_state_dict’])
model2.eval()
print(‘pth_loaded’)
dummy_input =[4,200,200]
print(‘Exporting the ONNX file…’)
torch.onnx.export(model2, dummy_input,‘model.onnx’)

How can I solve that issue ? Thanks

Blockquote

I guess the error is caused in:

dummy_input =[4,200,200]
torch.onnx.export(model2, dummy_input,'model.onnx')

as torch.onnx.export expects the model input (e.g. a tensor) in your dummy_input not a list of integers.

yes exactly. the problem solved with :

dummy_input =torch.randn([1,4,200,200], device=“cpu”)

thanks!