hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

[question] Any idea why the loss function is computed for output_1 and output_2? #57

Closed guysoft closed 3 years ago

guysoft commented 3 years ago

Hey, It seems that the loss function is computed for output_1 and output_2.

This can be seen by setting verbose to 1 and seeing the keras traning output:

  7/100 [=>............................] - ETA: 1:06 - loss: 3659.3479 - output_1_loss: 2951.3269 - output_2_loss: 703.0701

As you can see there is output_1_loss and output_2_loss. This is also computed for validation and any extra metric I add. I get metric_name_output_1 and metric_name_output_2.

I would assume there are two output layers, but it seems like in the loss the function that all the information in yolov4 is already contained in one:

        truth_xywh = y_true[..., 0:4]
        truth_conf = y_true[..., 4:5]
        truth_prob = y_true[..., 5:]

        num_classes = truth_prob.shape[-1]

        pred_xywh = y_pred[..., 0:4]
        pred_conf = y_pred[..., 4:5]
        pred_prob = y_pred[..., 5:]

Those are the 3 outputs expected from YOLOv4

source: https://github.com/hhk7734/tensorflow-yolov4/blob/master/py_src/yolov4/tf/train.py#L71

hhk7734 commented 3 years ago

If you use tiny, Yolo head returns 2 output.

https://github.com/hhk7734/tensorflow-yolov4/blob/be7b9305fcef1d1245948c26612c31f6d3212c5e/py_src/yolov4/model/head.py#L210

TF2 calls the loss function for each output.

guysoft commented 3 years ago

@hhk7734 Thanks! I gather L and M are medium and large?

And that output 1 is medium and output 2 is large?