加载训练模型的方法:
第一种:直接赋值训练时的整个代码
with tf.Session() as sess:
sess.run(init)
test_total_batch = int(len(test_label)/batch_size)
ckpt = tf.train.latest_checkpoint(model_path)# 找到存储变量值的位置
saver.restore(sess, ckpt)# 加载到当前环境中
print('finish loading model!')
test_writer = tf.summary.FileWriter(log_dir + '/restore')
test_accuracy_list = []
test_loss_list = []
# test
for j in tqdm(range(test_total_batch)):
x_test_batch, y_test_batch = get_batch(test_image, test_label, batch_size, j, test_total_batch)
summary,test_accuracy,test_loss = sess.run([merge, accuracy,loss], feed_dict = {x:x_test_batch, y:y_test_batch, keep_prob:dropout_rate})
test_accuracy_list.append(test_accuracy)
test_loss_list.append(test_loss)
test_writer.add_summary(summary,j)
print('test_acc:'+ str(np.mean(test_accur