【发布时间】:2021-07-02 05:54:12
【问题描述】:
我是 TensorFlow 新手。我有不同图像大小的图像分类问题。在documentation 中,我了解到在模型内部而不是在dataset.map() 函数中调整大小是多么有益。
我像这样批处理我的数据集:
ds_train = ds_train\
.batch(BATCH_SIZE)\
.prefetch(tf.data.experimental.AUTOTUNE)
我的模型很简单:
base_model = tf.keras.applications.ResNet50V2(
include_top=True, weights=None, input_tensor=None, input_shape=(224,224,3),
pooling=None, classes=NUM_CLASSES, classifier_activation='softmax')
seed = 42
model = tf.keras.Sequential([
tf.keras.Input(shape=(None, None, 3)),
tf.keras.layers.experimental.preprocessing.Resizing(224, 224),
tf.keras.layers.experimental.preprocessing.Rescaling(1./255),
tf.keras.layers.experimental.preprocessing.RandomFlip(mode='horizontal_and_vertical', seed=seed),
base_model
])
这给了我错误:
InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [95,116,3], [batch]: [108,112,3]。如何将调整大小层与批处理一起使用?
【问题讨论】:
标签: python tensorflow keras deep-learning tensorflow2.0