Training works in keras 2.2.2 but not in 2.2.3 and 2.2.4
See original GitHub issueHi, I’m training a semantic image segmentation model.
And I’ve built a generator that yields:
(images, masks, sample_weights) my batch size is 8. at the following shapes:
( (8, 256, 256, 3) , (8, 65536, 1) , (8, 65536) )
In the compilation I also defined sample_weight_mode = "temporal"
and this is the error I’m getting: (it looks like these versions reshape the validation labels to be a 1D vector)
InvalidArgumentError: Incompatible shapes: [524288] vs. [8,65536]
[[Node: metrics/acc/Equal = Equal[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"](metrics/acc/Reshape, metrics/acc/Cast)]]
[[Node: training/Adam/gradients/activation_1_1/concat_grad/Slice_1/_799 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:1", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_2406_training/Adam/gradients/activation_1_1/concat_grad/Slice_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:1"]()]]
When I set batch_size=1 it works.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:20 (5 by maintainers)
Top Results From Across the Web
Keras 2.2.4 with TensorFlow 1.4.1 crashing GPU instances
I'm having trouble when using a Conv2D architecture, the GPU instance seems to crash, i.e. i can see the GPU memory fill up...
Read more >How to correctly install Keras and Tensorflow - ActiveState
Once TensorFlow and Keras are installed, you can start working with them. ... It's not necessary to import all of the Keras and...
Read more >About Keras
Keras is: Simple -- but not simplistic. Keras reduces developer cognitive load to free you to focus on the parts of the problem...
Read more >Deep Learning with Keras - Keras 2.2.4 - INTERMEDIATE
In this 19-video course, learners explore deep learning with Keras, including how to create and use neural networks with Keras for machine learning ......
Read more >Keras vs. tf.keras: What's the difference in TensorFlow 2.0?
What does the TensorFlow 2.0 release mean for me as a Keras user? Am I supposed to use the keras package for training...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue happens with tf1.9 and keras2.2.4
I have a similar issue using tf.keras. My keras version is 2.2.4, my tensorflow version is 1.12.0, and I use Python 3.6. I train a simple RNN with one embedding layer, one GRU layer with
return_sequences=True
, one Dense layer (using TimeDistributed or not with the Dense layer doesn’t change the problem, I get the same error). My metric is sparse_categorical_entropy.The length of my sequences is 4, and there are 60 categories, so the shape of my input is
(batch_size, 4, 60)
. The shape of my output is also(batch_size, 4, 60)
sincereturn_sequences=True
.The error I get is InvalidArgumentError: Incompatible shapes: [batch_size] vs. [batch_size,4] [Op:Equal]
Note that, like in the posts above, the error does not occur when batch_size=1 or when I don’t use any metric. In both cases the neural network trains without error.
Note also that if I set
return_sequences=False
, that is, I only try to predict one category instead of a sequence and my output is of shape(batch_size,60)
, then the network trains also without error.EDIT : I managed to make my training work by replacing
by
where I defined
new_sparse_categorical_accuracy
by copying the code taken from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/metrics.py, that is: