gpt4 book ai didi

python - 从 Tensorflow 中删除变量

转载 作者:太空狗 更新时间:2023-10-30 02:38:45 25 4
gpt4 key购买 nike

我正在尝试使用各种超参数进行一些深度学习实验。我分别为每个超参数设置构建模型。在对第一个超参数设置进行训练和评估后,当我尝试使用第二个设置构建新模型时,它给我一个与变量重用和东西相关的错误。

所以我想在每次实验后重置我的 session 。我该怎么做?

我试过 tf.reset_default_graph(),但是当我调用 sess.run(tf.global_variables_initializer()) 时,出现以下错误:

ValueError: Fetch argument cannot be interpreted as a Tensor. (Operation name: "init" op: "NoOp" input: "^v/Assign" is not an element of this graph.)

如何删除所有变量并和平地重置我的 session ?

最佳答案

重置默认图表后,您还需要创建一个新 session 。一个小例子:

import tensorflow as tf

hello = tf.constant('Hello, TensorFlow!')

sess = tf.Session()
print(sess.run(hello))

tf.reset_default_graph()
sess = tf.Session() # Create new session
sess.run(tf.global_variables_initializer())

关于python - 从 Tensorflow 中删除变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46039111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com