keras - Inception V3 可以使用 150x150x3 的图像尺寸吗?
问题描述
我在官方 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)
解决方案
只要您的图像有 3 个通道,Inception V3就可以处理任何大小的图像。因为 ImageNet 图像由 3 个通道组成。它可以用于任何尺寸的原因是卷积不关心图像尺寸。您还可以将它与灰度图像一起使用,但需要做一些额外的工作,但我不确定它是否会破坏网络性能等。为此,您需要设置include_top = False
,否则您的图像大小应与模型定义的大小匹配,(299,299,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-Dataset API,您还可以执行以下操作:
your_train_data = your_train_data.map(lambda x, y: (tf.image.resize(x, (150,150), y))
推荐阅读
- javascript - 句子计数中不包括小数
- regression - Don't get the correct lasso MSE
- node.js - Webpack 4 devServer HMR plus full reload on other file changes (like views)
- r - 为什么β回归中的加权和未加权相关性之间没有区别?
- scala - Get distinct elements from rows of type ArrayType in Spark dataframe column
- python - Getting data from flask request is slow
- javascript - Stream files stored on S3 to client without downloading it to flask server
- r - 什么策略建议按月和年对数据框进行子集化以获得 R 中的单个数据框列表
- javafx - JavaFX 进入鼠标事件延迟/滞后
- android - ADB TCP port automatically changes to 5037