2017-02-22 170 views
1

我正在使用Windows GPU tensorflow 1.0。我想刪除無用或錯誤的變量。如何刪除已存在的tensorflow變量?

For example I run code and generate a bad model, then I copy code and just modify existed variable W1(shape=[3,3],name="W1") as W1(shape=[5,5],name="W1") and run. 

However tensorflow generate W1(shape=[5,5],name="W1_1") rather than replace old W1. So in the end Tensorflow will save both wrong trained W1(name='w1') and trained w1(name='w1_1'). When I restore W1, tensorflow give me wrong trained W1(name='w1').  

你能告訴我如何刪除舊的變量W1並添加新的W1?

(換行符編輯功能是沒用的)

+0

以更清潔的方式重新表達。我不明白你的意思。提供一些重現問題的代碼。 – fabrizioM

回答

0

首先,我不知道你想改變你的變量的形狀達到什麼。如果您以這種方式問我們這個問題,我們知道您的意圖,也許我們可以幫助您更好。

現在有多種選擇來解決問題: - 忽略了你的變量名(不會造成什麼錯誤?) - 清除所有變量:https://www.tensorflow.org/versions/master/api_docs/python/framework/utility_functions#reset_default_graph - 更改變量的形狀,而不是定義的新的一個。在這裏查看mrry的答案:How can I change the shape of a variable in TensorFlow?

+0

我重寫我的問題。總而言之,我想要精確處理每個變量。似乎沒有辦法修改已存在的變量。也許我必須清除所有變量並重新啓動。你的答案是有幫助的。 – artzers

+0

謝謝!祝你好運! – rmeertens