首页 > 解决方案 > ValueError: Input 0 is in compatible with layersimilarity_model: 预期形状=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3)

问题描述

我正在使用 tensorflow_similarity 创建模型。第一个 epoch 结束时引发的错误。

INPUT_SHAPE = (224,224,3)

我的模型(与示例回购https://github.com/tensorflow/similarity/blob/master/examples/supervised_hello_world.ipynb相同)

def create_model():
inputs = tf.keras.layers.Input(shape=INPUT_SHAPE)
x = tf.keras.layers.experimental.preprocessing.Rescaling(1./255)(inputs)
x = tf.keras.layers.Conv2D(32, 7, activation='relu')(x)
x = tf.keras.layers.Conv2D(32, 3, activation='relu')(x)
x = tf.keras.layers.MaxPool2D()(x)
x = tf.keras.layers.Conv2D(64, 7, activation='relu')(x)
x = tf.keras.layers.Conv2D(64, 3, activation='relu')(x)
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)

outputs = MetricEmbedding(64)(x)
return SimilarityModel(inputs, outputs)

我也尝试过通过 api 使用不同的模型

model = EfficientNetSim(input_shape=INPUT_SHAPE,embedding_size = 128,variant = "B0",augmentation = False,weights = None)

该错误也与以前相同。

ValueError: Input 0 is incompatible with layer similarity_model: expected shape=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3)

标签: pythontensorflowsimilarity

解决方案


我解决了错误。合适的是validation_data。tensorflow_similarity 中的采样器生成不等于 validation_data 的新批次。通过在 ( x_val , y_val ) 中给出验证数据或使等于采样器的批次来解决。


推荐阅读