1
$\begingroup$

For some square images, I'd like to use torch.nn.Conv2d with the kernel as a vertical block. As in, the kernel size is defined as max value of the first dimension by 1. Since the first dimension has no more room, I'd like to have 0 stride along that first dimension. I tried using the following definition:

self.conv1 = torch.nn.Conv2d(3, 32, (max_dim_0, 1),
                                    stride=(0, 1),
                                    padding=0, 
                                    dilation=1,
                                    groups=1, 
                                    bias=True, 
                                    padding_mode='zeros')

However, this causes my training loop throws a RuntimeError: non-positive stride is not supported exception. Is there a way to define the kernel as a vertical block?

$\endgroup$
1
  • $\begingroup$ does this help? $\endgroup$
    – Nikos M.
    Commented Jul 26, 2020 at 8:11

1 Answer 1

2
$\begingroup$

Setting stride to 0 is not necessary, torch will simply compute with respect to the input tensor sizes, so you can set stride to (1,1).

For x of size (batch_size, 3, max_dim_0, max_dim_0) (square image) the tensor output will be of size (batch_size, 32, 1, max_dim_0).

$\endgroup$
1
  • $\begingroup$ Thanks this worked for me :) $\endgroup$ Commented Jul 28, 2020 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.