pytorch / pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration
https://pytorch.org
Other
84.57k stars 22.78k forks source link

Padding mode for ConvTransposeNd #46027

Open pimdh opened 4 years ago

pimdh commented 4 years ago

🚀 Feature

Support the padding modes implemented in ConvNd also for ConvTransposeNd

Motivation

When using CNNs on physics models which live on periodic lattices, such as the Ising model, circular/periodic padding mode is the only sensible thing to do. When we want the CNN to output values on the lattice points (=pixels), I'd like to downsample with convolution with stride, then upsample with transposed convolution. This requires circular/periodic padding to be an option to ConvTransposeNd.

Pitch

Comparing Conv2D (https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py#L381) with ConvTranspose2D (https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py#L819), it looks like all that is needed is a call to F.pad. However, maybe some calculations on the padding size need to be done.

mruberry commented 4 years ago

Thanks for this suggestion, @pimdh. Would an implementation of a pad function like NumPy's pad also solve this issue?

JulianoGianlupi commented 3 years ago

I want to second @pimdh's feature request. And I think, @mruberry, that numpy's pad would solve any need like this (in my case I'd use 'edge')

Fengyixin-research commented 3 weeks ago

'ValueError: Only "zeros" padding mode is supported for ConvTranspose2d'. Why this error still occurs in 2024? Is there no way to use circular padding mode in ConvTranspose2d?