# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## 使用已经训练好的模型直接对测试集评估

from keras.models import load_model

model = load_model('keras-mnist-cnn-first.h5')

from keras.datasets import mnist
from keras.utils import np_utils

(X_train,y_train),(X_test,y_test) = mnist.load_data()
X_test = X_test.reshape(-1,1,28,28)
y_test = np_utils.to_categorical(y_test,num_classes=10)

loss,accuracy = model.evaluate(X_test,y_test)# 默认batch_size的的大小为32
print('\ntest loss:',loss)
print('\ntest accuracy',accuracy)

StarcoderdataJupyterScriptsDedupFiltered