如何获取变量的当前值?

编程入门 行业动态 更新时间:2024-10-12 16:21:27
本文介绍了如何获取变量的当前值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

假设我们有一个变量:

x = tf.Variable(...)

可以在训练过程中使用 assign() 方法更新此变量.

This variable can be updated during the training process using the assign() method.

获取变量当前值的最佳方法是什么?

我知道我们可以使用这个:

I know we could use this:

session.run(x)

但我担心这会触发整个操作链.

But I'm afraid this would trigger a whole chain of operations.

在 Theano 中,你可以做到

In Theano, you could just do

y = theano.shared(...)
y_vals = y.get_value()

我正在 TensorFlow 中寻找等效的东西.

I'm looking for the equivalent thing in TensorFlow.

推荐答案

一般来说,session.run(x) 只会评估计算 x 没有别的,所以如果你想检查变量的值应该相对便宜.

In general, session.run(x) will evaluate only the nodes that are necessary to compute x and nothing else, so it should be relatively cheap if you want to inspect the value of the variable.

看看这个很棒的答案https://stackoverflow/a/33610914/5543198了解更多背景信息.

Take a look at this great answer https://stackoverflow/a/33610914/5543198 for more context.

这篇关于如何获取变量的当前值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 05:25:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!