Where should i put the input image dimesions in the following architecture in Pytorch?
class Discriminator(nn.Module):
def __init__(self, channels=3):
    super(Discriminator, self).__init__()
    
    self.channels = channels

    def convlayer(n_input, n_output, k_size=4, stride=2, padding=0, bn=False):
        block = [nn.Conv2d(n_input, n_output, kernel_size=k_size, stride=stride, padding=padding, bias=False)]
        if bn:
            block.append(nn.BatchNorm2d(n_output))
        block.append(nn.LeakyReLU(0.2, inplace=True))
        return block

    self.model = nn.Sequential(
        *convlayer(self.channels, 32, 4, 2, 1),
        *convlayer(32, 64, 4, 2, 1),
        *convlayer(64, 128, 4, 2, 1, bn=True),
        *convlayer(128, 256, 4, 2, 1, bn=True),
        nn.Conv2d(256, 1, 4, 1, 0, bias=False),  # FC with Conv.
    )

def forward(self, imgs):
    logits = self.model(imgs)
    out = torch.sigmoid(logits)

    return out.view(-1,1)

The above architecture is of Discriminator of GAN model, i am little confused as in the first layer
*convlayer(self.channels, 32, 4, 2, 1)

self.channels ,which is 3 (colored image), is passed , I have an input image of 64 * 64 * 3. My first question is where the dimensions of input image are taken care in the above architecture?
I have got this confusion because when i saw the generator architecture ,
class Generator(nn.Module):
def __init__(self, nz=128, channels=3):
    super(Generator, self).__init__()
    
    self.nz = nz
    self.channels = channels
    
    def convlayer(n_input, n_output, k_size=4, stride=2, padding=0):
        block = [
            nn.ConvTranspose2d(n_input, n_output, kernel_size=k_size, stride=stride, padding=padding, bias=False),
            nn.BatchNorm2d(n_output),
            nn.ReLU(inplace=True),
        ]
        return block

    self.model = nn.Sequential(
        *convlayer(self.nz, 1024, 4, 1, 0), # Fully connected layer via convolution.
        *convlayer(1024, 512, 4, 2, 1),
        *convlayer(512, 256, 4, 2, 1),
        *convlayer(256, 128, 4, 2, 1),
        *convlayer(128, 64, 4, 2, 1),
        nn.ConvTranspose2d(64, self.channels, 3, 1, 1),

        nn.Tanh()
    )

def forward(self, z):
    z = z.view(-1, self.nz, 1, 1)
    img = self.model(z)
    return img

In the first layer
*convlayer(self.nz, 1024, 4, 1, 0)

they are passing self.nz ,which is 128 random latent points required to generate image of 64 * 64 * 3, as opposed to the above discriminator model where the channels are passed.
My second question is, if i have an image of 300 * 300 * 3, what should i change in my architecture of Discriminator to process the image?
P.S. I am new to Pytorch.

The dimensions of an input image are not at all required in convolutions. All you're going to do is to perform kernel convolutions (with/without) strides across the image. You just have to ensure that the input to a convolutional layer has a size more than the size of the kernel of that layer. For eg: You cannot apply a 3x3 kernel on a 2x2 image. Of course, you can come around this issue by padding, but in general, it's not possible.

The discriminator is going to take a sample from your dataset or from the one generated by the Generator to evaluate whether it's true or fake. Since this is a CNN and not a Linear Layer Network, you do not need to specify the size of the input image.

The generator is going to sample from the latent points and then generate an image. If you have a 300x300 image, you don't need to change anything with the discriminator.


