2017-08-08 37 views
0

我正在與使用Tensorflow的指針生成網絡相關的斯坦福存儲庫。這個倉庫可以在這裏找到:
https://github.com/abisee/pointer-generatorTensorflow Checkpoint在另一個系統上使用時不會產生問題。 Python2/3

我已經在這個倉庫的問題,部分要求演示關卡和人名的喜悅一個人回答我,他的實驗的檢查點。你可以在這裏看到:
https://github.com/abisee/pointer-generator/issues/12#issuecomment-320558080

現在,當我與運行的代碼檢查點,我收到以下異常或錯誤:

INFO:tensorflow:Loading checkpoint log/directory/myexperiment/train/model.ckpt-44550 
INFO:tensorflow:Restoring parameters from log/directory/myexperiment/train/model.ckpt-44550 
2017-08-08 11:40:45.466505: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/decoder/attention_decoder/lstm_cell/bias not found in checkpoint 
2017-08-08 11:40:45.468174: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/decoder/attention_decoder/lstm_cell/kernel not found in checkpoint 
2017-08-08 11:40:45.475224: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/bw/lstm_cell/kernel not found in checkpoint 
2017-08-08 11:40:45.475255: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/bw/lstm_cell/bias not found in checkpoint 
2017-08-08 11:40:45.488580: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/fw/lstm_cell/bias not found in checkpoint 
2017-08-08 11:40:45.489057: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/fw/lstm_cell/kernel not found in checkpoint 
INFO:tensorflow:Failed to load checkpoint from log/directory/myexperiment/train. Sleeping for 10 secs... 
INFO:tensorflow:Loading checkpoint log/directory/myexperiment/train/model.ckpt-44550 
INFO:tensorflow:Restoring parameters from log/directory/myexperiment/train/model.ckpt-44550 
2017-08-08 11:40:55.630779: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/decoder/attention_decoder/lstm_cell/kernel not found in checkpoint 
2017-08-08 11:40:55.631279: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/decoder/attention_decoder/lstm_cell/bias not found in checkpoint 
2017-08-08 11:40:55.645013: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/bw/lstm_cell/bias not found in checkpoint 
2017-08-08 11:40:55.651307: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/fw/lstm_cell/bias not found in checkpoint 
2017-08-08 11:40:55.654461: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/bw/lstm_cell/kernel not found in checkpoint 
2017-08-08 11:40:55.661814: W tensorflow/core/framework/op_kernel.cc:1158] Not found: Key seq2seq/encoder/bidirectional_rnn/fw/lstm_cell/kernel not found in checkpoint 

所以我想檢查是否問題的原因是GPU或CPU一個所以就用從問題的答案的溶液:)

2)Can a model trained on gpu used on cpu for inference and vice versa?

我TR以使文件run_summarization.py中的更改爲:

def setup_training(model, batcher): 
    """Does setup before starting training (run_training)""" 
    train_dir = os.path.join(FLAGS.log_root, "train") 
    if not os.path.exists(train_dir): os.makedirs(train_dir) 

    default_device = tf.device('/gpu:0') #tf.device('/cpu:0') 
    with default_device: 
    model.build_graph() # build the graph 
    if FLAGS.convert_to_coverage_model: 
     assert FLAGS.coverage, "To convert your non-coverage model to a coverage model, run with convert_to_coverage_model=True and coverage=True" 
     convert_to_coverage_model() 
    saver = tf.train.Saver(max_to_keep=1) # only keep 1 checkpoint at a time 

但它沒有工作。請讓我知道我需要做什麼來使張量流檢查點在任何帶有可用代碼的系統上運行。如果可能的話,不要更改代碼。

回答

0

您似乎正在運行eval模式。這需要與列車模式並行運行。 信息:tensorflow:從日誌/目錄/ myexperiment/train/model.ckpt -44550恢復參數

此行意味着您的檢查點已加載,保存程序恢復了會話。你可以看一下utils.py文件中的load_ckpt函數。你是否爲train和eval運行同一個模型?在這種情況下使用cpu或gpu不會影響它。如果在指針生成器FLAG中沒有提及,那麼它運行基線seq2seq模型

+0

實際上,訓練過的模型是已經從一些其他人的計算機上訓練過來的,在我的情況下,這個快樂給了我。我只是想把它和我的系統連接起來。 –

1

我能夠使用下面的代碼將檢查點加載到會話中,希望它可以幫助。所有的變量和相應的訓練值被恢復。

import tensorflow as tf 

config = tf.ConfigProto(allow_soft_placement=True) 
with tf.Session(config=config) as sess: 
    new_saver = tf.train.import_meta_graph(
     '/path/to/model.ckpt-44550.meta') 
    new_saver.restore(sess, '/path/to/model.ckpt-44550') 
    g = tf.get_default_graph() 
print('model_loaded') 
+0

我需要在當前代碼中進行更改..是run_summary.py?你如何運行代碼..請稍微解釋一下..它對我有幫助。 –

+0

另外我正在使用tensorflow的最新版本。你使用的版本是什麼? –

+0

我使用'tf = 1.2.0'。看來你需要chnage這些行https://github.com/abisee/pointer-generator/blob/master/run_summarization.py#L105-109 –