我使用ImageDataGenerator.flow_from_directory()来训练和测试我的模型。在训练时,准确率可达90%。
但当我测试我的模型时,准确率只是平均值(50%)。
这就是我使用ImageDataGenerator的方式
datagen = ImageDataGenerator(rescale=1. / 255)
train_data = datagen.flow_from_directory(img_path + '\\train', target_size=(224, 224),
classes=['NORMAL', 'PNEUMONIA'],
batch_size=10)
test_data = datagen.flow_from_directory(img_path + '\\test', target_size=(224, 224),
classes=['NORMAL', 'PNEUMONIA'],
batch_size=10)这是我训练和测试我的模型的方式:
model.fit_generator(train_data, steps_per_epoch=32, epochs=100)
test_info = model.evaluate_generator(test_data, steps=10)
print(test_info)在测试模型时,我尝试用train_data替换test_data。但是结果是一样的。
发布于 2018-11-09 21:42:10
看起来你的模型在训练数据上过度拟合了。你可以尝试一些方法来防止它,比如:
体系结构早期退出,L1/L2体系结构复杂性不断增加的数据集(if possible)
https://stackoverflow.com/questions/53226553
复制相似问题