张量流中什么是不可馈的?

2024-09-30 14:27:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试过下面的代码。但我在张量流中找不到不可喂养的东西。谁能告诉我什么是不可喂养的吗?在

#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import tensorflow as tf

x = tf.Variable(3)
y = tf.constant(3)
z = tf.add(1, 2)
with tf.Session() as sess:
    print sess.graph.is_feedable(x)
    print sess.graph.is_feedable(y)
    print sess.graph.is_feedable(z)

Tags: 代码envbinisusrtfasvim
1条回答
网友
1楼 · 发布于 2024-09-30 14:27:26

除非通过^{}方法显式地阻止它们输入,否则所有张量都是可馈的(包括常量)。可以直接或间接调用此方法,例如,^{}函数就是这样做的:

NOTE: If constant_value(tensor) returns a non-None result, it will no longer be possible to feed a different value for tensor. This allows the result of this function to influence the graph that is constructed, and permits static shape optimizations.

样本代码:

y = tf.constant(3)
tf.contrib.util.constant_value(y)  # 3

with tf.Session() as sess:
  print sess.graph.is_feedable(y)  # False!

相关问题 更多 >