{
  "id": 162947,
  "title": "giou loss question",
  "url": "/competitions/global-wheat-detection/discussion/162947",
  "author_name": "",
  "post_date": "2020-06-30T14:44:02.106372Z",
  "votes": 3,
  "comment_count": 2,
  "views": 0,
  "content": "<p>After I run my modeling and evaluate on Tensorboard, I understand the precision and recall but could someone give me advice regarding evaluating the giou loss? I get the ground truth and prediction and union but I don't want to misread what Tensorboard is showing for giou loss and obj loss. See attached image. </p>",
  "messages": [
    {
      "id": "909368",
      "postDate": "06/30/2020 14:44:02",
      "content": "<p>After I run my modeling and evaluate on Tensorboard, I understand the precision and recall but could someone give me advice regarding evaluating the giou loss? I get the ground truth and prediction and union but I don't want to misread what Tensorboard is showing for giou loss and obj loss. See attached image. </p>",
      "rawMarkdown": "After I run my modeling and evaluate on Tensorboard, I understand the precision and recall but could someone give me advice regarding evaluating the giou loss? I get the ground truth and prediction and union but I don't want to misread what Tensorboard is showing for giou loss and obj loss. See attached image.",
      "votes": null
    },
    {
      "id": "909745",
      "postDate": "06/30/2020 19:43:45",
      "content": "<p>Hi <a href=\"/crained\">@crained</a> , the official GIoU website has an excellent illustrateive explanation of many important stuffs:\n<a href=\"https://giou.stanford.edu/\">https://giou.stanford.edu/</a></p>\n\n<ul>\n<li>Why L1 / L2 loss are not ideal for bboxes regression (many good/bad predicted bboxes can have the same L1/L2 loss -- see picture below)</li>\n</ul>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1364892%2Fb387c41a02bde8353cb9bac7c2b9890a%2Fgiou.png?generation=1593546449520710&amp;alt=media\" alt=\"\"></p>\n\n<hr>\n\n<ul>\n<li><p>GIoU converges to IoU when prediction getting better and better (GIoU is bounded by [-1,1] )</p></li>\n<li><p>GIoU better generalizes IoU when there's no overlap/intersect (Consider two \"non-overlap to Ground truth\" bboxes predictions, GIoU gives better score to the closer prediction box, while IoU always give 0 score to both)</p></li>\n<li><p>Accordingt to the paper (Refer to algorithm 2), \nGIoU Loss = 1 - GIoU \n<a href=\"https://giou.stanford.edu/GIoU.pdf\">https://giou.stanford.edu/GIoU.pdf</a>  </p></li>\n<li><p>We can see historical development of GIoU in YoloV3/5 here : <a href=\"https://github.com/ultralytics/yolov3/issues/302\">https://github.com/ultralytics/yolov3/issues/302</a></p></li>\n</ul>\n\n<h2>Bonus</h2>\n\n<ul>\n<li><p>Note that now the best public kernel (i.e. YoloV5) already built-in this GIoU loss in the training pipeline.\nHowever, maybe there's an even improvement on GIoU namely DIoU and CIoU as explained here : \n<a href=\"https://medium.com/nodeflux/distance-iou-loss-an-improvement-of-iou-based-loss-for-object-detection-bounding-box-regression-4cbdd23d8660\">https://medium.com/nodeflux/distance-iou-loss-an-improvement-of-iou-based-loss-for-object-detection-bounding-box-regression-4cbdd23d8660</a> --- Note that in the paper, these DIoU and CIoU have been tested only on old benchmarks like FRCNN, and not yet tested on 2020 SOTA models like EffDet or YoloV4/5 </p></li>\n<li><p>Stunningly, YoloV5 already implemented both DIoU and CIoU . They are hidden under <code>utils/utils.py</code></p></li>\n</ul>\n\n<p>In function <code>def compute_loss(p, targets, model):</code>\nWe can see this line : <code>giou = bbox_iou(pbox.t(), tbox[i], x1y1x2y2=False, GIoU=True)  # giou(prediction, target)</code></p>\n\n<p>which actually can change to diou or ciou : \n<code>def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False)</code></p>",
      "rawMarkdown": "Hi @crained , the official GIoU website has an excellent illustrateive explanation of many important stuffs:\nhttps://giou.stanford.edu/\n\n- Why L1 / L2 loss are not ideal for bboxes regression (many good/bad predicted bboxes can have the same L1/L2 loss -- see picture below)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1364892%2Fb387c41a02bde8353cb9bac7c2b9890a%2Fgiou.png?generation=1593546449520710&amp;alt=media)\n\n----\n\n- GIoU converges to IoU when prediction getting better and better (GIoU is bounded by [-1,1] )\n\n- GIoU better generalizes IoU when there's no overlap/intersect (Consider two \"non-overlap to Ground truth\" bboxes predictions, GIoU gives better score to the closer prediction box, while IoU always give 0 score to both)\n\n- Accordingt to the paper (Refer to algorithm 2), \nGIoU Loss = 1 - GIoU \nhttps://giou.stanford.edu/GIoU.pdf  \n\n- We can see historical development of GIoU in YoloV3/5 here : https://github.com/ultralytics/yolov3/issues/302\n\n## Bonus\n- Note that now the best public kernel (i.e. YoloV5) already built-in this GIoU loss in the training pipeline.\nHowever, maybe there's an even improvement on GIoU namely DIoU and CIoU as explained here : \nhttps://medium.com/nodeflux/distance-iou-loss-an-improvement-of-iou-based-loss-for-object-detection-bounding-box-regression-4cbdd23d8660 --- Note that in the paper, these DIoU and CIoU have been tested only on old benchmarks like FRCNN, and not yet tested on 2020 SOTA models like EffDet or YoloV4/5 \n\n- Stunningly, YoloV5 already implemented both DIoU and CIoU . They are hidden under `utils/utils.py`\n\nIn function `def compute_loss(p, targets, model):`\nWe can see this line : `giou = bbox_iou(pbox.t(), tbox[i], x1y1x2y2=False, GIoU=True)  # giou(prediction, target)`\n\nwhich actually can change to diou or ciou : \n`def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False)`",
      "votes": null
    },
    {
      "id": "911657",
      "postDate": "07/01/2020 23:09:45",
      "content": "<p>This is great. Thank you <a href=\"/ratthachat\">@ratthachat</a> . I read the Stanford paper on it and got a good sense for it but this really grounds it for me. Thank you!</p>",
      "rawMarkdown": "This is great. Thank you @ratthachat . I read the Stanford paper on it and got a good sense for it but this really grounds it for me. Thank you!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 909745,
      "author_name": "ratthachat",
      "author_url": "",
      "post_date": "06/30/2020 19:43:45",
      "content": "<p>Hi <a href=\"/crained\">@crained</a> , the official GIoU website has an excellent illustrateive explanation of many important stuffs:\n<a href=\"https://giou.stanford.edu/\">https://giou.stanford.edu/</a></p>\n\n<ul>\n<li>Why L1 / L2 loss are not ideal for bboxes regression (many good/bad predicted bboxes can have the same L1/L2 loss -- see picture below)</li>\n</ul>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1364892%2Fb387c41a02bde8353cb9bac7c2b9890a%2Fgiou.png?generation=1593546449520710&amp;alt=media\" alt=\"\"></p>\n\n<hr>\n\n<ul>\n<li><p>GIoU converges to IoU when prediction getting better and better (GIoU is bounded by [-1,1] )</p></li>\n<li><p>GIoU better generalizes IoU when there's no overlap/intersect (Consider two \"non-overlap to Ground truth\" bboxes predictions, GIoU gives better score to the closer prediction box, while IoU always give 0 score to both)</p></li>\n<li><p>Accordingt to the paper (Refer to algorithm 2), \nGIoU Loss = 1 - GIoU \n<a href=\"https://giou.stanford.edu/GIoU.pdf\">https://giou.stanford.edu/GIoU.pdf</a>  </p></li>\n<li><p>We can see historical development of GIoU in YoloV3/5 here : <a href=\"https://github.com/ultralytics/yolov3/issues/302\">https://github.com/ultralytics/yolov3/issues/302</a></p></li>\n</ul>\n\n<h2>Bonus</h2>\n\n<ul>\n<li><p>Note that now the best public kernel (i.e. YoloV5) already built-in this GIoU loss in the training pipeline.\nHowever, maybe there's an even improvement on GIoU namely DIoU and CIoU as explained here : \n<a href=\"https://medium.com/nodeflux/distance-iou-loss-an-improvement-of-iou-based-loss-for-object-detection-bounding-box-regression-4cbdd23d8660\">https://medium.com/nodeflux/distance-iou-loss-an-improvement-of-iou-based-loss-for-object-detection-bounding-box-regression-4cbdd23d8660</a> --- Note that in the paper, these DIoU and CIoU have been tested only on old benchmarks like FRCNN, and not yet tested on 2020 SOTA models like EffDet or YoloV4/5 </p></li>\n<li><p>Stunningly, YoloV5 already implemented both DIoU and CIoU . They are hidden under <code>utils/utils.py</code></p></li>\n</ul>\n\n<p>In function <code>def compute_loss(p, targets, model):</code>\nWe can see this line : <code>giou = bbox_iou(pbox.t(), tbox[i], x1y1x2y2=False, GIoU=True)  # giou(prediction, target)</code></p>\n\n<p>which actually can change to diou or ciou : \n<code>def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False)</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 911657,
          "author_name": "crained",
          "author_url": "",
          "post_date": "07/01/2020 23:09:45",
          "content": "<p>This is great. Thank you <a href=\"/ratthachat\">@ratthachat</a> . I read the Stanford paper on it and got a good sense for it but this really grounds it for me. Thank you!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "909368": "After I run my modeling and evaluate on Tensorboard, I understand the precision and recall but could someone give me advice regarding evaluating the giou loss? I get the ground truth and prediction and union but I don't want to misread what Tensorboard is showing for giou loss and obj loss. See attached image.",
    "909745": "Hi @crained , the official GIoU website has an excellent illustrateive explanation of many important stuffs:\nhttps://giou.stanford.edu/\n\n- Why L1 / L2 loss are not ideal for bboxes regression (many good/bad predicted bboxes can have the same L1/L2 loss -- see picture below)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1364892%2Fb387c41a02bde8353cb9bac7c2b9890a%2Fgiou.png?generation=1593546449520710&amp;alt=media)\n\n----\n\n- GIoU converges to IoU when prediction getting better and better (GIoU is bounded by [-1,1] )\n\n- GIoU better generalizes IoU when there's no overlap/intersect (Consider two \"non-overlap to Ground truth\" bboxes predictions, GIoU gives better score to the closer prediction box, while IoU always give 0 score to both)\n\n- Accordingt to the paper (Refer to algorithm 2), \nGIoU Loss = 1 - GIoU \nhttps://giou.stanford.edu/GIoU.pdf  \n\n- We can see historical development of GIoU in YoloV3/5 here : https://github.com/ultralytics/yolov3/issues/302\n\n## Bonus\n- Note that now the best public kernel (i.e. YoloV5) already built-in this GIoU loss in the training pipeline.\nHowever, maybe there's an even improvement on GIoU namely DIoU and CIoU as explained here : \nhttps://medium.com/nodeflux/distance-iou-loss-an-improvement-of-iou-based-loss-for-object-detection-bounding-box-regression-4cbdd23d8660 --- Note that in the paper, these DIoU and CIoU have been tested only on old benchmarks like FRCNN, and not yet tested on 2020 SOTA models like EffDet or YoloV4/5 \n\n- Stunningly, YoloV5 already implemented both DIoU and CIoU . They are hidden under `utils/utils.py`\n\nIn function `def compute_loss(p, targets, model):`\nWe can see this line : `giou = bbox_iou(pbox.t(), tbox[i], x1y1x2y2=False, GIoU=True)  # giou(prediction, target)`\n\nwhich actually can change to diou or ciou : \n`def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False)`",
    "911657": "This is great. Thank you @ratthachat . I read the Stanford paper on it and got a good sense for it but this really grounds it for me. Thank you!"
  },
  "source": "meta"
}