Hi, I am still learning PyTorch, so please forgive me for any confusion. I am looking for an implementation that one CONV operation uses multiple kernels. For example on CONV1D, I have an array [1,0,1,1,0] and would like to use 3 1x3 kernels ([0.1,0.2,0.1],[0.1,0,0], [0,0.2,0]) to sweep the array sequentially, and get [10.1+00.2+10.1=0.2, 00.1+10+10=0, 10+10.2+00=0.2]. I couldn’t find any straightforward PyTorch solutions and would like to hear any suggestions. Thanks.
Based on your description it seems as if you would like to apply the kernels to a single location and shift each kernel by 1?
If so, you could e.g. apply a standard convolution and get the diagonal of the result:
x = torch.tensor([[[[1., 0., 1., 1., 0.]]]]) conv = nn.Conv2d(1, 3, kernel_size=(1, 3), bias=False) with torch.no_grad(): weight = torch.tensor([[[[0.1, 0.2, 0.1]]], [[[0.1, 0., 0.]]], [[[0, 0.2, 0]]]]) conv.weight.copy_(weight) out = conv(x) out[:, torch.arange(3), :, torch.arange(3)]
unfold the input and use a matrix multiplication to get the desired results.
This is what I need, thanks