I want to implement a custom loss function in keras based on binary_crossEntropy. I have question about shape of output tnesor of Keras.losses.binary_crossentropy. I expect that it should be a 1D tensor with length of batch_size. but it returns a tensor with shape of [batch size, classes] with identical loss amount in each row for all classes. should i manually use max along rows? is there a better way? and why the output of K.binary_crossentropy is not 1d tensor? is it related to math concepts?
def custom_loss(y_true, y_pred):
loss_tensor = K.binary_crossentropy(y_true, y_pred)
# return K.max(loss_tensor, axis=1)
return loss_tensor
# model.compile(loss={'classifier':'kullback_leibler_divergence'},optimizer='Nadam',metrics=['acc'])
tmp_y_true = tf.constant([[0.0, 1.0], [1.0, 0.0]])
tmp_y_pred = tf.constant([[0.8, 0.2], [0.75, 0.25]])
output = custom_loss(tmp_y_true, tmp_y_pred)
tmp_out = K.eval(output)