Keras 《盗梦空间》V3可以使用150x150x3的图像大小吗?

Keras 《盗梦空间》V3可以使用150x150x3的图像大小吗?,keras,classification,Keras,Classification,我在官方的keras文档中看到了这段代码,并且我已经阅读了在输入模型之前需要调整大小/缩放的图像。你能给个建议吗 from tensorflow.keras.applications.inception_v3 import InceptionV3 from tensorflow.keras.layers import Input # input size input_tensor = Input(shape=(150, 150, 3)) model = InceptionV3(input_t

我在官方的keras文档中看到了这段代码,并且我已经阅读了在输入模型之前需要调整大小/缩放的图像。你能给个建议吗

from tensorflow.keras.applications.inception_v3 import InceptionV3
from tensorflow.keras.layers import Input

# input size
input_tensor = Input(shape=(150, 150, 3))

model = InceptionV3(input_tensor=input_tensor, weights='imagenet', include_top=True)

Inception V3可以处理任何大小的图像,只要图像有3个通道。因为ImageNet图像由3个通道组成。它可以用于任何大小的原因是卷积不关心图像大小。您还可以使用灰度图像进行一些额外的工作,但我不确定它是否会破坏网络性能等。为此,您需要设置
include\u top=False
,否则您的图像大小应与模型的定义大小相匹配,
(299299,3)

您可以使用
Lambda
图层重新调整图像大小。假设您有1024x1024个图像:

input_images = tf.keras.Input(shape=(1024, 1024, 3))

whatever_this_size = tf.keras.layers.Lambda(lambda x: tf.image.resize(x,(150,150),
                     method=tf.image.ResizeMethod.BILINEAR))(input_images)

model = InceptionV3(input_tensor=whatever_this_size, weights='imagenet', include_top=False)
如果您使用的是TF数据集API,还可以执行以下操作:

your_train_data = your_train_data.map(lambda x, y: (tf.image.resize(x, (150,150), y))

Inception V3可以处理任何大小的图像,只要图像有3个通道。因为ImageNet图像由3个通道组成。它可以用于任何大小的原因是卷积不关心图像大小。您还可以使用灰度图像进行一些额外的工作,但我不确定它是否会破坏网络性能等。为此,您需要设置
include\u top=False
,否则您的图像大小应与模型的定义大小相匹配,
(299299,3)

您可以使用
Lambda
图层重新调整图像大小。假设您有1024x1024个图像:

input_images = tf.keras.Input(shape=(1024, 1024, 3))

whatever_this_size = tf.keras.layers.Lambda(lambda x: tf.image.resize(x,(150,150),
                     method=tf.image.ResizeMethod.BILINEAR))(input_images)

model = InceptionV3(input_tensor=whatever_this_size, weights='imagenet', include_top=False)
如果您使用的是TF数据集API,还可以执行以下操作:

your_train_data = your_train_data.map(lambda x, y: (tf.image.resize(x, (150,150), y))

你所说的最好的方式是什么意思?简单/容易的方式。你所说的最好的方式是什么意思?简单/容易的方式。