Skip to main content
 首页 » 编程设计

python之tensorflow 中什么是不可馈送的

2024年08月19日30EasonJim

我试过下面的代码。但我没有发现在 tensorflow 中有什么是不可喂养的。谁能告诉我什么是不能喂食的?

#!/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) 

请您参考如下方法:

所有张量都是可馈送的(包括常量,如您所见),除非明确阻止它们通过 tf.Graph.prevent_feeding 馈送方法。可以直接或间接调用此方法,例如tf.contrib.util.constant_value。功能:

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!