预测微调接收resnetv2

2024-04-29 21:34:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在我的测试集上用我微调的InceptionResNet2进行预测。我正在努力为模型生成正确的输入形状。我尝试运行的代码是:

Y_pred = model.predict(test_data)

出现的错误如下:

ValueError: Error when checking input: expected global_average_pooling2d_1_input to have shape (8, 8, 1536) but got array with shape (7, 7, 512)

我用于微调的模型如下:

base_model = InceptionResNetV2(weights='imagenet', include_top=False, input_shape=(299,299,3))

top_model = Sequential()
top_model.add(GlobalAveragePooling2D(input_shape=base_model.output_shape[1:]))
top_model.add(Dense(num_classes, activation='softmax'))
top_model.load_weights(top_model_weights_path)

new_model = Model(inputs=base_model.input, outputs=top_model(base_model.output))

有人知道为什么会出现这种情况吗


Tags: 代码模型addinputoutputbasemodeltop