0
$\begingroup$

I would like to do Transfer Learning using one of the novel networks such as VGG, ResNet, Inception, etc.

The problem is that my images are grayscale (1 channel) since all the above mentioned models were trained on ImageNet dataset (which consists of RGB images).

One of the solutions is to repeat the image array 3 times to make it 3 channel.

Is this really the only solution for that? Is it a good solution? Are there any other solutions?

$\endgroup$
  • $\begingroup$ Here's an answer to it. stackoverflow.com/questions/45939561/… $\endgroup$ – Shubham Panchal May 4 '19 at 2:36
  • $\begingroup$ Shubham has already provided with another question's link, but I would also like to add one more method here. You can simply change the input layer to accept the grayscale image and then use the pretrained weights for the hidden layers. $\endgroup$ – thanatoz May 4 '19 at 5:06
  • $\begingroup$ Dear Shubham, the link provides the same way that I asked about which is "repeat the image array 3 times to make it 3 channel". $\endgroup$ – Hunar May 4 '19 at 13:17
  • $\begingroup$ @thanatoz, could you give more detail? what you mean by "You can simply change the input layer to accept the grayscale image and then use the pretrained weights for the hidden layers.". $\endgroup$ – Hunar May 4 '19 at 13:18
  • $\begingroup$ @SoK, Sorry, but this approach does not works. Will need to figure out something else. Throws this error Input 0 is incompatible with layer block1_conv1: $\endgroup$ – thanatoz May 6 '19 at 6:36
-1
$\begingroup$
print(grayscale_batch.shape)  # (64, 224, 224)    

rgb_batch = np.repeat(grayscale_batch[..., np.newaxis], 3, -1)    
print(rgb_batch.shape)  # (64, 224, 224, 3)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.