Python 还原Tensorflow检查点文件时出错
在tensorflow中使用Python 还原Tensorflow检查点文件时出错,python,tensorflow,Python,Tensorflow,在tensorflow中使用saver.restore()方法时出现以下错误。知道为什么会这样吗 我这样保存模型: saver.save(sess、检查点路径、全局步骤=步骤) 错误是: tensorflow.python.framework.errors.InvalidArgumentError: Node 'Variable_1/Assign': Unknown input node Variable_1 [[Node: Variable_1/initial_value = Con
saver.restore()
方法时出现以下错误。知道为什么会这样吗
我这样保存模型:
saver.save(sess、检查点路径、全局步骤=步骤)
错误是:
tensorflow.python.framework.errors.InvalidArgumentError: Node 'Variable_1/Assign': Unknown input node Variable_1
[[Node: Variable_1/initial_value = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [] values: 0.9>]()]]
您试图加载原始网络中不存在的变量,我相信省略
v1 = tf.Variable(0)
这将解决问题
如果要添加新变量,则需要以不同方式加载,加载方法应如下所示:
reader = tf.train.NewCheckpointReader(os.path.join(checkpoint_dir, ckpt_name))
restore_dict = dict()
for v in tf.trainable_variables():
tensor_name = v.name.split(':')[0]
if reader.has_tensor(tensor_name):
print('has tensor ', tensor_name)
restore_dict[tensor_name] = v
# put the logic of the new/modified variable here and assign to the restore_dict, i.e.
# restore_dict['my_var_scope/my_var'] = get_my_variable()
@mrry如果您在此处看到任何错误,请告诉我尝试为每个变量定义一个名称,可能是加载检查点时自动生成的变量名称不同。
v1 = tf.Variable(0)
reader = tf.train.NewCheckpointReader(os.path.join(checkpoint_dir, ckpt_name))
restore_dict = dict()
for v in tf.trainable_variables():
tensor_name = v.name.split(':')[0]
if reader.has_tensor(tensor_name):
print('has tensor ', tensor_name)
restore_dict[tensor_name] = v
# put the logic of the new/modified variable here and assign to the restore_dict, i.e.
# restore_dict['my_var_scope/my_var'] = get_my_variable()