ruiminshen / yolo-tf

TensorFlow implementation of the YOLO (You Only Look Once)
GNU Lesser General Public License v3.0
198 stars 72 forks source link

Cost function in Yolo-v1 #3

Open christophesaintjean opened 7 years ago

christophesaintjean commented 7 years ago

Hi, I think there is an error with the cost function in Yolo-v1. In the original paper, the authors said that the confidence value should be :

TaihuLight commented 7 years ago

The cost function in YOLO-V2 is right in this project?

ruiminshen commented 7 years ago

@christophesaintjean Thank you for your question. In the function model.yolo.Objectives.init, the tensors "mask_best" and "masknormal" representing $1{ij}^{obj}$ and $1_{ij}^{noobj}$, respectively.

The tensor "mask_best" requires two conditions: the cell contains an object (self.mask) AND the bbox has the best IoU value in its cell (best_box). Because "best_box_iou" calculates the best IoU value of each independent cell, and "best_box" requires the IoU value of a bbox equals "best_box_iou". So it will be 0 if its IoU is not the best in its cell.

ruiminshen commented 7 years ago

@TaihuLight Yes, I've checked it.

christophesaintjean commented 7 years ago

@ruiminshen, i studied more your code and noticed that i agree your comment I explain it below for the interested reader.

I am implementing Yolo-v1 with Keras. My implementation for these two losses are as the following:

So maybe, there is a very subtle difference between our interpretations:

At the end, it is the same loss since IOU is 1 for the best box in the learning step. I got this because i have encoded the image annotation into a nb_cells(nb_classes + boxes_per_cell (1 + 4)) vector. However, only the first box in each cell is used for the desired output.

Best regards, Christophe

ps: thank you very much for having shared your valuable code.