keras_multi_gpu icon indicating copy to clipboard operation
keras_multi_gpu copied to clipboard

Incompatible shapes

Open pococito opened this issue 8 years ago • 1 comments

Hi, seems like it's not able to split the tensors every time. I get "incompatible shapes". Perhaps it cannot handle odd lengths?

nvalidArgumentError: Incompatible shapes: [17,258] vs. [35,258]
	 [[Node: sequential_4/gru_3/while/add = Add[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](sequential_4/gru_3/while/strided_slice, sequential_4/gru_3/while/MatMul)]]

Caused by op 'sequential_4/gru_3/while/add', defined at:
  File "/usr/lib/python3.5/runpy.py", line 193, 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 "/home/pawel/venv/lib/python3.5/site-packages/ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "/home/pawel/venv/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()

(...)

  File "/home/pawel/venv/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 "/home/pawel/venv/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): Incompatible shapes: [17,258] vs. [35,258]
	 [[Node: sequential_4/gru_3/while/add = Add[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](sequential_4/gru_3/while/strided_slice, sequential_4/gru_3/while/MatMul)]]

pococito avatar Sep 12 '17 09:09 pococito

@pococito I had encountered erros/problems/issues a lot of times about the slice operation when creating a multi-gpu model. Finnally I have figured out a more stable solution without using slice. Briefly, I prepare an InputLayer for each tower. For example, if the input to a single tower is (image, label), the inputs to the whole model with 2 gpus would be (image1, label1, image2, label2). You can easily modify your data generator to generate n_tower times of separated input data. Wish you luck.

chenjiasheng avatar Sep 15 '17 02:09 chenjiasheng