question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fixing 'Incompatible Shapes' error

See original GitHub issue

I am trying to train this model on my own data. I have been able to get it to work before with my own data, but I wanted to have my images semantically segmented beforehand, so I used a different model to do so, and I think in doing so I must have changed my environment enough to start getting this error because I highly doubt it’s an issue with the new images I’m using. They are the same size as the previous. I have run the requirements.txt file and still am getting this issue. I have posted the error below. Any help on what the problem might be and how to fix it would be greatly appreciated. Thank you in advance!

Starting training… Train for 200 steps, validate for 1169 steps Epoch 1/100 2020-12-06 20:35:50.965473: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Invalid argument: Incompatible shapes: [3] vs. [256,512,4] [[{{node Equal_29}}]] [[IteratorGetNext]] 2020-12-06 20:35:50.987892: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Invalid argument: Incompatible shapes: [3] vs. [256,512,4] [[{{node Equal_29}}]] [[IteratorGetNext]] [[metrics/mean_io_u_with_one_hot_labels/StatefulPartitionedCall/confusion_matrix/assert_non_negative/assert_less_equal/Assert/AssertGuard/else/_6/Assert/data_1/_20]] 1/200 […] - ETA: 35:21WARNING:tensorflow:Can save best model only with val_mean_io_u_with_one_hot_labels available, skipping. WARNING:tensorflow:Early stopping conditioned on metric val_mean_io_u_with_one_hot_labels which is not available. Available metrics are: Traceback (most recent call last): File “./train.py”, line 185, in <module> callbacks=callbacks) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py”, line 819, in fit use_multiprocessing=use_multiprocessing) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py”, line 342, in fit total_epochs=epochs) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py”, line 128, in run_one_epoch batch_outs = execution_function(iterator) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_v2_utils.py”, line 98, in execution_function distributed_function(input_fn)) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/def_function.py”, line 568, in call result = self._call(*args, **kwds) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/def_function.py”, line 632, in _call return self._stateless_fn(*args, **kwds) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py”, line 2363, in call return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py”, line 1611, in _filtered_call self.captured_inputs) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py”, line 1692, in _call_flat ctx, args, cancellation_manager=cancellation_manager)) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py”, line 545, in call ctx=ctx) File “/home/techlab_grizzly/Desktop/Cam2BEV/env37/lib/python3.7/site-packages/tensorflow_core/python/eager/execute.py”, line 67, in quick_execute six.raise_from(core._status_to_exception(e.code, message), None) File “<string>”, line 3, in raise_from tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [3] vs. [256,512,4] [[{{node Equal_29}}]] [[IteratorGetNext]] [Op:__inference_distributed_function_17137] Function call stack: distributed_function

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
boycejamcommented, Dec 7, 2020

I accidentally closed this issue so just commenting again to make sure you can see the last comment:

https://github.com/boycejam/Our_BEV_Files

Above is the link to a repo I made containing the files you mentioned. Let me know if there is anything else you need

0reactions
lreihercommented, Dec 7, 2020

Problem is that your input image has a fourth alpha channel, s.t. the resized image has shape (256, 512, 4). This causes the crash during one-hot-encoding.

I will push a fix tomorrow, s.t. an image will always be loaded as RGB instead of RGBA, even if present. In the meantime, you can fix it yourself by replacing utils.py#L77 with

img = tf.image.decode_png(img, channels=3)

Some more notes on your files:

  • The standard implementation expects semantically segmented input and output images, which are then one-hot-en/decoded as part of the pipeline. Your images are a blend of the real-world-image and the semantic segmentation. One-hot-en/decoding will not work properly this way.
  • Your input image color-codes vehicles in a purple-ish way, but the standard 0,0,142 (RGB) blue is listed in the convert_10.xml. You need to check the colors you specify there.
  • Your label image has shape (640, 480), while your input image has shape (480, 640). Keep in mind that both will be center-cropped/resized to (256, 512).
  • It’s important that you provide a good estimate of the homography matrix. Just saying as I couldn’t have a look at your homography file.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Tensorflow Incompatible Shapes Error in Tutorial
The reshapes with the -1's are clues. It's not the batch size that's wrong it's the image size. You're flattening it out into...
Read more >
Incompatible shapes - Keras - TensorFlow Forum
Hi, I try to make predictions with keras models but face an issue when I use fit. My goal is to get 30...
Read more >
increase fit batch size: 1->2 => Incompatible shapes on model ...
Re: increase fit batch size: 1->2 => Incompatible shapes on model.compile(): [2,1] vs. ... It seems odd that a fit parameter would cause...
Read more >
Incompatible shapes ValueError raised in vitis_quantize
I have a custom model where the float model predicts fine with my dataset, but running the quantizer with the same dataset leads...
Read more >
Incompatible Shapes due to Batch Size : r/tensorflow - Reddit
No matter how what I change the batch size to, when I try to train the model, I always get a similar error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found