当前位置:   article > 正文

CNN 3 LeNet5, AlexNet, MyCNN,ResNet 模型重载_alexnet.h5

alexnet.h5
  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}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

对比文章二的准确率结果来看,重新加载模型准确率大大降低,但是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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

运行每个程序,得到预测准确率

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/691172
推荐阅读
相关标签
  

闽ICP备14008679号