import tensorflow as tf import csv new_model = tf.keras.models.load_model('model') # Check its architecture new_model.summary() train_label = [] train_feature=[] with open("test.csv","r") as r: reader = csv.reader(r) for i in reader: train_label.append((eval(i.pop()))) b = [eval(j) for j in i] train_feature.append(b) train_features = tf.constant(train_feature) train_labels = tf.constant(train_label) test_accuracy = tf.keras.metrics.Accuracy() branch = 32 for num in range(len(train_features)//branch): # training=False is needed only if there are layers with different # behavior during training versus inference (e.g. Dropout). x = train_features[num*32:(num+1)*32] y = train_labels[num*32:(num+1)*32] logits = new_model(x, training=False) prediction = tf.argmax(logits, axis=1, output_type=tf.int32) print("真实值为",y,"预测值为",prediction) test_accuracy(prediction, y) print("Test set accuracy: {:.3%}".format(test_accuracy.result()))