{
  "id": 302441,
  "title": "Anyone Solved this problem??",
  "url": "/competitions/tensorflow-great-barrier-reef/discussion/302441",
  "author_name": "Eugene J. Ryu",
  "post_date": "2022-01-22T15:16:56.191000",
  "votes": 0,
  "comment_count": 6,
  "views": 0,
  "content": "<p>Hi, I have a RuntimeError which is related to the Dimensions of an input image.</p>\n<p>The troubled function is this, yolox_inference and the Runtime error happened. </p>\n<p><code>def yolox_inference(img, model, test_size):\n    bboxes = []\n    bbclasses = []\n    scores = []\n    preproc = ValTransform(legacy=False)\n    tensor_img, _ = preproc(img, None, test_size)\n    tensor_img = torch.from_numpy(tensor_img).unsqueeze(0)\n    tensor_img = tensor_img.float()\n    tensor_img = tensor_img.cuda()\n    with torch.no_grad():\n        outputs = model(tensor_img)\n        outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)\n    if outputs[0] is None:\n        return [], [], []\n    outputs = outputs[0].cpu()\n    bboxes = outputs[:, 0:4]\n    bboxes /= min(test_size[0]/img.shape[0], test_size[1]/img.shape[1])\n    bbclasses = outputs[:, 6]\n    scores = outputs[:, 4] * outputs[:, 5]\n    return bboxes, bbclasses, scores</code></p>\n<p>`---------------------------------------------------------------------------<br>\nRuntimeError                              Traceback (most recent call last)<br>\n/tmp/ipykernel_2575/2502701481.py in <br>\n     18     img = cv2.imread(path)[…,::-1]<br>\n     19 <br>\n---&gt; 20     bboxes_1, bbclasses, scores = yolox_inference(img, yolox_model, test_size)<br>\n     21     # bboxes_1, bbclasses, scores = yolox_inference(img[…,::-1], yolox_model, test_size)<br>\n     22     pred_1, pred_2 = voc2coco(bboxes_1.detach().numpy(), img.shape[1], img.shape[2]).astype(int), bboxes_2</p>\n<p>/tmp/ipykernel_2575/239627864.py in yolox_inference(img, model, test_size)<br>\n     15 <br>\n     16     with torch.no_grad():<br>\n---&gt; 17         outputs = model(tensor_img)<br>\n     18         outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)`</p>\n<p>I transformed the tensor_img in many ways, but still got the error. I searched with \"yolo5\" RuntimeError : Sizes of tensors… I didn't find out a clear solution for this trouble. </p>\n<p>If someone solved this problem before here, help. </p>",
  "messages": [
    {
      "id": 1660312,
      "postDate": "2022-01-22T15:32:19.310Z",
      "content": "<p>you either post all related codes, or learn from shared notebooks first.</p>\n<p>my wild guess is that your test_size not properly  configured.</p>",
      "rawMarkdown": "you either post all related codes, or learn from shared notebooks first.\n\nmy wild guess is that your test_size not properly  configured.",
      "votes": 1,
      "replies": [
        {
          "id": 1660359,
          "postDate": "2022-01-22T16:07:38.910Z",
          "content": "<p>I apologize for the way of questioning here was in the wrong way. I got the error while clone coding the below kernel. Thus all the codes are the same as this kernel. </p>\n<p><a href=\"https://www.kaggle.com/yamqwe/great-barrier-reef-yolox-yolov5-ensemble\" target=\"_blank\">YOLOX and YOLO5 Ensemble</a></p>\n<p>And your wild guess is right!!!! I typed the test_size (800, 1200) and real test_size in that kernel is (800, 1280). You solved my problem. Thank you very much 😊😊</p>",
          "rawMarkdown": "I apologize for the way of questioning here was in the wrong way. I got the error while clone coding the below kernel. Thus all the codes are the same as this kernel. \n\n[YOLOX and YOLO5 Ensemble](https://www.kaggle.com/yamqwe/great-barrier-reef-yolox-yolov5-ensemble)\n\nAnd your wild guess is right!!!! I typed the test_size (800, 1200) and real test_size in that kernel is (800, 1280). You solved my problem. Thank you very much 😊😊"
        },
        {
          "id": 1660667,
          "postDate": "2022-01-22T20:56:55.493Z",
          "content": "<p>Yes, absolutely …. input size must be divided by 64 :) due to yoloX network architecture </p>",
          "rawMarkdown": "Yes, absolutely …. input size must be divided by 64 :) due to yoloX network architecture "
        },
        {
          "id": 1661987,
          "postDate": "2022-01-23T22:43:37.947Z",
          "content": "<p>Correction. Division by 32 is sufficient</p>",
          "rawMarkdown": "Correction. Division by 32 is sufficient",
          "votes": 1
        },
        {
          "id": 1661989,
          "postDate": "2022-01-23T22:47:17.553Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 1661990,
          "postDate": "2022-01-23T22:54:40.173Z",
          "content": "<p><a href=\"https://www.kaggle.com/alexchwong\" target=\"_blank\">@alexchwong</a> you are right …. I do not know why I think about 64 …. 32 … is correct. Thank you for correction.</p>",
          "rawMarkdown": "@alexchwong you are right .... I do not know why I think about 64 .... 32 ... is correct. Thank you for correction."
        }
      ]
    },
    {
      "id": 1660294,
      "postDate": "2022-01-22T15:16:56.193Z",
      "content": "<p>Hi, I have a RuntimeError which is related to the Dimensions of an input image.</p>\n<p>The troubled function is this, yolox_inference and the Runtime error happened. </p>\n<p><code>def yolox_inference(img, model, test_size):\n    bboxes = []\n    bbclasses = []\n    scores = []\n    preproc = ValTransform(legacy=False)\n    tensor_img, _ = preproc(img, None, test_size)\n    tensor_img = torch.from_numpy(tensor_img).unsqueeze(0)\n    tensor_img = tensor_img.float()\n    tensor_img = tensor_img.cuda()\n    with torch.no_grad():\n        outputs = model(tensor_img)\n        outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)\n    if outputs[0] is None:\n        return [], [], []\n    outputs = outputs[0].cpu()\n    bboxes = outputs[:, 0:4]\n    bboxes /= min(test_size[0]/img.shape[0], test_size[1]/img.shape[1])\n    bbclasses = outputs[:, 6]\n    scores = outputs[:, 4] * outputs[:, 5]\n    return bboxes, bbclasses, scores</code></p>\n<p>`---------------------------------------------------------------------------<br>\nRuntimeError                              Traceback (most recent call last)<br>\n/tmp/ipykernel_2575/2502701481.py in <br>\n     18     img = cv2.imread(path)[…,::-1]<br>\n     19 <br>\n---&gt; 20     bboxes_1, bbclasses, scores = yolox_inference(img, yolox_model, test_size)<br>\n     21     # bboxes_1, bbclasses, scores = yolox_inference(img[…,::-1], yolox_model, test_size)<br>\n     22     pred_1, pred_2 = voc2coco(bboxes_1.detach().numpy(), img.shape[1], img.shape[2]).astype(int), bboxes_2</p>\n<p>/tmp/ipykernel_2575/239627864.py in yolox_inference(img, model, test_size)<br>\n     15 <br>\n     16     with torch.no_grad():<br>\n---&gt; 17         outputs = model(tensor_img)<br>\n     18         outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)`</p>\n<p>I transformed the tensor_img in many ways, but still got the error. I searched with \"yolo5\" RuntimeError : Sizes of tensors… I didn't find out a clear solution for this trouble. </p>\n<p>If someone solved this problem before here, help. </p>",
      "rawMarkdown": "Hi, I have a RuntimeError which is related to the Dimensions of an input image.\n\nThe troubled function is this, yolox_inference and the Runtime error happened. \n\n`def yolox_inference(img, model, test_size):\n    bboxes = []\n    bbclasses = []\n    scores = []\n    preproc = ValTransform(legacy=False)\n    tensor_img, _ = preproc(img, None, test_size)\n    tensor_img = torch.from_numpy(tensor_img).unsqueeze(0)\n    tensor_img = tensor_img.float()\n    tensor_img = tensor_img.cuda()\n    with torch.no_grad():\n        outputs = model(tensor_img)\n        outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)\n    if outputs[0] is None:\n        return [], [], []\n    outputs = outputs[0].cpu()\n    bboxes = outputs[:, 0:4]\n    bboxes /= min(test_size[0]/img.shape[0], test_size[1]/img.shape[1])\n    bbclasses = outputs[:, 6]\n    scores = outputs[:, 4] * outputs[:, 5]\n    return bboxes, bbclasses, scores`\n\n\n`---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n/tmp/ipykernel_2575/2502701481.py in <module>\n     18     img = cv2.imread(path)[...,::-1]\n     19 \n---> 20     bboxes_1, bbclasses, scores = yolox_inference(img, yolox_model, test_size)\n     21     # bboxes_1, bbclasses, scores = yolox_inference(img[...,::-1], yolox_model, test_size)\n     22     pred_1, pred_2 = voc2coco(bboxes_1.detach().numpy(), img.shape[1], img.shape[2]).astype(int), bboxes_2\n\n/tmp/ipykernel_2575/239627864.py in yolox_inference(img, model, test_size)\n     15 \n     16     with torch.no_grad():\n---> 17         outputs = model(tensor_img)\n     18         outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)`\n\nI transformed the tensor_img in many ways, but still got the error. I searched with \"yolo5\" RuntimeError : Sizes of tensors... I didn't find out a clear solution for this trouble. \n\nIf someone solved this problem before here, help. "
    }
  ],
  "comments": [
    {
      "id": 1660312,
      "author_name": "dragon zhang",
      "author_url": "",
      "post_date": "2022-01-22T15:32:19.310000",
      "content": "<p>you either post all related codes, or learn from shared notebooks first.</p>\n<p>my wild guess is that your test_size not properly  configured.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1660359,
          "author_name": "Eugene J. Ryu",
          "author_url": "",
          "post_date": "2022-01-22T16:07:38.910000",
          "content": "<p>I apologize for the way of questioning here was in the wrong way. I got the error while clone coding the below kernel. Thus all the codes are the same as this kernel. </p>\n<p><a href=\"https://www.kaggle.com/yamqwe/great-barrier-reef-yolox-yolov5-ensemble\" target=\"_blank\">YOLOX and YOLO5 Ensemble</a></p>\n<p>And your wild guess is right!!!! I typed the test_size (800, 1200) and real test_size in that kernel is (800, 1280). You solved my problem. Thank you very much 😊😊</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1660667,
          "author_name": "Remek Kinas",
          "author_url": "",
          "post_date": "2022-01-22T20:56:55.493000",
          "content": "<p>Yes, absolutely …. input size must be divided by 64 :) due to yoloX network architecture </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1661987,
          "author_name": "Alex Wong",
          "author_url": "",
          "post_date": "2022-01-23T22:43:37.947000",
          "content": "<p>Correction. Division by 32 is sufficient</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1661989,
          "author_name": "",
          "author_url": "",
          "post_date": "2022-01-23T22:47:17.553000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1661990,
          "author_name": "Remek Kinas",
          "author_url": "",
          "post_date": "2022-01-23T22:54:40.173000",
          "content": "<p><a href=\"https://www.kaggle.com/alexchwong\" target=\"_blank\">@alexchwong</a> you are right …. I do not know why I think about 64 …. 32 … is correct. Thank you for correction.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1660312": "you either post all related codes, or learn from shared notebooks first.\n\nmy wild guess is that your test_size not properly  configured.",
    "1660294": "Hi, I have a RuntimeError which is related to the Dimensions of an input image.\n\nThe troubled function is this, yolox_inference and the Runtime error happened. \n\n`def yolox_inference(img, model, test_size):\n    bboxes = []\n    bbclasses = []\n    scores = []\n    preproc = ValTransform(legacy=False)\n    tensor_img, _ = preproc(img, None, test_size)\n    tensor_img = torch.from_numpy(tensor_img).unsqueeze(0)\n    tensor_img = tensor_img.float()\n    tensor_img = tensor_img.cuda()\n    with torch.no_grad():\n        outputs = model(tensor_img)\n        outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)\n    if outputs[0] is None:\n        return [], [], []\n    outputs = outputs[0].cpu()\n    bboxes = outputs[:, 0:4]\n    bboxes /= min(test_size[0]/img.shape[0], test_size[1]/img.shape[1])\n    bbclasses = outputs[:, 6]\n    scores = outputs[:, 4] * outputs[:, 5]\n    return bboxes, bbclasses, scores`\n\n\n`---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\n/tmp/ipykernel_2575/2502701481.py in <module>\n     18     img = cv2.imread(path)[...,::-1]\n     19 \n---> 20     bboxes_1, bbclasses, scores = yolox_inference(img, yolox_model, test_size)\n     21     # bboxes_1, bbclasses, scores = yolox_inference(img[...,::-1], yolox_model, test_size)\n     22     pred_1, pred_2 = voc2coco(bboxes_1.detach().numpy(), img.shape[1], img.shape[2]).astype(int), bboxes_2\n\n/tmp/ipykernel_2575/239627864.py in yolox_inference(img, model, test_size)\n     15 \n     16     with torch.no_grad():\n---> 17         outputs = model(tensor_img)\n     18         outputs = postprocess(outputs, num_classes, confthre, nmsthre, class_agnostic=True)`\n\nI transformed the tensor_img in many ways, but still got the error. I searched with \"yolo5\" RuntimeError : Sizes of tensors... I didn't find out a clear solution for this trouble. \n\nIf someone solved this problem before here, help. "
  }
}