问题描述
限时送ChatGPT账号..我想在 Tensorflow 中使用 MomentumOptimizer
.然而,由于这个优化器使用了一些内部变量,尝试在不初始化这个变量的情况下使用它会产生一个错误:
I want to use MomentumOptimizer
in Tensorflow. However, since this optimizer uses some internal variable, attempting to use it without initializing this variable yields an error:
FailedPreconditionError
(回溯见上文):尝试使用未初始化的值 Variable_2/Momentum
FailedPreconditionError
(see above for traceback): Attempting to use uninitialized valueVariable_2/Momentum
这可以通过初始化所有变量来轻松解决,例如使用
This can be easily solved by initializing all variables, using for example
tf.global_variables_initializer().run()
但是,我不想初始化所有变量 - 只初始化优化器的变量.有没有办法做到这一点?
However, I do not want to initialize all the variables - only those of optimizer. Is there any way to do this?
推荐答案
还有一个更直接的方法:
There is a more straightforward way:
optimizer = tf.train.AdamOptimizer()
session.run(tf.variables_initializer(optimizer.variables()))
这篇关于如何在 Tensorflow 中仅初始化优化器变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论