简体   繁体   中英

Is it possible to feed the pretrained Inception model (tensorflow 2.0/Keras) with 2D grayscale images?

According to Keras 2.0 documentation, in relation to the input shape of the images that can be fed to the pretrained inception model:

input_shape: optional shape tuple, only to be specified if include_top is False (otherwise the input shape has to be (299, 299, 3) (with 'channels_last' data format) or (3, 299, 299) (with 'channels_first' data format). It should have exactly 3 inputs channels , and width and height should be no smaller than 75. Eg (150, 150, 3) would be one valid value.

However, I am dealing with grayscale image which are 2D. How I should deal with this situation?

You can copy the grayscale image 3 times for a pseudoRGB image

import numpy as np
# img=np.zeros((224,224))

If your image is of shape length 2, only width and height you will first need to add an extra dimension:

img = np.expand_dims(img,-1)

The you repeat this last dimension 3 times:

img = np.repeat(img,3,2)
print(img.shape)
# (224,224,3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM