I was exploring the padding options and
x = torch.randn(2, 37, 256, 256)+10
S = x.shape
kh, kw = 101, 101 # kernel size
dh, dw = 1, 1 # stride
pad = (S[-1]%kw // 2, S[-1]%kw // 2, S[-2]%kh // 2, S[-2]%kh // 2, 0, 0, 0, 0)
# Pad to multiples of 32
x = F.pad(x, pad)
plt.imshow(x[0,0,:,:])
Returns
But selecting mode="circular"
gives NotImplementedError
.
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
/home/gridsan/groups/dedalus_group/gfd22/stochastic_closures_repo/src/01-model/ml/cnn.py in <cell line: 11>()
40 pad = (S[-1]%kw // 2, S[-1]%kw // 2, S[-2]%kh // 2, S[-2]%kh // 2, 0, 0, 0, 0)
41 # Pad to multiples of 32
---> 42 x = F.pad(x, pad, mode="circular")
44 plt.imshow(x[0,0,:,:])
File /state/partition1/llgrid/pkg/anaconda/anaconda3-2022b/lib/python3.8/site-packages/torch/nn/functional.py:4397, in _pad(input, pad, mode, value)
4395 raise NotImplementedError
4396 else:
-> 4397 raise NotImplementedError("Only 2D, 3D, 4D, 5D padding with non-constant padding are supported for now")
NotImplementedError: Only 2D, 3D, 4D, 5D padding with non-constant padding are supported for now
torch.__version__ = 1.11.0+cu113
Not sure I understand this error, because for me, this is a 4D padding.
I tried to perform the padding for each channel and snapshot and got the same error.
Similar code works for numpy.pad
.