Invalid argument: Incompatible shapes: [227] vs. [89]

2,071 views
Skip to first unread message

dia...@gmail.com

unread,
Aug 17, 2016, 10:54:18 AM8/17/16
to Discuss
Hello Guys.

I have to detect the changes that a forget gate has in an lstm cell in feed forwarding data, in order to do this (since simple print functions inside the scripts don't show any other result than "tensor bla bla bla") I moved all of the necessary data into the operations section (lstmcell, rnn, and _step_function basically). When I train the neural network with the training data, it works same as if it was done using the functions, however when I try to do feedforward with the test data, I receive this error

---------------------------------------------------------------------------
StatusNotOK                               Traceback (most recent call last)
/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
    643     try:
--> 644       return fn(*args)
    645     except tf_session.StatusNotOK as e:

/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/client/session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
    627         return tf_session.TF_Run(
--> 628             session, None, feed_dict, fetch_list, target_list, None)
    629 

StatusNotOK: Invalid argument: Incompatible shapes: [227] vs. [89]
	 [[Node: Equal = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/gpu:0"](ArgMax_2, ArgMax_3)]]
	 [[Node: Mean_1/_483 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_3440_Mean_1", tensor_type=DT_FLOAT, _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-10-76dcd36eb6ef> in <module>()
     36     test_data = np.reshape(test_data,((test_batch, n_steps, n_input)))
     37     test_label = labelsTest
---> 38     print ("Testing Accuracy:",         sess.run(accuracy, feed_dict={x: test_data, y: test_label, l:89}))
     39 
     40     x_val, y_val = sess.run([value_x, value_y], feed_dict={x: test_data, y: test_label, l: 89})

/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    338     try:
    339       result = self._run(None, fetches, feed_dict, options_ptr,
--> 340                          run_metadata_ptr)
    341       if run_metadata:
    342         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
    562     try:
    563       results = self._do_run(handle, target_list, unique_fetches,
--> 564                              feed_dict_string, options, run_metadata)
    565     finally:
    566       # The movers are no longer used. Delete them.

/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
    635     if handle is None:
    636       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
--> 637                            target_list, options, run_metadata)
    638     else:
    639       return self._do_call(_prun_fn, self._session, handle, feed_dict,

/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
    657       # pylint: disable=protected-access
    658       raise errors._make_specific_exception(node_def, op, error_message,
--> 659                                             e.code)
    660       # pylint: enable=protected-access
    661 

InvalidArgumentError: Incompatible shapes: [227] vs. [89]
	 [[Node: Equal = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/gpu:0"](ArgMax_2, ArgMax_3)]]
	 [[Node: Mean_1/_483 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_3440_Mean_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'Equal', defined at:
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/ipykernel/__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/traitlets/config/application.py", line 596, in launch_instance
    app.start()
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/ipykernel/kernelapp.py", line 442, in start
    ioloop.IOLoop.instance().start()
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/zmq/eventloop/ioloop.py", line 162, in start
    super(ZMQIOLoop, self).start()
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tornado/ioloop.py", line 883, in start
    handler_func(fd_obj, events)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/ipykernel/kernelbase.py", line 276, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/ipykernel/kernelbase.py", line 391, in execute_request
    user_expressions, allow_stdin)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/ipykernel/ipkernel.py", line 199, in do_execute
    shell.run_cell(code, store_history=store_history, silent=silent)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/IPython/core/interactiveshell.py", line 2723, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/IPython/core/interactiveshell.py", line 2825, in run_ast_nodes
    if self.run_code(code, result):
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-eb29a262e0ba>", line 15, in <module>
    correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/ops/gen_math_ops.py", line 466, in equal
    return _op_def_lib.apply_op("Equal", x=x, y=y, name=name)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/ops/op_def_library.py", line 655, in apply_op
    op_def=op_def)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 2154, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/gomez/Documents/virtual/lib/python3.4/site-packages/tensorflow/python/framework/ops.py", line 1154, in __init__
    self._traceback = _extract_stack()

And that's weird cause I opted to send data to a placeholder telling the size of the batch I was going to use.

P.D These are the 2 running sessions I used

# Run optimization op (backprop) in Training session
sess.run(optimizer, feed_dict={x: batch_x, y: batch_y, l: 227})

#Run accuracy in Test session.
sess.run(accuracy, feed_dict={x: test_data, y: test_label, l:89}))

Could anyone please tell me where am I failing. That would be really useful for me.

alviseDT

unread,
Aug 17, 2016, 11:13:41 AM8/17/16
to Discuss, dia...@gmail.com
Seems to me that you are giving the wrong data to the network. Seems to me you are passing to the network a lenght 'l' that is different between training and testing, is that a value that 'should' modify some kind of size? if so, consider using different variables for different sized data, otherwise the network wont be able to allocate the proper sized memory. (not sure if this is the case tho.)
Reply all
Reply to author
Forward
0 new messages