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 position. In other words, the output is (num_batches, height, width, num_classes)
. I have labels of the same size where the real class is coded as one-hot. I would like to calculate the categorical-crossentropy
loss using this.
Problem #1: The K.softmax
function expects a 2D
tensor (num_batches, num_classes)
Problem #2: I'm not sure how the losses from each position should be combined. Is it correct to reshape
the tensor to (num_batches * height * width, num_classes)
and then calling K.categorical_crossentropy
on that? Or rather, call K.categorical_crossentropy(num_batches, num_classes)
height*width times and average the results?