簡體   English   中英

在Tensorflow中保存和恢復Experimenter / Estimator

[英]Save and restore Experimenter/Estimator in Tensorflow

我正在編寫一個訓練4個神經網絡並收集其結果以找到更好結果的程序。 我將使用集成方法來執行此操作,但問題不關乎它。

問題是在訓練過程后恢復每個模型。 我發現了另一個問題 ,但這根本沒有幫助。

(偽)代碼

我的英語不太好,所以我將嘗試使用偽python代碼解釋我的工作流程:

for i in range(4):
    # Create the estimator (a DNNClassifier).
    estimator = build_estimator(...)
    # Train the model.
    estimator.fit(input_fn=...)

# Do other stuffs...

for i in range(4):
    # Restore the estimator using the same arguments.
    estimator = build_estimator(...)
    # Predict the input data.
    predictions[i] = estimator.predict(input_fn=...)

    # Do others stuffs using the predictions collection.

錯誤

從廣義上講,這就是我的代碼,即使它看起來不錯且簡單明了,也無法正常工作。 在還原期間會顯示此錯誤,這表示我的DNN未正確保存。

2017-07-24 11:40:24.517773: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/hiddenlayer_1/weights not found in checkpoint
2017-07-24 11:40:24.517884: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/hiddenlayer_0/biases not found in checkpoint
2017-07-24 11:40:24.518739: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/hiddenlayer_0/weights not found in checkpoint
2017-07-24 11:40:24.519621: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/logits/biases not found in checkpoint
2017-07-24 11:40:24.519684: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/hiddenlayer_1/biases not found in checkpoint
2017-07-24 11:40:24.519861: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/hiddenlayer_2/weights not found in checkpoint
2017-07-24 11:40:24.519947: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/hiddenlayer_2/biases not found in checkpoint
2017-07-24 11:40:24.522592: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\framework\op_kernel.cc:1158] Not found: Key dnn/logits/weights not found in checkpoint

注意

  1. 已使用相同的參數創建並還原了DNNClassifier。
  2. 據我所知,我不需要保存任何檢查點,因為DNNClassifier在訓練過程中會這樣做。
  3. 我讀的地方,之前使用predictevaluation是必要的。 我嘗試過,但是什么都沒有改變。
  4. 如果您願意,我可以共享代碼的其他片段,但是我認為這對您沒有更多幫助。

您應該這樣創建模型:

estimator = tf.contrib.learn.DNNClassifier(feature_columns = feature_cols,hidden_​​units = [10,10,10],n_classes = 2,model_dir = your_path)

estimator.fit(input_fn = lambda:input_fn1(訓練數據),步長= 1000)

estimator_predict = estimator.predict(input_fn = lambda:input_fn1(test_data))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM