美文网首页
NotFoundError (see above for tra

NotFoundError (see above for tra

作者: Xfyyzy | 来源:发表于2019-05-10 10:26 被阅读0次

    在restore已训练好模型的时候,验证第二张图片时报以下错误

    NotFoundError (see above for traceback): Key Variable_10 not found in checkpoint

    原因:

    保存在checkpoint中的变量如weights的变量名为weights,
    预测第一张图片时,weights的name="weights";
    预测第二张时,模型再次加载,weights也第二次加载,但是name="weights"已经存在,name会变成"weights_2",但是找不到这个变量名,于是报错。
    详细见https://blog.csdn.net/l18930738887/article/details/69808692

    解决方案:

    在每一次预测结束后加上tf.reset_default_graph()

    读取多张图片并进行预测

    test_pics_dir ="./test_pics"
    files = os.listdir(test_pics_dir)
    for file in files:
        pre_pic_path = test_pics_dir+"/"+file
        image = predict(pre_pic_path)
        y_predict = get_result(image)
        print("真实值:",p_true,"预测值为:",y_predict)
        #重新定义默认图
        tf.reset_default_graph()
    

    tf.reset_default_graph函数用于清除默认图形堆栈并重置全局默认图形

    相关文章

      网友评论

          本文标题:NotFoundError (see above for tra

          本文链接:https://www.haomeiwen.com/subject/hpjooqtx.html