How can I change number of channels on Resnet to make it work only on B/W images?

Viewed 3556

I'm working on tensorflow and my dataset is composed only by Black and White images, so I thought that I could make my neural net (currently I am using Resnet50) less heavy and easier to train and test by changing the number of channels from 3 to 1, Is there a way to do so? (Ik I can treat b/w images as rgb images but I don't want to do that)

Thanks in advance for the answer

1 Answers

The pretrained weights in keras.applications require a 3 channel input. You could one of two things:

  1. Use a different pretrained model that works on grayscale images.
  2. Set the R, G and B channels to replicate your BW input, then fine-tune the entire neural network on your own dataset. This probably won't work without the fine-tuning step.

On a side note, I must say this task will not help in your goal of making it 'less heavy and easier to train and test'. If you call model.summary() on keras Resnet50, you see that of the total trainable 23,534,592 parameters, only about 10K of them are in the initial layer. So at best you can reduce the number of parameters by an insignificant few thousand.

I would instead suggest using a lighter model such as MobileNet that are also available in Keras.

Related