我剛剛更新了我的Tensorflow的本地安裝到0.11rc2,我得到一個消息,說我要一個參數添加到我的保護,使其在2版本保存我更新了這個,現在我不能加載以此格式保存的模型。當我運行我的模型時,它在每個時代都會保存。當它保存,它用於保存文件名爲translate.ckpt-3916
和translate.ckpt-3916.meta
。現在,我得到三個文件,而不是兩個,命名爲translate.ckpt-3916.index
,translate.ckpt-3916.meta
和translate.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)]]