2017-02-22 174 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