[英]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:根据 Keras 2.0 文档,关于可以输入到预训练初始 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.
input_shape:可选的形状元组,仅在 include_top 为 False 时指定(否则输入形状必须为 (299, 299, 3)(使用 'channels_last' 数据格式)或 (3, 299, 299)(使用 'channels_first'数据格式)。它应该正好有 3 个输入通道,并且宽度和高度应该不小于 75。例如 (150, 150, 3) 将是一个有效值。
However, I am dealing with grayscale image which are 2D.但是,我正在处理 2D 的灰度图像。 How I should deal with this situation?
我应该如何处理这种情况?
You can copy the grayscale image 3 times for a pseudoRGB image对于伪RGB图像,您可以将灰度图像复制3次
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:如果您的图像的形状长度为 2,则只有宽度和高度,您首先需要添加一个额外的尺寸:
img = np.expand_dims(img,-1)
The you repeat this last dimension 3 times:您将最后一个维度重复 3 次:
img = np.repeat(img,3,2)
print(img.shape)
# (224,224,3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.