背景
在Keras中微调分类模型时,它打印了val_acc: 0.8456。使用This code进行微调。
经过微调、手动加载训练模型并预测估值集后,0.28的精度大大降低。
以下代码用于评估:
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差异较大的原因可能是什么
发布于 2017-07-31 10:13:06
您正在使用不同的预处理来进行训练和测试。具体来说,
rescale = 1./255用于训练,但是
x = vgg19.preprocess_input(x)用于测试。
imagenet_utils.preprocess_input()所做的是减去平均值(在ImageNet上计算,顾名思义):
# Zero-center by mean pixel
x[:, :, :, 0] -= 103.939
x[:, :, :, 1] -= 116.779
x[:, :, :, 2] -= 123.68因此,它与应用于训练数据的预处理有很大的不同。
发布于 2017-07-31 17:51:31
使用相同的ImageDataGenerator
我的ImageDataGenerator是:
train_datagen = ImageDataGenerator(
rescale=1. / 255, ...)能够按如下方式重现其预处理过程:
img = load_img(image_path, target_size=target_size)
x = img_to_array(img)
x = np.expand_dims(x, axis=0)
x *= rescale_factor
score = model.predict(x)https://stackoverflow.com/questions/45399535
复制相似问题