0

Can I use this loss function for YOLO

    def myLoss(y_actual,y_pred):
        a = tf.keras.losses.BinaryCrossentropy()(y_actual[:,:,:,0],y_pred[:,:,:,0])
        b = tf.keras.losses.MeanSquaredError()(y_actual[:,:,:,1:], y_pred[:,:,:,1:]*y_actual[:,:,:,:1])
      
    
        loss= a + b 
        return loss

where y_actual = [Pc,bx,by,bw,bh,c1,c2,c3]
pc = probability that one of c1,c2,c3 exists in a particular grid,
bx,by,bw,bh are bounding box parameters for a particular grid,
c1,c2,c3 are 3 classes i want to predict, eg: 0,0,1 for class 3

I read somewhere that when Pc_actual=0 the loss doesnt care about the bounding box and class prediction and so i multiplied them with Pc_actual so that when pc_actual is 0 loss corresponding to those terms are 0.

Please correct me if I am wrong

hitesh kumar
  • 421
  • 5
  • 8

1 Answers1

0

You are right when Pc_actual=0 the loss doesn't care about the bounding box and class prediction but it cares about the result of Pc_pred because you need the model to learn it as well so when Pc_actual=0 the loss function should be (Pc_actual - Pc_pred)**2 to penalize the model when it predict that there is an object while there is no objects.

Mostafa Labib
  • 789
  • 6
  • 17