General unfold function with dilation

PyTorch provide the powerful function unfold, through both torch.nn.functional.unfold and the builtin function for tensor torch.Tensor.unfold. It seems the latter is easier to use, and it is more general as it is not restricted to 4D tensor. However, the former implementation support dilation, while the latter does not.

Does anyone has method to augment the builtin function implementation to make it support dilation?

1 Like

They are really doing different things. nn.Unfold gets the sliding window from image tensors. Tensor.unfold just unfolds along a single dimension. (You can think of the former as doing the latter along dim 2 and dim 3 at the same time). For Tensor.unfold, step arg is probably what you want.

Thanks. step arg is stride, not dilation. Also, doing nn.unfold twice does not give the same result as tensor.unfold.

I am looking for a unfold function with dilation too. Hope some one can giva more imformation!

What does nn.Unfold not do what you need when you give it a dilation parameter?

After some research and trail,nn.Unfold with stride parameter seems to do what I want. I am still trying…