2016-11-07 64 views
2

我刚刚更新了我的Tensorflow的本地安装到0.11rc2,我得到一个消息,说我要一个参数添加到我的保护,使其在2版本保存我更新了这个,现在我不能加载以此格式保存的模型。当我运行我的模型时,它在每个时代都会保存。当它保存,它用于保存文件名为translate.ckpt-3916translate.ckpt-3916.meta。现在,我得到三个文件,而不是两个,命名为translate.ckpt-3916.indextranslate.ckpt-3916.metatranslate.ckpt-3916.data-000000-of-000001与节电器V2 Tensorflow加载模型

加载数据,我用下面的代码:

ckpt = tf.train.get_checkpoint_state(FLAGS.train_dir) 
    if ckpt and tf.gfile.Exists(ckpt.model_checkpoint_path): 
     print("Reading model parameters from %s" % ckpt.model_checkpoint_path) 
     model.saver.restore(session, ckpt.model_checkpoint_path) 
    else: 
     print("Created model with fresh parameters.") 
     session.run(tf.initialize_all_variables()) 
return model 

哪里model是已经跟我程序的标准超参数初始化的模型对象。这对于保存者v1而言没有问题。 ckpt.model_checkpoint_path计算结果为路径translate.ckpt-3916不论版本,所以如果检查点被保存V2,没有找到文件。 (当保存任一版本)的checkpoint文件在该目录中的

内容是:

model_checkpoint_path: "translate.ckpt-3916" 
all_model_checkpoint_paths: "translate.ckpt-3916" 

有加载与保护V2数据的新方法?否则,我如何加载我的检查点?

编辑: 更改线路if ckpt and tf.gfile.Exists(ckpt.model_checkpoint_path):if ckpt and ckpt.model_checkpoint_path:喜欢this question显示似乎有点进一步工作,但随后引发以下错误:

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [84] rhs shape= [98] 
[[Node: save/Assign_54 = Assign[T=DT_FLOAT, _class=["loc:@NLC/Logistic/Linear/Bias"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](NLC/Logistic/Linear/Bias, save/RestoreV2_54)]] 

回答

2

我贴在我的编辑方法实际上是正确的方法让这个工作。我得到的错误是因为数据在我制作检查点时和我试图加载时发生了变化。

只是为了使其可见,从上面的代码通过改变线路if ckpt and tf.gfile.Exists(ckpt.model_checkpoint_path):做了V2关卡加载到if ckpt and ckpt.model_checkpoint_path: