ONNX export failed:Couldn't export Python operator Im2Col

I am trying to convert a pytorch model to Onnx format. I am using F.unfold in between.
But while converting I am getting below error.

import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
import torch

class Test_model(torch.nn.Module):
def forward(self, x, y):
x = torch.rand(1, 64, 157, 317)
#x=F.unfold(x, kernel_size=3, padding=1)
unfold_p0=nn.Unfold(kernel_size=3,padding=0, stride=4)
return x

model = Test_model()
dummy_input = torch.ones(2, 3, dtype=torch.long)
loop_count = torch.tensor(5, dtype=torch.long)

torch.onnx.export(model, (dummy_input, loop_count), ‘loop.onnx’, verbose=True)

proto, export_map = graph._export_onnx(params, _onnx_opset_version, defer_weight_export, operator_export_type)
RuntimeError: ONNX export failed: Couldn’t export Python operator Im2Col

I am using torch version: 1.2.0

torch.unfold is not supported in the PyTorch to ONNX exporter yet. There’s an open PR for initial export support.

Just curious - which model is this needed for?

The PR mentioned above provides export for torch.Tensor.Unfold op. However, I think your model uses torch.nn.Unfold export (this one internally uses Im2Col). nn.Unfold is currently in out backlog of unsupported ops. I will updated the thread once we have started a PR for this one.