Create a CNN that has a Kernel that is 1xD, where D is number of columns that slides vertically over a MxD matrix?
Create a CNN that has a Kernel that is 1xD, where D is number of columns that slides vertically over a MxD matrix?
I'm trying to create a CNN in Pytorch that has a kernel that slides a 1xD kernel over a 2D image vertically so the output should be Mx1. As in the CNN convolves each row of the image then produces a single value for each row. Also having the ability to change from a 1xD to a NxD where N is some predefined number of rows would be nice as well. The input is purely just a matrix not a 3D matrix representing an image.

Kernels in nn.Conv2d do not have to be square, they can also be rectangular:
class MyModel(nn.Module):
  def __init__(self, in_channels, out_channels, N, D):
    super(MyModel, self).__init__()
    self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=(N, D), padding=0, stride=1)

  def forward(self, x):
    return self.conv(x)

Note that your input x has to be 4 dimensional: B-C-H-W. Where the number of channels C must match in_channels defined when constructing MyModel.
If you have a single image with only one channel, then the input should have two leading singleton dimensions: that is, x should have the shape 1-1-M-D.
See this answer for more information about why x should be 4D.
