Custom loss function implementation issue in keras
问题 I am implementing a custom loss function in keras. The output of the model is 10 dimensional softmax layer. To calculate loss: first I need to find the index of y firing 1 and then subtract that value with true value. I'm doing the following: from keras import backend as K def diff_loss(y_true,y_pred): # find the indices of neuron firing 1 true_ind=K.tf.argmax(y_true,axis=0) pred_ind=K.tf.argmax(y_pred,axis=0) # cast it to float32 x=K.tf.cast(true_ind,K.tf.float32) y=K.tf.cast(pred_ind,K.tf