Tensorflow Placeholder is not an element of this graph
By : Jack N
Date : March 29 2020, 07:55 AM
it helps some times I believe you have a plain old Python scope problem here. You define x in the __init__ method but nowhere is the value x passed to anyone. When you get to code :
feed_dict_train = {x: x_batch,
y_true: y_true_batch}

Tensorflow graph with multiple inputs wihtout tf.placeholder for validation
By : Francuskuspaiman Uni
Date : March 29 2020, 07:55 AM

tensorflow pass numpy array to graph using placeholder vs tf.convert_to_tensor()
By : MiNet
Date : March 29 2020, 07:55 AM
hop of those help? tf_convert_to_tensor is highly unpractical because it does not scale. See the example below: code :
X = np.random.rand(3,3)
Y = np.random.rand(3,3)
X_tensor = tf.convert_to_tensor(X)
X_squared = tf.square(X_tensor)
Y_tensor = tf.convert_to_tensor(Y)
Y_squared = tf.square(Y)
with tf.Session() as sess:
x = sess.run(X_squared)
y = sess.run(Y_squared)
X = np.random.rand(3,3)
Y = np.random.rand(3,3)
graph_input = tf.placeholder(shape=[None, None], dtype=tf.float64)
squared = tf.square(graph_input)
with tf.Session() as sess:
x = sess.run(squared, feed_dict={graph_input: X})
y = sess.run(squared, feed_dict={graph_input: Y})

Tensorflow Graph  check if a node depends on a placeholder
By : user3191042
Date : March 29 2020, 07:55 AM
it helps some times Checking dependency between tensors in a graph can be done with a function like this: code :
import tensorflow as tf
# Checks if tensor a depends on tensor b
def tensor_depends(a, b):
if a.graph is not b.graph:
return False
gd = a.graph.as_graph_def()
gd_sub = tf.graph_util.extract_sub_graph(gd, [a.op.name])
return b.op.name in {n.name for n in gd_sub.node}
import tensorflow as tf
x = tf.placeholder(name='X', dtype=tf.int64, shape=[])
y = tf.placeholder(name='Y', dtype=tf.int64, shape=[])
p = tf.add(x, y)
q = tf.add(x, x)
print(tensor_depends(q, x))
# True
print(tensor_depends(q, y))
# False

Tensorflow: Replacing/feeding a placeholder of a graph with tf.Variable?
By : peter zhu
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a model M1 whose data input is a placeholder M1.input and whose weights are trained. My goal is to build a new model M2 which computes the output o of M1 (with its trained weights) from an input w in a form of tf.Variable (instead of feeding actual values to M1.input). In other words, I use the trained model M1 as a blackbox function to build a new model o = M1(w) (in my new model, w is to be learned and the weights of M1 are fixed as constants). The problem is that M1 only accepts as its input M1.input through which we need to feed actual values, not a tf.Variable like w. , This is possible. What about: code :
import tensorflow as tf
def M1(input, reuse=False):
with tf.variable_scope('model_1', reuse=reuse):
param = tf.get_variable('param', [1])
o = input + param
return o
w = tf.get_variable('some_w', [1])
plhdr = tf.placeholder_with_default(w, [1])
output_m1 = M1(plhdr)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(w.assign([42]))
print(sess.run(output_m1, {plhdr: [0]})) # direct from placeholder
print(sess.run(output_m1)) # direct from variable

