ConvTranspose2d using unfold

Hello,
Supose i have an matrix img and a kernel kernel.
Is it possible to do a transposed convolution doing a matrix multiplication.
I know that when you unroll the kernel you have to transpose this but when unrolling the input i cant
figure it out.

import torch
# as an input im using a tensor with the size of a mnist digit
img = torch.randn(1 ,1 ,28 ,28)
# kernel with 1 input dim and 1 output dim
kernel = torch.randn(1 ,1 ,3 ,3)
# unfold with kernel size 3 ,stride 2 , padding 1
unfold = torch.nn.Unfold(kernel_size=(3,3) ,stride=2 ,padding=1)
# unfolded data
img_unfolded = unfold(img)

"""
so how to do the convtranspose using img_unfolded and kernel?
"""

thanks for looking at it and have a nice day :slight_smile:

1 Like