{
  "id": 171057,
  "title": "A question on the EfficientDet public kernel",
  "url": "/competitions/global-wheat-detection/discussion/171057",
  "author_name": "",
  "post_date": "2020-07-30T07:51:22.370209200Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I have a question on the training <a href=\"https://www.kaggle.com/shonenkov/training-efficientdet\">kernel</a> by shnonenkov.</p>\n\n<p>I understand that this line of code below is because the pretrained model from the effdet repo uses yxyx format. \n<code>target['boxes'][:,[0,1,2,3]] = target['boxes'][:,[1,0,3,2]] #yxyx: be warning</code></p>\n\n<p>However, when we make predictions, wouldn't the format be screwed up?</p>\n\n<p>Thanks!</p>",
  "messages": [
    {
      "id": "951545",
      "postDate": "07/30/2020 07:51:22",
      "content": "<p>I have a question on the training <a href=\"https://www.kaggle.com/shonenkov/training-efficientdet\">kernel</a> by shnonenkov.</p>\n\n<p>I understand that this line of code below is because the pretrained model from the effdet repo uses yxyx format. \n<code>target['boxes'][:,[0,1,2,3]] = target['boxes'][:,[1,0,3,2]] #yxyx: be warning</code></p>\n\n<p>However, when we make predictions, wouldn't the format be screwed up?</p>\n\n<p>Thanks!</p>",
      "rawMarkdown": "I have a question on the training [kernel](https://www.kaggle.com/shonenkov/training-efficientdet) by shnonenkov.\n\nI understand that this line of code below is because the pretrained model from the effdet repo uses yxyx format. \n`target['boxes'][:,[0,1,2,3]] = target['boxes'][:,[1,0,3,2]] #yxyx: be warning`\n\nHowever, when we make predictions, wouldn't the format be screwed up?\n\nThanks!",
      "votes": null
    },
    {
      "id": "951641",
      "postDate": "07/30/2020 09:30:30",
      "content": "<p>No. The model produces outputs in the \"xyxy\" format during generating predictions.</p>",
      "rawMarkdown": "No. The model produces outputs in the \"xyxy\" format during generating predictions.",
      "votes": null
    },
    {
      "id": "951654",
      "postDate": "07/30/2020 09:39:55",
      "content": "<p>Oh I see. You mean the DetBenchEval produces xyxy predictions, right? </p>",
      "rawMarkdown": "Oh I see. You mean the DetBenchEval produces xyxy predictions, right?",
      "votes": null
    },
    {
      "id": "951697",
      "postDate": "07/30/2020 10:17:44",
      "content": "<p>DetBenchEval produces outputs in the xywh format and inside the \"make_predictions\" function alex convert them to xyxy format.\n<code>\ndef make_predictions(images, score_threshold=0.22):\n    images = torch.stack(images).cuda().float()\n    predictions = []\n    with torch.no_grad():\n        det = net(images, torch.tensor([1]*images.shape[0]).float().cuda())\n        for i in range(images.shape[0]):\n            boxes = det[i].detach().cpu().numpy()[:,:4] <br>\n            scores = det[i].detach().cpu().numpy()[:,4]\n            indexes = np.where(scores &gt; score_threshold)[0]\n            boxes = boxes[indexes]  ## xywh\n            boxes[:, 2] = boxes[:, 2] + boxes[:, 0]\n            boxes[:, 3] = boxes[:, 3] + boxes[:, 1]  ##xyxy\n            predictions.append({\n                'boxes': boxes[indexes],\n                'scores': scores[indexes],\n            })\n    return [predictions]\n</code></p>",
      "rawMarkdown": "DetBenchEval produces outputs in the xywh format and inside the \"make_predictions\" function alex convert them to xyxy format.\n```\ndef make_predictions(images, score_threshold=0.22):\n    images = torch.stack(images).cuda().float()\n    predictions = []\n    with torch.no_grad():\n        det = net(images, torch.tensor([1]*images.shape[0]).float().cuda())\n        for i in range(images.shape[0]):\n            boxes = det[i].detach().cpu().numpy()[:,:4]    \n            scores = det[i].detach().cpu().numpy()[:,4]\n            indexes = np.where(scores &gt; score_threshold)[0]\n            boxes = boxes[indexes]  ## xywh\n            boxes[:, 2] = boxes[:, 2] + boxes[:, 0]\n            boxes[:, 3] = boxes[:, 3] + boxes[:, 1]  ##xyxy\n            predictions.append({\n                'boxes': boxes[indexes],\n                'scores': scores[indexes],\n            })\n    return [predictions]\n```",
      "votes": null
    },
    {
      "id": "951721",
      "postDate": "07/30/2020 10:41:29",
      "content": "<p>Ah now everything makes sense. I was trying to output the mAP scores during validation steps. Hence my question. Thanks a lot! </p>",
      "rawMarkdown": "Ah now everything makes sense. I was trying to output the mAP scores during validation steps. Hence my question. Thanks a lot!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 951641,
      "author_name": "mohammadzunaed",
      "author_url": "",
      "post_date": "07/30/2020 09:30:30",
      "content": "<p>No. The model produces outputs in the \"xyxy\" format during generating predictions.</p>",
      "votes": null,
      "replies": [
        {
          "id": 951654,
          "author_name": "faraksuli",
          "author_url": "",
          "post_date": "07/30/2020 09:39:55",
          "content": "<p>Oh I see. You mean the DetBenchEval produces xyxy predictions, right? </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 951697,
          "author_name": "mohammadzunaed",
          "author_url": "",
          "post_date": "07/30/2020 10:17:44",
          "content": "<p>DetBenchEval produces outputs in the xywh format and inside the \"make_predictions\" function alex convert them to xyxy format.\n<code>\ndef make_predictions(images, score_threshold=0.22):\n    images = torch.stack(images).cuda().float()\n    predictions = []\n    with torch.no_grad():\n        det = net(images, torch.tensor([1]*images.shape[0]).float().cuda())\n        for i in range(images.shape[0]):\n            boxes = det[i].detach().cpu().numpy()[:,:4] <br>\n            scores = det[i].detach().cpu().numpy()[:,4]\n            indexes = np.where(scores &gt; score_threshold)[0]\n            boxes = boxes[indexes]  ## xywh\n            boxes[:, 2] = boxes[:, 2] + boxes[:, 0]\n            boxes[:, 3] = boxes[:, 3] + boxes[:, 1]  ##xyxy\n            predictions.append({\n                'boxes': boxes[indexes],\n                'scores': scores[indexes],\n            })\n    return [predictions]\n</code></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 951721,
          "author_name": "faraksuli",
          "author_url": "",
          "post_date": "07/30/2020 10:41:29",
          "content": "<p>Ah now everything makes sense. I was trying to output the mAP scores during validation steps. Hence my question. Thanks a lot! </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "951545": "I have a question on the training [kernel](https://www.kaggle.com/shonenkov/training-efficientdet) by shnonenkov.\n\nI understand that this line of code below is because the pretrained model from the effdet repo uses yxyx format. \n`target['boxes'][:,[0,1,2,3]] = target['boxes'][:,[1,0,3,2]] #yxyx: be warning`\n\nHowever, when we make predictions, wouldn't the format be screwed up?\n\nThanks!",
    "951641": "No. The model produces outputs in the \"xyxy\" format during generating predictions.",
    "951654": "Oh I see. You mean the DetBenchEval produces xyxy predictions, right?",
    "951697": "DetBenchEval produces outputs in the xywh format and inside the \"make_predictions\" function alex convert them to xyxy format.\n```\ndef make_predictions(images, score_threshold=0.22):\n    images = torch.stack(images).cuda().float()\n    predictions = []\n    with torch.no_grad():\n        det = net(images, torch.tensor([1]*images.shape[0]).float().cuda())\n        for i in range(images.shape[0]):\n            boxes = det[i].detach().cpu().numpy()[:,:4]    \n            scores = det[i].detach().cpu().numpy()[:,4]\n            indexes = np.where(scores &gt; score_threshold)[0]\n            boxes = boxes[indexes]  ## xywh\n            boxes[:, 2] = boxes[:, 2] + boxes[:, 0]\n            boxes[:, 3] = boxes[:, 3] + boxes[:, 1]  ##xyxy\n            predictions.append({\n                'boxes': boxes[indexes],\n                'scores': scores[indexes],\n            })\n    return [predictions]\n```",
    "951721": "Ah now everything makes sense. I was trying to output the mAP scores during validation steps. Hence my question. Thanks a lot!"
  },
  "source": "meta"
}