I have a network that produces a 4D output tensor where the value at each position in spatial dimensions (~pixel) is to be interpreted as the class probabilities for that po
Found this issue to confirm my intuition.
In short : the softmax will take 2D or 3D inputs. If they are 3D keras will assume a shape like this (samples, timedimension, numclasses) and apply the softmax on the last one. For some weird reasons, it doesnt do that for 4D tensors.
Solution : reshape your output to a sequence of pixels
reshaped_output = Reshape((height*width, num_classes))(output_tensor)
Then apply your softmax
new_output = Activation('softmax')(reshaped_output)
And then either you reshape your target tensors to 2D or you just reshape that last layer into (width, height, num_classes).
Otherwise, something I would try if I wasn't on my phone right now is to use a TimeDistributed(Activation('softmax'))
. But no idea if that would work... will try later
I hope this helps :-)