2017-02-22 62 views
1

我有一个在Tensorflow r0.12训练的一个模式,即使用SaverV2创建检查点文件。我的模型是从tensorflow.python.ops的RNN利用的rnn_cellrnn_cell.GRUCell。由于更改为1.0,这个包已经根据this answer更新Tensorflow检查文件到1.0

搬到core_rnn_cell_impltensorflow.contrib.rnn.python.ops我从heretf_update.py文件到我的档案更新到新版本。但是,自更新以来,我的旧检查点文件不起作用。这似乎有些由新GRUCell实施所需的变量不存在或有不同的名称。

实施例的错误(有132个这样的错误):

2017-02-22 11:36:08.037315: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights not found in checkpoint 
2017-02-22 11:36:08.037382: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights/Adam not found in checkpoint 
2017-02-22 11:36:08.037494: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases/Adam not found in checkpoint 
2017-02-22 11:36:08.037499: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/candidate/weights/Adam_1 not found in checkpoint 
2017-02-22 11:36:08.037538: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights not found in checkpoint 
2017-02-22 11:36:08.037615: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases not found in checkpoint 
2017-02-22 11:36:08.037618: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/biases/Adam_1 not found in checkpoint 
2017-02-22 11:36:08.038098: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights/Adam_1 not found in checkpoint 
2017-02-22 11:36:08.038121: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderAttnCell/gru_cell/gates/weights/Adam not found in checkpoint 
2017-02-22 11:36:08.038222: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/biases not found in checkpoint 
2017-02-22 11:36:08.038229: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/weights not found in checkpoint 
2017-02-22 11:36:08.038233: W tensorflow/core/framework/op_kernel.cc:993] Not found: Key NLC/Decoder/DecoderCell0/gru_cell/candidate/biases/Adam_1 not found in checkpoint 

保存/载入完美地工作,直到更新。我能做些什么来将旧的检查点文件更新为r1.0?

如果它的事项,我使用python2.7和使用或者仅CPU tensorflow或tensorflow使用CUDA时,会发生同样的错误。

回答

4

有没有简单的方法来做到这一点...一个方法是使用get_variable_to_shape_map()

ckpt_reader = tf.train.NewCheckpointReader(filepath) 
    ckpt_vars = ckpt_reader.get_variable_to_shape_map() 

,这将使你的变量名的列表中已保存的检查点的形状。然后......创建一个从旧名称映射到新名称的字典即

old_to_new={} 
old_to_new[old_name] = new_name 

然后instantitate金丹和恢复只是那些瓦尔

saver = tf.Saver(old_to_new) 
saver.restore(filepath) 

祝你好运,希望这有助于。

+0

感谢明确的答案。我想我只是为了简单而重新训练模型,但我很高兴有一种方法可以做到这一点。 – jbird