Input 3 and 1 channel input to the network in pytorch?

My dataset consists mostly of 3 channel images, but i also have a few 1 channel images,Is it possible to train a network that takes in both 3 channels and 1 channels as inputs?

Any suggestions are welcome,Thanks in advance,

You could check for the number of channels and based on this chose a separate model input layer.
However, I wouldn’t apply this method.

The straightforward solution would be to load your images and convert them to RGB:

image ='RGB')

You can add this line to your Dataset's __getitem__ method.

Thanks for the reply ptrblck!
Hmmm,So this converts the grayscale image to RGB?

Yes. It converts grayscale images to RGB and just keeps color images as RGB.

Thanks you for your time

No worries! Let me know, it that works for you!