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,
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 can detect the grayscale images by checking the size and apply some transformation to have 3 channels.
It seems to be better to convert images from grayscale to RGB than simply copying the image three times on the channels.
You can do that by cv2.cvtColor(gray_img, cv.CV_GRAY2RGB)
if you have opencv-python
installed.
If you want a clean implementation you can extend torchvision.transform
with a new Transform
that does this job automatically.
Load your images and convert them to RGB:
from PIL import Image
image = Image.open(path).convert('RGB')