nekodesu
nekodesu

Reputation: 869

Cannot interpret feed_dict key as Tensor

I have a list of placeholders called "enqueue_ops" and a list of methods called "feed_fns", each of which returns a feed_dict.

The queue runner of my graph is defined as:

queue_runner = feeding_queue_runner.FeedingQueueRunner(
            queue=queue, enqueue_ops=enqueue_ops,
            feed_fns=feed_fns)

However I got an error of

TypeError: Cannot interpret feed_dict key as Tensor: The name 'face_detection/x1' refers to an Operation, not a Tensor. Tensor names must be of the form "<op_name>:<output_index>".

But why are they looking at my feed_dict keys, while my feed_dict values are tensors that they don't want to look at?

Thanks!!!

Upvotes: 1

Views: 9184

Answers (1)

Achintha Ihalage
Achintha Ihalage

Reputation: 2440

In tensorflow if you want to restore a graph and use it, before saving the graph you should give your desired variables, placeholders, operations etc a unique name.

For an example see below.

W = tf.Variable(0.1, name='W')
X = tf.placeholder(tf.float32, (None, 2), name='X')
mult = tf.multiply(W,X,name='mult')

Then, once the graph is saved, you could restore and use it as follows. Remember to bundle your tensors with quotation marks. And if you are finding a value of a tensor, add :0 at the end of the tensor name as tensorflow requires it to be in "op_name:output_index" format.

with tf.Session() as sess:
    new_saver = tf.train.import_meta_graph('your_model.meta')
    new_saver.restore(sess, tf.train.latest_checkpoint('./'))
    print(sess.run('mult:0', feed_dict={'X:0': [[1,4],[2,9]]}))

Upvotes: 1

Related Questions