efficientdet-pytorch
efficientdet-pytorch copied to clipboard
implement IOU Loss
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 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 Yes, I followed the other code but I implemented it from scratch.
@hamadichihaoui great, thanks for confirming. I'll update here when I get some results training on COCO.
@rwightman Thanks, I will be waiting for your updates!
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 what AP you got on COCO?
I don't think my stats are comparable because I changed a lot of the original code.
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.
I addressed it the same way, maybe there is a more elegant way to implement it.
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_boxesfrom the model are inyxyx 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 consumegt_boxes&pred_boxes?
Thanks for your help!
@zlyin nope, no major updates, started looking at the code, paper but haven't finished either.
@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, thank you for your help! I have implemented the new loss_function. Thanks!