tensorflow 报错:Key Variable_4 not found in checkpoint

遇到一个问题,在实际中需要连续导入两个不同的模型,会发现有一个报错,解决方法如下


    index = getModel1(q1,q2)
    ...
    func()
    ...
    index2 = getModel2(q3,q4)
NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Key Variable_4 not found in checkpoint
	 [[node save_1/RestoreV2 (defined at Model.py:80)  = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save_1/Const_0_0, save_1/RestoreV2/tensor_names, save_1/RestoreV2/shape_and_slices)]]

导入两个tf训练好的模型过程中,出现这样一个报错,显示找不到 checkpoint,但是导入位置没有错,这个时候是由于tf运算图没有重置的原因,有人实验过证明第二次导入时候其中的变量名发生变化

 

解决只需要在前面加  

tf.reset_default_graph()

即可

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值