I am finding some issues while converting from pytorch to ONNX please help me in sorting out things .
Please find the issue below
TypeError: i_(): incompatible function arguments. The following argument types are supported:
1. (self: torch._C.Node, arg0: str, arg1: int) -> torch._C.Node
Invoked with: %338 : Tensor = onnx::RandomNormal(), scope: VAEGen
, ‘shape’, 333 defined in (%333 : int[] = prim::ListConstruct(%320, %324, %328, %332), scope: VAEGen
) (occurred when translating randn)
The code for the model is below
class VAEGen(nn.Module):
# VAE architecture
def __init__(self, input_dim):
super(VAEGen, self).__init__()
# dim = params['dim']
# n_downsample = params['n_downsample']
# n_res = params['n_res']
# activ = params['activ']
# pad_type = params['pad_type']
# content encoder
self.enc = ContentEncoder(2, 4, 3, 64, 'in', 'relu', pad_type='reflect')
self.dec = Decoder(2, 4, self.enc.output_dim, 3, res_norm='in', activ='relu', pad_type='reflect')
def forward(self, images):
# This is a reduced VAE implementation where we assume the outputs are multivariate Gaussian distribution with mean = hiddens and std_dev = all ones.
hiddens,_ = self.encode(images)
if self.training == False:
noise = Variable(torch.randn(hiddens.size()).cuda(hiddens.data.get_device()))
images_recon = self.decode(hiddens + noise)
else:
images_recon = self.decode(hiddens)
return images_recon, hiddens
def encode(self, images):
hiddens = self.enc(images)
noise = Variable(torch.randn(hiddens.size()).cuda(hiddens.data.get_device()))
return hiddens, noise
def decode(self, hiddens):
images = self.dec(hiddens)
return images
The conversion code for pytorch to ONNX is below
generator = VAEGen(3).cuda() # Initalize your weights there
dummy_input = torch.randn(1 ,3, 256, 256).cuda()
torch.onnx.export(generator, dummy_input, "exported.onnx")