0

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,

Ryan
  • 8,459
  • 14
  • 40
  • 66
  • 1
    I do not think what you are saying is easy to implement because the weights should be of fixed sized, but definitely you can identify the 1 channel images in the data-preprocessing part and then copy it three times to make a 3 channel image – Manuel Lagunas May 23 '18 at 12:20

2 Answers2

1

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.

iacolippo
  • 4,133
  • 25
  • 37
1

Load your images and convert them to RGB:

from PIL import Image
image = Image.open(path).convert('RGB')
A.M
  • 327
  • 1
  • 2
  • 11