Generating multiple Tensorboard directories - python

I'm trying to run the same training and Test in a loop, while changing some parameters. Each time the training is done, Tensorflow sould generate a new Tensorboard directory.
And that's exactly the problem I have:
........................
def generatingTBFolder(index):
global TB_Folder
TB_Folder ='TB_Graphs_'+str(index)
with tf.device('/cpu:0'):
for k in range(2,5):## here is the problem
generatingTBFolder(k)
train(k,numberOFclasses)
I don't use a loop like :
with tf.device('/cpu:0'):
generatingTBFolder(3)
train(3,numberOFclasses)
the program works fine and generate a TB folder with the result. but using the loop delivers the following :
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1038 try:
-> 1039 return fn(*args)
1040 except errors.OpError as e:
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
1020 feed_dict, fetch_list, target_list,
-> 1021 status, run_metadata)
1022
c:\users\engine\appdata\local\programs\python\python35\lib\contextlib.py in __exit__(self, type, value, traceback)
65 try:
---> 66 next(self.gen)
67 except StopIteration:
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()
465 compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466 pywrap_tensorflow.TF_GetCode(status))
467 finally:
InvalidArgumentError: You must feed a value for placeholder tensor 'input/Features_values' with dtype float
[[Node: input/Features_values = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-2-54a526dfc682> in <module>()
238 for k in range(2,5):
239 generatingTBFolder(k)
--> 240 train(k,numberOFclasses)
<ipython-input-2-54a526dfc682> in train(numberOfFeatures, numberOFclasses)
208 for i in range(max_steps):
209 if i%5 ==0: # Record summarie and Test-set accruracy
--> 210 summary, acc = sess.run([merged,accuracy], feed_dict=feed_dict(False))
211 #summary, acc = sess.run([merged,accuracy], feed_dict={x:np.reshape(Test_Frame.values[:,indices[0:numberOfFeatures]],[len(Test_Frame),numberOfFeatures]),y_:np.asarray(Test_Frame.iloc[:,-1]),keep_prob:0.9})
212 test_writer.add_summary(summary,i)
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
776 try:
777 result = self._run(None, fetches, feed_dict, options_ptr,
--> 778 run_metadata_ptr)
779 if run_metadata:
780 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
980 if final_fetches or final_targets:
981 results = self._do_run(handle, final_targets, final_fetches,
--> 982 feed_dict_string, options, run_metadata)
983 else:
984 results = []
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1030 if handle is None:
1031 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1032 target_list, options, run_metadata)
1033 else:
1034 return self._do_call(_prun_fn, self._session, handle, feed_dict,
c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1050 except KeyError:
1051 pass
-> 1052 raise type(e)(node_def, op, message)
1053
1054 def _extend_graph(self):
InvalidArgumentError: You must feed a value for placeholder tensor 'input/Features_values' with dtype float
[[Node: input/Features_values = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'input/Features_values', defined at:
File "c:\users\engine\appdata\local\programs\python\python35\lib\runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\engine\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
app.launch_new_instance()
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
app.start()
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
ioloop.IOLoop.instance().start()
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start
super(ZMQIOLoop, self).start()
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tornado\ioloop.py", line 887, in start
handler_func(fd_obj, events)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
return self.dispatch_shell(stream, msg)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelbase.py", line 228, in dispatch_shell
handler(stream, idents, msg)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\kernelbase.py", line 390, in execute_request
user_expressions, allow_stdin)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\ipykernel\zmqshell.py", line 501, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\IPython\core\interactiveshell.py", line 2717, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\IPython\core\interactiveshell.py", line 2821, in run_ast_nodes
if self.run_code(code, result):
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-54a526dfc682>", line 240, in <module>
train(k,numberOFclasses)
File "<ipython-input-1-54a526dfc682>", line 90, in train
x =tf.placeholder(tf.float32,[None,numberOfFeatures],name='Features_values')
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1507, in placeholder
name=name)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 1997, in _placeholder
name=name)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 768, in apply_op
op_def=op_def)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "c:\users\engine\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1228, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'input/Features_values' with dtype float
[[Node: input/Features_values = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
I've already seen this error, when I start a Tensorflow program and it crashes because of shape error or any non syntax error, starting the same program without restarting the python kernel delivers that the same error message.
The problem no is I really need to do that in a loop ( 500 is the actual limit) so there is no way to do it manually.
Any idea how may I solve this ?

I found a workaround to this issue, by starting the whole script using another one, that uses a loop:
if __name__ == "__main__" :
with tf.device('/cpu:0'):
print("Got ", int(sys.argv[1]))
generatingTBFolder(int(sys.argv[1]))
train(int(sys.argv[1]),numberOFclasses)
And here is the script:
import os
for i in range(2,456):
command="python TensorCode.py "+str(i)
os.system(command)
the result looks good in Tensorboard.
hope this may helps someone out there !

Related

Getting "InvalidArgumentError" in TensorFlow when working on MNIST data

I'm following a Udemy course and a beginner with CNN with TensorFlow. When I'm running a session I'm getting InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10] error.
with tf.Session() as sess:
sess.run(init)
for step in range(1000):
batch_x, batch_y = mnist.train.next_batch(100)
sess.run(train, feed_dict={x:batch_x, y:batch_y})
# Evaluate the model
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_true,1))
# Output will be like [True, False, True.....] --> Cast to [1.0, 0.0, 1.0.....]
acc = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
print(sess.run(acc,feed_dict={x:mnist.test.images,y_true:mnist.test.labels}))
I'm getting the following error.
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1326 try:
-> 1327 return fn(*args)
1328 except errors.OpError as e:
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
1305 feed_dict, fetch_list, target_list,
-> 1306 status, run_metadata)
1307
~/anaconda3/envs/tfdeeplearning/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
65 try:
---> 66 next(self.gen)
67 except StopIteration:
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status()
465 compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466 pywrap_tensorflow.TF_GetCode(status))
467 finally:
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]
[[Node: Placeholder_1 = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-30-1df33799cd1a> in <module>()
7 batch_x, batch_y = mnist.train.next_batch(100)
8
----> 9 sess.run(train, feed_dict={x:batch_x, y:batch_y})
10
11 # Evaluate the model
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
893 try:
894 result = self._run(None, fetches, feed_dict, options_ptr,
--> 895 run_metadata_ptr)
896 if run_metadata:
897 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1122 if final_fetches or final_targets or (handle and feed_dict_tensor):
1123 results = self._do_run(handle, final_targets, final_fetches,
-> 1124 feed_dict_tensor, options, run_metadata)
1125 else:
1126 results = []
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1319 if handle is None:
1320 return self._do_call(_run_fn, self._session, feeds, fetches, targets,
-> 1321 options, run_metadata)
1322 else:
1323 return self._do_call(_prun_fn, self._session, handle, feeds, fetches)
~/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1338 except KeyError:
1339 pass
-> 1340 raise type(e)(node_def, op, message)
1341
1342 def _extend_graph(self):
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]
[[Node: Placeholder_1 = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'Placeholder_1', defined at:
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 477, in start
ioloop.IOLoop.instance().start()
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 177, in start
super(ZMQIOLoop, self).start()
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tornado/ioloop.py", line 888, in start
handler_func(fd_obj, events)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
handler(stream, idents, msg)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel/ipkernel.py", line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/ipykernel/zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2698, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2802, in run_ast_nodes
if self.run_code(code, result):
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-23-12e74ec33d57>", line 2, in <module>
y_true = tf.placeholder(tf.float32, shape=[None, 10])
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/ops/array_ops.py", line 1548, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2094, in _placeholder
name=name)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Users/majain/anaconda3/envs/tfdeeplearning/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1204, 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_1' with dtype float and shape [?,10]
[[Node: Placeholder_1 = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
`
The dimensions of y_true and mnist.test.labels should be consistent.Hope can help you.
It looks like, you haven't initialized the placeholder variables.
Tensorflow constructs a computation graph by using statements that you have written.
So when you write:
sess.run(acc,feed_dict={x:mnist.test.images,y_true:mnist.test.labels})
TensorFlow searches what all things it requires to calculate acc and recursively it looks for other variables.
The error tells that one of the placeholder variable isn't initialized or initialized in a wrong way.
You are feeding wrong variable names in feed_dict. Tensorflow is looking for y_true for computing cross_entropy step but you are feeding it "y". Make following change Computation graph sess.run(train, feed_dict={x:batch_x, y_true:batch_y})

Python - TensorArray has size zero, but element shape [?,128] is not fully defined

Trying to run: https://github.com/huseinzol05/Stock-Prediction-Models/blob/master/deep-learning/17.lstm-seq2seq-bidirectional-attention.ipynb
With the data: https://gist.github.com/TensorTom/d37f4bd605d6a13dfc75015c5e150b82
But this happens during training epochs (Or just at or after the last epoch):
---------------------------------------------------------------------------
UnimplementedError Traceback (most recent call last)
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1333 try:
-> 1334 return fn(*args)
1335 except errors.OpError as e:
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1318 return self._call_tf_sessionrun(
-> 1319 options, feed_dict, fetch_list, target_list, run_metadata)
1320
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1406 self._session, options, feed_dict, fetch_list, target_list,
-> 1407 run_metadata)
1408
UnimplementedError: TensorArray has size zero, but element shape [?,128] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[{{node decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3}}]]
[[{{node decoder/bidirectional_rnn/bw/bw/while/Exit_3}}]]
During handling of the above exception, another exception occurred:
UnimplementedError Traceback (most recent call last)
<ipython-input-8-07a23d0b1dbd> in <module>
22 modelnn.X: np.expand_dims(df_log.iloc[upper_b:], axis = 0),
23 modelnn.backward_hidden_layer: init_value_backward,
---> 24 modelnn.forward_hidden_layer: init_value_forward,
25 },
26 )
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
927 try:
928 result = self._run(None, fetches, feed_dict, options_ptr,
--> 929 run_metadata_ptr)
930 if run_metadata:
931 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1150 if final_fetches or final_targets or (handle and feed_dict_tensor):
1151 results = self._do_run(handle, final_targets, final_fetches,
-> 1152 feed_dict_tensor, options, run_metadata)
1153 else:
1154 results = []
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1326 if handle is None:
1327 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1328 run_metadata)
1329 else:
1330 return self._do_call(_prun_fn, handle, feeds, fetches)
/usr/lib/python3.7/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1346 pass
1347 message = error_interpolation.interpolate(message, self._graph)
-> 1348 raise type(e)(node_def, op, message)
1349
1350 def _extend_graph(self):
UnimplementedError: TensorArray has size zero, but element shape [?,128] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[node decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
[[node decoder/bidirectional_rnn/bw/bw/while/Exit_3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
Caused by op 'decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3', defined at:
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.7/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/usr/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 505, in start
self.io_loop.start()
File "/usr/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 132, in start
self.asyncio_loop.run_forever()
File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
self._run_once()
File "/usr/lib/python3.7/asyncio/base_events.py", line 1775, in _run_once
handle._run()
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/lib/python3.7/site-packages/tornado/ioloop.py", line 758, in _run_callback
ret = callback()
File "/usr/lib/python3.7/site-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1233, in inner
self.run()
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 370, in dispatch_queue
yield self.process_one()
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 346, in wrapper
runner = Runner(result, future, yielded)
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1080, in __init__
self.run()
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 357, in process_one
yield gen.maybe_future(dispatch(*args))
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 267, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/usr/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 534, in execute_request
user_expressions, allow_stdin,
File "/usr/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/usr/lib/python3.7/site-packages/ipykernel/ipkernel.py", line 294, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/lib/python3.7/site-packages/ipykernel/zmqshell.py", line 536, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2819, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2845, in _run_cell
return runner(coro)
File "/usr/lib/python3.7/site-packages/IPython/core/async_helpers.py", line 67, in _pseudo_sync_runner
coro.send(None)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3020, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3185, in run_ast_nodes
if (yield from self.run_code(code, result)):
File "/usr/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-6-2e75d5202b26>", line 2, in <module>
modelnn = Model(0.01, num_layers, df_log.shape[1], size_layer, df_log.shape[1], dropout_rate)
File "<ipython-input-5-7fc0ccd4ec49>", line 97, in __init__
dtype = tf.float32,
File "/usr/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 443, in bidirectional_dynamic_rnn
time_major=time_major, scope=fw_scope)
File "/usr/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 671, in dynamic_rnn
dtype=dtype)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 883, in _dynamic_rnn_loop
final_outputs = tuple(ta.stack() for ta in output_final_ta)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/rnn.py", line 883, in <genexpr>
final_outputs = tuple(ta.stack() for ta in output_final_ta)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 1128, in stack
return self._implementation.stack(name=name)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 292, in stack
return self.gather(math_ops.range(0, self.size()), name=name)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py", line 306, in gather
element_shape=element_shape)
File "/usr/lib/python3.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 6291, in tensor_array_gather_v3
element_shape=element_shape, name=name)
File "/usr/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/usr/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 3300, in create_op
op_def=op_def)
File "/usr/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1801, in __init__
self._traceback = tf_stack.extract_stack()
UnimplementedError (see above for traceback): TensorArray has size zero, but element shape [?,128] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[node decoder/bidirectional_rnn/fw/fw/TensorArrayStack/TensorArrayGatherV3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
[[node decoder/bidirectional_rnn/bw/bw/while/Exit_3 (defined at <ipython-input-5-7fc0ccd4ec49>:97) ]]
So I talked to someone about this who was using the same script and they suggested that it was because my dataset was too many lines; that they were able to avoid this error by limiting the lines of data to 400 lines. This did indeed get rid of the error but it doesn't solve the problem.
Using < 400 lines is fine for 1 day per-line OHLCV data but if I want to use a lower timeframe, say, 1minute per-line OHLCV data, 400 lines isn't going to cut it.
How can I get this model to accept an arbitrary rows of data?

tensorboard written in the jupyter notebook doesn't work

I run the code
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 1])
y_ = tf.placeholder(tf.float32, [None, 1])
m = tf.Variable(0.)
y = m*x
loss = tf.reduce_mean(tf.pow(y - y_, 2))
update = tf.train.GradientDescentOptimizer(0.0001).minimize(loss)
msum = tf.summary.scalar('m', m)
losssum = tf.summary.scalar('loss', loss)
merged = tf.summary.merge_all()
sess = tf.Session()
file_writer = tf.summary.FileWriter('./my_graph', sess.graph)
sess.run(tf.global_variables_initializer())
data_dict = {x:[[7.01], [3.02], [4.99], [8.]], y_:[[14.01], [6.01], [10.], [16.04]]}
for i in range(0,1000):
[_,curr_sammary] = sess.run([update,merged], feed_dict = data_dict)
file_writer.add_summary(curr_sammary, i)
file_writer.close()
print(sess.run(m))
But this code is not running because of the following error:
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1321 try:
-> 1322 return fn(*args)
1323 except errors.OpError as e:
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1306 return self._call_tf_sessionrun(
-> 1307 options, feed_dict, fetch_list, target_list, run_metadata)
1308
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1408 self._session, options, feed_dict, fetch_list, target_list,
-> 1409 run_metadata)
1410 else:
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [?,1]
[[Node: Placeholder = 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:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-42-c57f3c0f3525> in <module>()
1 data_dict = {x:[[7.01], [3.02], [4.99], [8.]], y_:[[14.01], [6.01], [10.], [16.04]]}
2 for i in range(0,1):
----> 3 [_,curr_sammary] = sess.run([update,merged], feed_dict = data_dict)
4 file_writer.add_summary(curr_sammary, i)
5
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
898 try:
899 result = self._run(None, fetches, feed_dict, options_ptr,
--> 900 run_metadata_ptr)
901 if run_metadata:
902 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1133 if final_fetches or final_targets or (handle and feed_dict_tensor):
1134 results = self._do_run(handle, final_targets, final_fetches,
-> 1135 feed_dict_tensor, options, run_metadata)
1136 else:
1137 results = []
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1314 if handle is None:
1315 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1316 run_metadata)
1317 else:
1318 return self._do_call(_prun_fn, handle, feeds, fetches)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1333 except KeyError:
1334 pass
-> 1335 raise type(e)(node_def, op, message)
1336
1337 def _extend_graph(self):
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [?,1]
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[?,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'Placeholder', defined at:
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.5/dist-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/usr/local/lib/python3.5/dist-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelapp.py", line 486, in start
self.io_loop.start()
File "/usr/local/lib/python3.5/dist-packages/tornado/platform/asyncio.py", line 132, in start
self.asyncio_loop.run_forever()
File "/usr/lib/python3.5/asyncio/base_events.py", line 345, in run_forever
self._run_once()
File "/usr/lib/python3.5/asyncio/base_events.py", line 1312, in _run_once
handle._run()
File "/usr/lib/python3.5/asyncio/events.py", line 125, in _run
self._callback(*self._args)
File "/usr/local/lib/python3.5/dist-packages/tornado/platform/asyncio.py", line 122, in _handle_events
handler_func(fileobj, events)
File "/usr/local/lib/python3.5/dist-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python3.5/dist-packages/zmq/eventloop/zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 233, in dispatch_shell
handler(stream, idents, msg)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/ipkernel.py", line 208, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python3.5/dist-packages/ipykernel/zmqshell.py", line 537, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2662, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2785, in _run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2901, in run_ast_nodes
if self.run_code(code, result):
File "/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-8fcfa2faf332>", line 3, in <module>
x = tf.placeholder(tf.float32, [None, 1])
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py", line 1734, in placeholder
return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 4924, in placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3414, in create_op
op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1740, 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' with dtype float and shape [?,1]
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[?,1], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
After trying to understand the source of the problem I saw that if the line
[_,curr_sammary] = sess.run([update,merged], feed_dict = data_dict)
in the loop I change the line
sess.run(update, feed_dict = data_dict)
the problem is solved.
I tried to search for understand what the error was and didn't find anything to solve the problem.
I need the line to work in its original form (without the deletions)
I would be happy if someone can tell me what the problem is and what its solution is.
I'm on tensorflow-gpu (1.7.0) and the original, unedited version
[_,curr_sammary] = sess.run([update,merged], feed_dict = data_dict)
runs successfully runs with no errors on both Jupyter and on the terminal.
I DID, however, notice that when i ran the script a second time on Jupyter, that I got the same error as you. This leads me to believe you're keeping state between runs.
On the terminal (where no state is kept between consecutive runs), it all worked fine

My TensorFlow code produces an error with the dimensionality of inputs

InvalidArgumentError Traceback (most recent call last)
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1321 try:
-> 1322 return fn(*args)
1323 except errors.OpError as e:
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1306 return self._call_tf_sessionrun(
-> 1307 options, feed_dict, fetch_list, target_list, run_metadata)
1308
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1408 self._session, options, feed_dict, fetch_list, target_list,
-> 1409 run_metadata)
1410 else:
InvalidArgumentError: Tensor must be 4-D with last dim 1, 3, or 4, not [32,32,28,28]
[[Node: Konvolution1/Konvolution1Bild = ImageSummary[T=DT_FLOAT, bad_color=Tensor<type: uint8 shape: [4] values: 255 0 0...>, max_images=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Konvolution1/Konvolution1Bild/tag, Konvolution1/Konvolution1Bild/tensor/_39)]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-8-73b3b51081a0> in <module>()
18 print(i, 'Trainingsgenauigkeit = ', genau*100,'%', 'verlust = ', verlust)
19
---> 20 s = sess.run(merged, feed_dict={x:batch_x, y:batch_y, dropoutPH:dropout})
21 writer.add_summary(s, i)
22 genauigkeitTest = sess.run(genauigkeitTraining, feed_dict={x:mnist.test.images,y:mnist.test.labels, keep_prob:1.0})
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
898 try:
899 result = self._run(None, fetches, feed_dict, options_ptr,
--> 900 run_metadata_ptr)
901 if run_metadata:
902 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1133 if final_fetches or final_targets or (handle and feed_dict_tensor):
1134 results = self._do_run(handle, final_targets, final_fetches,
-> 1135 feed_dict_tensor, options, run_metadata)
1136 else:
1137 results = []
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1314 if handle is None:
1315 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1316 run_metadata)
1317 else:
1318 return self._do_call(_prun_fn, handle, feeds, fetches)
C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1333 except KeyError:
1334 pass
-> 1335 raise type(e)(node_def, op, message)
1336
1337 def _extend_graph(self):
InvalidArgumentError: Tensor must be 4-D with last dim 1, 3, or 4, not [32,32,28,28]
[[Node: Konvolution1/Konvolution1Bild = ImageSummary[T=DT_FLOAT, bad_color=Tensor<type: uint8 shape: [4] values: 255 0 0...>, max_images=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Konvolution1/Konvolution1Bild/tag, Konvolution1/Konvolution1Bild/tensor/_39)]]
Caused by op 'Konvolution1/Konvolution1Bild', defined at:
File "C:\Anaconda\envs\Matura\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Anaconda\envs\Matura\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "C:\Anaconda\envs\Matura\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
app.start()
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel\kernelapp.py", line 486, in start
self.io_loop.start()
File "C:\Anaconda\envs\Matura\lib\site-packages\tornado\platform\asyncio.py", line 127, in start
self.asyncio_loop.run_forever()
File "C:\Anaconda\envs\Matura\lib\asyncio\base_events.py", line 421, in run_forever
self._run_once()
File "C:\Anaconda\envs\Matura\lib\asyncio\base_events.py", line 1425, in _run_once
handle._run()
File "C:\Anaconda\envs\Matura\lib\asyncio\events.py", line 127, in _run
self._callback(*self._args)
File "C:\Anaconda\envs\Matura\lib\site-packages\tornado\ioloop.py", line 759, in _run_callback
ret = callback()
File "C:\Anaconda\envs\Matura\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\Anaconda\envs\Matura\lib\site-packages\zmq\eventloop\zmqstream.py", line 536, in <lambda>
self.io_loop.add_callback(lambda : self._handle_events(self.socket, 0))
File "C:\Anaconda\envs\Matura\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
self._handle_recv()
File "C:\Anaconda\envs\Matura\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
self._run_callback(callback, msg)
File "C:\Anaconda\envs\Matura\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\Anaconda\envs\Matura\lib\site-packages\tornado\stack_context.py", line 276, in null_wrapper
return fn(*args, **kwargs)
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel\kernelbase.py", line 233, in dispatch_shell
handler(stream, idents, msg)
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel\ipkernel.py", line 208, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "C:\Anaconda\envs\Matura\lib\site-packages\ipykernel\zmqshell.py", line 537, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Anaconda\envs\Matura\lib\site-packages\IPython\core\interactiveshell.py", line 2662, in run_cell
raw_cell, store_history, silent, shell_futures)
File "C:\Anaconda\envs\Matura\lib\site-packages\IPython\core\interactiveshell.py", line 2785, in _run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Anaconda\envs\Matura\lib\site-packages\IPython\core\interactiveshell.py", line 2901, in run_ast_nodes
if self.run_code(code, result):
File "C:\Anaconda\envs\Matura\lib\site-packages\IPython\core\interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-9e8915c7d2a2>", line 26, in <module>
tf.summary.image('Konvolution1Bild', tf.unstack(konv1, axis = 3))
File "C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\summary\summary.py", line 162, in image
tag=tag, tensor=tensor, max_images=max_outputs, name=scope)
File "C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\ops\gen_logging_ops.py", line 387, in image_summary
bad_color=bad_color, name=name)
File "C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Anaconda\envs\Matura\lib\site-packages\tensorflow\python\framework\ops.py", line 3392, in create_op
op_def=op_def)
File "C:\Anaconda\envs\Matura\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): Tensor must be 4-D with last dim 1, 3, or 4, not [32,32,28,28]
[[Node: Konvolution1/Konvolution1Bild = ImageSummary[T=DT_FLOAT, bad_color=Tensor<type: uint8 shape: [4] values: 255 0 0...>, max_images=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Konvolution1/Konvolution1Bild/tag, Konvolution1/Konvolution1Bild/tensor/_39)]]
Snippets of the code that produce this error:
merged = tf.summary.merge_all()
init = tf.global_variables_initializer()
with tf.Session() as sess:
writer= tf.summary.FileWriter( "/tmp/mnist_logs", sess.graph)
sess.run(init)
for i in range(anzahlIterationen):
batch_x, batch_y = mnist.train.next_batch(batchGrösse)
sess.run(training, feed_dict={x: batch_x, y: batch_y, dropoutPH:dropout})
if i % (np.floor(anzahlIterationen/5)) == 0:
verlust, genau = sess.run([kreuzentropie, genauigkeitTraining], feed_dict={x:batch_x, y:batch_y, dropoutPH:dropout})
print(i, 'Trainingsgenauigkeit = ', genau*100,'%', 'verlust = ', verlust)
s = sess.run(merged, feed_dict={x:batch_x, y:batch_y, dropoutPH:dropout})
writer.add_summary(s, i)
genauigkeitTest = sess.run(genauigkeitTraining, feed_dict={x:mnist.test.images,y:mnist.test.labels, keep_prob:1.0})
print("test accuracy %g"%(testAccurac
I really don't know where this error comes from. I can't think of a way to influence the tensors that I input because I want data from that.
The code already worked for previous versions. I can't think of I moment where I changed something with the summary

TensorFlow - FailedPreconditionError using tf.train.match_filenames_once()

I'm trying to read some .wav files using tensorflow, using the following code:
import tensorflow as tf
filenames = tf.train.match_filenames_once('audio_dataset/*.wav')
count_num_files = tf.size(filenames)
filename_queue = tf.train.string_input_producer(filenames)
reader = tf.WholeFileReader()
filename, file_contents = reader.read(filename_queue)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
num_files = sess.run(count_num_files)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(num_files):
audio_file = sess.run(filename)
print(audio_file)
I'm running tensorflow in a Python 3.5 environment, using Jupyter notebook.
in order to read audio files, I need to use a dependency, the Bregman Toolkit, which uses Python 2.X.
documentation Bregman Toolkit says that you can set up a python 2.X kernel alongside python 3X, doing:
$ python2 -m pip install ipykernel
$ python2 -m -ipykernel install --user
which I did. Jupyter has now the option of starting either 2.X or 3.X kernels.
but after all setup, when I try to run the code, I get this long Traceback:
---------------------------------------------------------------------------
FailedPreconditionError Traceback (most recent call last)
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1038 try:
-> 1039 return fn(*args)
1040 except errors.OpError as e:
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
1020 feed_dict, fetch_list, target_list,
-> 1021 status, run_metadata)
1022
/Users/me/anaconda/envs/py35/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
65 try:
---> 66 next(self.gen)
67 except StopIteration:
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status()
465 compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466 pywrap_tensorflow.TF_GetCode(status))
467 finally:
FailedPreconditionError: Attempting to use uninitialized value matching_filenames_7
[[Node: matching_filenames_7/read = Identity[T=DT_STRING, _class=["loc:#matching_filenames_7"], _device="/job:localhost/replica:0/task:0/cpu:0"](matching_filenames_7)]]
During handling of the above exception, another exception occurred:
FailedPreconditionError Traceback (most recent call last)
<ipython-input-12-a6f1ad8baaa4> in <module>()
9 with tf.Session() as sess:
10 sess.run(tf.global_variables_initializer())
---> 11 num_files = sess.run(count_num_files)
12
13 coord = tf.train.Coordinator()
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
776 try:
777 result = self._run(None, fetches, feed_dict, options_ptr,
--> 778 run_metadata_ptr)
779 if run_metadata:
780 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
980 if final_fetches or final_targets:
981 results = self._do_run(handle, final_targets, final_fetches,
--> 982 feed_dict_string, options, run_metadata)
983 else:
984 results = []
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1030 if handle is None:
1031 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1032 target_list, options, run_metadata)
1033 else:
1034 return self._do_call(_prun_fn, self._session, handle, feed_dict,
/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
1050 except KeyError:
1051 pass
-> 1052 raise type(e)(node_def, op, message)
1053
1054 def _extend_graph(self):
FailedPreconditionError: Attempting to use uninitialized value matching_filenames_7
[[Node: matching_filenames_7/read = Identity[T=DT_STRING, _class=["loc:#matching_filenames_7"], _device="/job:localhost/replica:0/task:0/cpu:0"](matching_filenames_7)]]
Caused by op 'matching_filenames_7/read', defined at:
File "/Users/me/anaconda/envs/py35/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/me/anaconda/envs/py35/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 477, in start
ioloop.IOLoop.instance().start()
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 177, in start
super(ZMQIOLoop, self).start()
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tornado/ioloop.py", line 888, in start
handler_func(fd_obj, events)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
handler(stream, idents, msg)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/ipkernel.py", line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2717, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2821, in run_ast_nodes
if self.run_code(code, result):
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-12-a6f1ad8baaa4>", line 3, in <module>
filenames = tf.train.match_filenames_once('audio_dataset/*.wav')
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/training/input.py", line 68, in match_filenames_once
collections=[ops.GraphKeys.LOCAL_VARIABLES])
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/variables.py", line 197, in __init__
expected_shape=expected_shape)
File "/Users/meme/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/variables.py", line 316, in _init_from_args
self._snapshot = array_ops.identity(self._variable, name="read")
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1338, in identity
result = _op_def_lib.apply_op("Identity", input=input, name=name)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
op_def=op_def)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Users/me/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
self._traceback = _extract_stack()
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value matching_filenames_7
[[Node: matching_filenames_7/read = Identity[T=DT_STRING, _class=["loc:#matching_filenames_7"], _device="/job:localhost/replica:0/task:0/cpu:0"](matching_filenames_7)]]
can anyone please point me in the right direction?
The immediate fix is to add the following line:
sess.run(tf.global_variables_initializer())
...before this line:
threads = tf.train.start_queue_runners(coord=coord)
However, I'd like to show you a new and slightly easier way to write your program using the tf.contrib.data API (available in TensorFlow 1.3, and will become tf.data in TensorFlow 1.4):
import tensorflow as tf
filenames = tf.contrib.data.Dataset.list_files('audio_dataset/*.wav')
name_and_content = filenames.map(lambda x: (x, tf.read_file(x))
iterator = name_and_content.make_one_shot_iterator()
filename, file_contents = iterator.get_next()
with tf.Session() as sess:
try:
while True:
audio_file = sess.run(filename)
print(audio_file)
except tf.errors.OutOfRangeError: # Raised when there are no more files.
pass

Categories

Resources