What is a proper way to modify the code above to adjust the model for a dataset that consists of black and white/grayscale images, not RGB?
This model is designed for processing 3-channel images (RGB) while I need to handle some black and white image data, so I’d like to change the “ch” parameter to “1” instead of “3.”
But if we just change this parameter — “nc = 3” → “nc = 1” — without adjusting generator’s and discriminator’s code blocks, executing just gives an error message:
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
Changing nc-->1 will result in a generator/discriminator capable of handling one channel (grayscale). However, you need to also adjust the dataloading/transforming step to convert the images into grayscale. That error suggests that this is not happening yet.
Specifically, we’re interested in those transforms. Each datapoint starts off as a PIL image. The transforms suggest that each datapoint will:
Get resized
Cropped
Turned into a tensor
Normalized. Here the first tuple denotes the mean for each channel and the second tuple denotes the std for each channel.
We’ll need to do 2 things here. We need to add a transformation for grayscale and because we’ll only have one channel, we’ll go ahead and adjust that normalization step as well.