Issue regarding channel size in DCGAN for grayscale image

I tried to modify this example code https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html of DCGAN for my own dataset. The exmple code is for RGB image, but my data is grayscale image. Therefore, I set the value of number of channels ‘nc’ as 1. However, when I tried running the program, i got thid error:
RuntimeError: Given groups=1, weight of size 64 1 4 4, expected input[128, 3, 64, 64] to have 1 channels, but got 3 channels instead. I do know that its a problem about number of channels but I have no idea what else should I change to solve this error.

Any help would be appreciated!

May be when making first conv layer you accidentally written 3 instead of one.

Hi, i did specify it as 3. this is my code:
#i set the channel as 1
nc = 1
#and this is the model for discriminator
class Discriminator(nn.Module):
def init(self, ngpu):
super(Discriminator, self).init()
self.ngpu = ngpu
self.main = nn.Sequential(
# input is (nc) x 64 x 64
nn.Conv2d(nc, ndf, 4, 2, 1, bias=False),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf) x 32 x 32
nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 2),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf2) x 16 x 16
nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 4),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf
4) x 8 x 8
nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 8),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*8) x 4 x 4
nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False),
nn.Sigmoid()
)

def forward(self, input):
    return self.main(input)

I think , as err says,

model wants input of size

128, 3, 64, 64 # ( batch, channel, h, w )

but you are passing

64 1 4 4 # ( batch, channel, h, w ) 

please print those discriminator values and debug it , where is error coming from .
Also please use proper code formatting while posting.

Welcome Here :wave:.
If not solved, moderators will it , please calm.

Try by adding transforms.Grayscale( num_output_channels=1) in your tranform section and see if any error is coming