简体   繁体   English

是否可以用 2D 灰度图像提供预训练的 Inception model(tensorflow 2.0/Keras)?

[英]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.

相关问题 Tensorflow:使用预训练的初始模型 - Tensorflow: use pretrained inception model 为 Keras Model 推理将 2D 灰度重塑为 4D - Reshaping 2D Grayscale into 4D for Keras Model Inference 在 TensorFlow 2.0 中,如何将 TFRecord 数据提供给 keras model? - In TensorFlow 2.0, how to feed TFRecord data to keras model? 如何在 Keras - Tensorflow 2.0 中的预训练 InceptionResNetV2 model 的不同层中找到激活的形状 - How to find the shapes of activations in the different layers of a pretrained InceptionResNetV2 model in Keras - Tensorflow 2.0 TensorFlow、Keras:替换预训练 model 中的激活层 - TensorFlow, Keras: Replace Activation layer in pretrained model 使用 VGG16 预训练模型处理灰度图像时出错 - Error while using VGG16 pretrained model for grayscale images 是否可以在预训练的 tensorflow 模型中删除类别? - Is it possible to remove categories in a pretrained tensorflow model? 如何将图像输入模型Keras - How to feed in images into the model Keras 在预训练的方式Keras,Tensorflow中使用机器学习模型 - Use Machine Learning Model in Pretrained Manner Keras, Tensorflow Tensorflow,Keras预训练的MobileNetV2模型未下载 - Tensorflow, Keras pretrained MobileNetV2 Model doesn't download
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM