Mask input / skip row in conv layer

Hi,

is there a way to skip/mask a particular row/column or even pixel of the input in a Conv2D layer?
Further, is it possible to skip/mask only the backward pass?

An example:
Given an input with (h,w)=(10,10) e.g. the 5th row should be ignored, so that the output size after appropriately padded convolution is (h,w) = (9,10).

Hi,

You can manually remove the row with (for a 1D Tensor) new = torch.cat([old[:idx], old[idx+1:]], 0).

Thanks, but the row/column/pixel is needed for the convolution of neighboring rows/columns/pixels. It just should not produce an output where it’s at the center of the convolution kernel (especially not on the backward pass)

You can delete that line after the convolution computation then?

For the forward pass yes, but what happens to the backward pass then?

Since you deleted this output’s row, it’s gradient will be 0. And so it won’t have any impact on the input.

Perfect, many thanks!

What is with individual pixels, if I want to ignore them for the backward pass?

What do you mean by ignore them for the backward pass exactly? Do you want to force the gradients for these pixels to be 0?

Yes kind of.
I need those pixels in the forward pass, but when the kernel is centered on those pixels it (the entire kernel at that location) should not contribute to the gradient.

The masking will do what you want. As it will fill the gradient for these pixels with 0s and the backward of the conv will propagate 0 * w = 0 for these entries.

sorry, which masking do you mean?

Any of them :slight_smile: But in particular the one discussed above using .cat will work.