本文介绍了微调模型中的Keras精度差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Keras中微调分类模型时,它打印了val_acc: 0.8456. 此代码用于微调.

While fine tuning a classification model in Keras, it printed val_acc: 0.8456. This code was used for fine-tuning.

微调后,手动加载经过训练的模型并预测估值集,则会收到0.28更低的准确性.

After fine-tuning, manually loading the trained model and predicting the valuation set, a much lower accuracy of 0.28 was received.

以下代码用于评估:

model = load_model(MODEL_PATH)
...
img = kimage.load_img(img_path, target_size=target_size)
x = kimage.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = vgg19.preprocess_input(x)
pred = model.predict(x)

问题

0.85 != 0.28准确性差异很大的原因是什么?

Question

What might be the cause for the big discrepancy in accuracy 0.85 != 0.28?

推荐答案

您正在使用不同的预处理进行培训和测试.具体来说,

You're using different preprocessing for training and testing.Specifically,

rescale = 1./255

用于训练,但是

x = vgg19.preprocess_input(x)

用于测试.

imagenet_utils.preprocess_input()的作用是减去平均值(如名称所建议,在ImageNet上计算):

What imagenet_utils.preprocess_input() does is subtracting the mean (computed on ImageNet, as suggested by the name):

    # Zero-center by mean pixel
    x[:, :, :, 0] -= 103.939
    x[:, :, :, 1] -= 116.779
    x[:, :, :, 2] -= 123.68

因此,它与对训练数据进行的预处理完全不同.

So it's fairly different from the preprocessing applied on your training data.

这篇关于微调模型中的Keras精度差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:05