model accuracy
{'AlexNet.h5': 0.3725,
'LeNet5.h5': 0.2192,
'MiniVGG_CNN_model.h5': 0.1748,
'MiniVGG_CNN_model_augu.h5': 0.1752,
'MyCNN.h5': 0.2073}
对比文章二的准确率结果来看,重新加载模型准确率大大降低,但是AlexNet反而性能得到提升。
有知道原因的可以留言。
GitHub 上同样情况的讨论
模型重载,预测
def model_prediction(model_name, test_size):
(X_train_full, y_train_full), (X_test, y_test) = datasets.cifar10.load_data()
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
# X_train_full, X_test = X_train_full / 255.0, X_test / 255.0
# X_train, y_train = X_train_full[0:1000], y_train_full[0:1000]
# X_valid, y_valid = X_train_full[1000:2000], y_train_full[1000:2000]
# print(y_test[:10])
idxs = np.arange(X_test.shape[0])
np.random.shuffle(idxs)
X_test, y_test = X_test[idxs], y_test[idxs]
# print(y_test[:10])
model = keras.models.load_model(model_name)
model.summary()
r = model.predict(X_test[:test_size], batch_size=32, verbose=1)
count = 0
wrong_names = []
for i in range(test_size):
if np.argmax(r[i]) == y_test[i][0]:
count += 1
else:
wrong_names.append(class_names[y_test[i][0]])
# print(count, wrong_names)
# plot_images(X_test[:test_size], y_train=y_test[:test_size])
# plot_images(X_test[:test_size], prediction=r, flag=True)
return count/test_size
运行每个程序,得到预测准确率
if __name__ == '__main__':
model_percent = {}
name = ["AlexNet.h5", "LeNet5.h5", "MiniVGG_CNN_model.h5", "MiniVGG_CNN_model_augu.h5", "MyCNN.h5"]
for n in name:
K.clear_session() # Some memory clean-up
my_per = model_prediction(n, 10000)
model_percent[n] = my_per
print(model_percent)