efficientdet-pytorch icon indicating copy to clipboard operation
efficientdet-pytorch copied to clipboard

implement IOU Loss

Open hamadichihaoui opened this issue 5 years ago • 13 comments

Based on: https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/86a370aa2cadea6ba7e5dffb2efc4bacc4c863ea/utils/box/box_utils.py#L47 Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression https://arxiv.org/pdf/1911.08287.pdf Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression https://giou.stanford.edu/GIoU.pdf UnitBox: An Advanced Object Detection Network https://arxiv.org/pdf/1608.01471.pdf

I made a quick test using the global wheat detection dataset, the [email protected] reaches 0.35 and stop to increase. @rwightman

hamadichihaoui avatar Jul 11 '20 15:07 hamadichihaoui

@hamadichihaoui thanks for the contribution, I will evaluate the iou loss with my next training experiments before adding

One question, the reference impl has a GPL license so code can not be directly brought in here without changing my Apache 2.0 license (which I do not intend to do). Did you implement your PR from scratch without using any of the original code directly?

rwightman avatar Jul 13 '20 20:07 rwightman

@rwightman Yes, I followed the other code but I implemented it from scratch.

hamadichihaoui avatar Jul 13 '20 20:07 hamadichihaoui

@hamadichihaoui great, thanks for confirming. I'll update here when I get some results training on COCO.

rwightman avatar Jul 13 '20 20:07 rwightman

@rwightman Thanks, I will be waiting for your updates!

hamadichihaoui avatar Jul 13 '20 20:07 hamadichihaoui

Looking forward to the results! I implemented my own version of CIoU/DIoU loss but I couldn't obtain similar results on COCO when compared to huber loss.

liaopeiyuan avatar Jul 15 '20 15:07 liaopeiyuan

@liaopeiyuan what AP you got on COCO?

hamadichihaoui avatar Jul 15 '20 15:07 hamadichihaoui

I don't think my stats are comparable because I changed a lot of the original code.

liaopeiyuan avatar Jul 15 '20 15:07 liaopeiyuan

Also, I haven't looked at your implementation, but AFAIK CIoU loss/DIoU loss only operates on xyxy/yxyx inputs, which is a lot different from EfficientDet's xy(log w)(log h)-relative format. How did you address this problem in your code? In my code, I chose to maintain box predictions as relative (to anchors), but decoded the raw output into xyxy format (with the exp function applied), then calculated the IoU losses for each outputs from the boxnet. but this seems less ideal. I wonder if @rwightman may have a more natural adaptation to this codebase.

liaopeiyuan avatar Jul 15 '20 15:07 liaopeiyuan

I addressed it the same way, maybe there is a more elegant way to implement it.

hamadichihaoui avatar Jul 15 '20 18:07 hamadichihaoui

Hi Ross, any updates in this thread, @rwightman?

Hi @hamadichihaoui @liaopeiyuan, may I ask how you guys decode the gt_boxes & pred_boxes when calculating the loss?

  • Currently, both my gt_boxes & pred_boxes from the model are in yxyx relative to the anchors. I just use these relative values directly to calculate the loss. Though it converges well, but the model performances is pretty bad.
  • Did you use anchor sizes to recover the absolute xyxy format of boxes? If so, how did you retrieve the anchor sizes while calculating the loss?
  • As mentioned in your post above, what's the difference between raw outputs & box_predictions? Shouldn't the loss function consume gt_boxes & pred_boxes?

Thanks for your help!

zlyin avatar Jul 25 '20 04:07 zlyin

@zlyin nope, no major updates, started looking at the code, paper but haven't finished either.

rwightman avatar Jul 25 '20 05:07 rwightman

@zlyin I used decode_box_outputs to recover the absolute xyxy format of boxes. The method takes 3 arguments, rel_codes= the output of the models in the relative format (raw outputs), anchors, output_xyxy= whether to get the absolute boxes in xyxy or yxyx. The idea is just rel_codes and the anchors (which are both list) must match meaning that the rel_codes[0] should correspond to anchors[0] and so on.

hamadichihaoui avatar Jul 25 '20 11:07 hamadichihaoui

@hamadichihaoui, thank you for your help! I have implemented the new loss_function. Thanks!

zlyin avatar Jul 28 '20 02:07 zlyin