环境:python3,tensotflow

在恢复了预先训练好的模型进行预测时,第一次是能够成功执行的,但我多次restore模型时,出现了以下问题:

1.ValueError: Variable char_embed/char_embedding already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:

解决方法参考https://www.jianshu.com/p/fc11f32800f9

2. NotFoundError (see above for traceback): Key Variable_3 not found in checkpoint

错误提示在checkpoint中没有找到Variable_3。使用以下语句查看checkpoint中的变量,发现的确没有Variable_3。而使用tf.global_variables()查看到新生成了包括Variable_3的新tensor。可参考这里了解具体过程。

解决办法:加入tf.reset_default_graph() 或参考这里进行多项查看。

import os#checkpoint文件的路径checkpoint_path=os.path.join(os.getcwd(),'ckpt1/ner.ckpt')reader=tf.train.NewCheckpointReader(checkpoint_path)var=reader.get_variable_to_shape_map()for key in var: print("tensor_name",key) #显示tensor的内容,若只想查看tensor的名称,可以下面这句注释掉,使结果更清晰 print(reader.get_tensor(key))

其中,我的/ckpt1下的文件如下:

3. 加入tf.reset_default_graph之后,出现以下报错:

Error: Do not use tf.reset_default_graph() to clear nested graphs. If you need a cleared graph, exit the nesting and create a new graph.

原因参考这里,就是说,不能在以下情况使用tf.reset_default_graph():

Inside a with graph.as_default(): block. 【在with graph.as_default(): 块下面】
Inside a with tf.Session(): block.【在with tf.Session():块下面】
Between creating a tf.InteractiveSession and calling sess.close() 【在使用了tf.InteractiveSession和调用sess.close()之间】
---------------------
作者:xxzhix
来源:CSDN
原文:https://blog.csdn.net/xxzhix/article/details/81983982
版权声明:本文为博主原创文章,转载请附上博文链接!

Linux上多次restore Tensorflow模型报错的更多相关文章

  1. 在Linux上配置xampp后远程访问域名报错

    在Linux上配置xampp后远程访问域名报错: New XAMPP security concept: Access to the requested object is only availabl ...

  2. linux上安装完torch后仍报错:ImportError: No module named torch

    linux上安装完torch后仍报错: Traceback (most recent call last): File , in <module> import torch ImportE ...

  3. Linux上tomcat部署web项目,访问报错"ip访问时间过长"

    项目原来是可以访问的,后来突然不能不访问了,系统ip也是能ping通的,后来就想是不是防火墙的问题,查看一下还真是 原因:Linux服务器上的防火墙开着,关闭即可 1.查看firewall服务状态 s ...

  4. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  5. 在PHP5.4上使用Google翻译的API报错

    /********************************************************************** * 在PHP5.4上使用Google翻译的API报错 * ...

  6. PyCharm导入tensorflow包报错的问题

    [注]PyCharm导入tensorflow包报错的问题 若是你也遇到这个问题,说明你也没有理解tensorflow到底在哪里. 当安装了anaconda3.6后,在PyCharm中设置interpr ...

  7. 在CentOS上安装node.js的时候报错:No acceptable C compiler found!解决办法

    在CentOS上安装node.js的时候报错:No acceptable C compiler found! 原因:没有c编译器. 解决办法:安装GCC 命令如下: #yum install gcc ...

  8. Windows 10 上安装 3D Studio Max 2016 报错的解决办法

    在 Windows 10 上安装 3D Stuido Max 2016 报错,无法正常安装,查看日志是 VC 运行时安装错误,经过分析发现在 Windows 10 上已经有这些运行时并且版本比安装包中 ...

  9. Linux 下使用C语言 gets()函数报错

    在Linux下,使用 gets(cmd) 函数报错:warning: the 'gets' function is dangerous and should not be used. 解决办法:采用 ...

随机推荐

  1. Installation failed: Timeout was reached: Operation timed out after 10000 milliseconds with 0 out of 0 bytes received

    Trying this option worked for me. library(httr) with_config(use_proxy(...), install_github(...)) OR ...

  2. JavaWeb基础—dbutils的简单入门

    简明入门教程,参考:https://www.cnblogs.com/CQY1183344265/p/5854418.html 进行此章节之前,介绍一个JdbcUtils的再次的简单封装 (例如后面需要 ...

  3. 微信小程序:选项卡页面切换

    一.功能描述 在同一个页面内实现不同展示页面的切换功能,如下图所示 二.代码实现 1. index.js Page({ /** * 页面的初始数据 */ data: { currentData : 0 ...

  4. setInterval只执行一次的原因

    setInterval(arrow(),) 改为: setInterval(arrow,) 原因: arrow()这是一个函数调用,函数调用就会有返回值, 而arrow()没有返回值,所以这里的arr ...

  5. Codeforces 912 E.Prime Gift (折半枚举、二分)

    题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...

  6. GitLab篇之备份还原

    1. GitLab备份配置 输入以下命令,打开gitlab配置文件 [root@code-server ~]# vim /etc/gitlab/gitlab.rb 修改以下配置,gitlab有自动清理 ...

  7. webgl绘制粗线段

    webgl1不支持设置线段宽度,这就只好通过shader来实现了,参考了踏得网的例子,引用地址:http://wow.techbrood.com/fiddle/43140.先在此感谢踏得网创始人之一 ...

  8. GitHub笔记(四)——标签管理

    五 标签管理 1 打标签.默认master $ git tag v1.0 要对add merge这次提交打标签,它对应的commit id是f52c633,敲入命令: $ git tag v0.9 f ...

  9. Netty源码分析第8章(高性能工具类FastThreadLocal和Recycler)---->第4节: recycler中获取对象

    Netty源码分析第八章: 高性能工具类FastThreadLocal和Recycler 第四节: recycler中获取对象 这一小节剖析如何从对象回收站中获取对象: 我们回顾上一小节demo的ma ...

  10. python编辑选课系统

    一.需求分析 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3. 课程包含,周期,价格,通过学校创建课 ...