I come across this error when I run the following code, trying to get prediction on test data. By printing out operation names, I see no operation named Placeholder_4
, and can see an op named prediction_output
with tf.Session() as sess:
imported_meta = tf.train.import_meta_graph("test-model-220.meta")
imported_meta.restore(sess, tf.train.latest_checkpoint('./'))
graph = tf.get_default_graph()
for op in graph.get_operations():
print(op.name)
batch_size = tf.placeholder(tf.int64)
a, b = tf.placeholder(tf.float32, shape=[None, len(X)]), tf.placeholder(tf.float32, shape=[None, 8])
train_dataset = tf.data.Dataset.from_tensor_slices((a, b)).batch(batch_size).repeat()
test_dataset = tf.data.Dataset.from_tensor_slices((a, b)).batch(batch_size)
iterator = tf.data.Iterator.from_structure(train_dataset.output_types, train_dataset.output_shapes)
features, labels = iterator.get_next()
# create the initialisation operations
training_init_op = iterator.make_initializer(train_dataset)
test_init_op = iterator.make_initializer(test_dataset)
# a = tf.placeholder(tf.float32, shape=[None, len(X)])
sess.run(test_init_op)
pred = graph.get_tensor_by_name("prediction_output:0")
prediction = sess.run(pred, feed_dict={a: X, b: [[1, 1, 1, 1, 1, 1, 1, 1]], batch_size: 1})
# print(prediction)
Stack trace of error:
Traceback (most recent call last):
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 1322, in _do_call
return fn(*args)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 1307, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 1409, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_4' with dtype float and shape [?,1]
[[Node: Placeholder_4 = Placeholder[dtype=DT_FLOAT, shape=[?,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/akshar.b/pythonfiles/Extract_Coordinates/restore.py", line 70, in <module>
sess.run(test_init_op)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 900, in run
run_metadata_ptr)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 1135, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 1316, in _do_run
run_metadata)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\client\session.py", line 1335, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_4' with dtype float and shape [?,1]
[[Node: Placeholder_4 = Placeholder[dtype=DT_FLOAT, shape=[?,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'Placeholder_4', defined at:
File "C:/Users/akshar.b/pythonfiles/Extract_Coordinates/restore.py", line 56, in <module>
a, b = tf.placeholder(tf.float32, shape=[None, len(X)]), tf.placeholder(tf.float32, shape=[None, 8])
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1808, in placeholder
return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 5835, in placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 3392, in create_op
op_def=op_def)
File "C:\Users\akshar.b\PycharmProjects\hello\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 1718, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_4' with dtype float and shape [?,1]
[[Node: Placeholder_4 = Placeholder[dtype=DT_FLOAT, shape=[?,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]