tensorflow加载模型测试的两种方法

本文介绍了TensorFlow加载已训练模型的两种方法:一是通过复用训练时的完整代码,二是直接从保存的ckpt文件中恢复模型。这两种方式对于测试和应用训练好的模型十分有用。
摘要由CSDN通过智能技术生成

加载训练模型的方法:

第一种:直接赋值训练时的整个代码

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值