{
  "id": 322383,
  "title": "Submitted notebook can't access any test images except abc.jpg",
  "url": "/competitions/hotel-id-to-combat-human-trafficking-2022-fgvc9/discussion/322383",
  "author_name": "",
  "post_date": "2022-05-01T21:26:21.784716400Z",
  "votes": 1,
  "comment_count": 3,
  "views": 0,
  "content": "<p>Hey all, I just resumed my work on this competition after being occupied at school work for a few weeks. I am so stuck now since I don't know how to build submission.csv, even though I carefully checked every piece of suggestion from <a href=\"https://www.kaggle.com/competitions/hotel-id-to-combat-human-trafficking-2022-fgvc9/discussion/314661\" target=\"_blank\">this post</a>. </p>\n<p>I tested a few things: (1) I created an empty notebook, called pd.read_csv() on the sample submission csv, and made that as my submission. (2) I followed <a href=\"https://www.kaggle.com/code/michaln/hotel-id-starter-classification-inference\" target=\"_blank\">this implementation</a> in a notebook that I built previously. To create the test_df, I tried (2a) reading the sample submission csv and (2b) calling os.listdir() on the folder of test images. </p>\n<p><strong>RESULTS:</strong></p>\n<p>(1) made a valid submission with score 0.00. Notebook is <a href=\"https://www.kaggle.com/code/jaredfeng/hotel-id-submission-test\" target=\"_blank\">here</a>.</p>\n<p>Both (2a) and (2b) failed to make valid submissions with a common error. It says the test_df I created only has one row, but the list of predictions has 128 entries. 128 is the batch size I set for the test_loader, but it is also weird that it only has one batch. I previously printed out the 128 predictions in a draft session, it turned out all predictions from row 2-128 were the same, so I assume the corresponding rows in the input tensors were all zeros.<br>\nNotebook is <a href=\"https://www.kaggle.com/code/jaredfeng/hotel-id/notebook?scriptVersionId=94516473\" target=\"_blank\">here</a>.</p>\n<p>Any help would be appreciated.</p>\n<p><strong>EDIT:</strong></p>\n<p>Issue resolved as per analysis and suggestion from the comment. All notebooks from me have been set to private again, as they were set to public for debugging only. (My approaches were basically ill-developed aka trash so not worth viewing by any means)</p>",
  "messages": [
    {
      "id": "1774136",
      "postDate": "05/01/2022 21:26:21",
      "content": "<p>Hey all, I just resumed my work on this competition after being occupied at school work for a few weeks. I am so stuck now since I don't know how to build submission.csv, even though I carefully checked every piece of suggestion from <a href=\"https://www.kaggle.com/competitions/hotel-id-to-combat-human-trafficking-2022-fgvc9/discussion/314661\" target=\"_blank\">this post</a>. </p>\n<p>I tested a few things: (1) I created an empty notebook, called pd.read_csv() on the sample submission csv, and made that as my submission. (2) I followed <a href=\"https://www.kaggle.com/code/michaln/hotel-id-starter-classification-inference\" target=\"_blank\">this implementation</a> in a notebook that I built previously. To create the test_df, I tried (2a) reading the sample submission csv and (2b) calling os.listdir() on the folder of test images. </p>\n<p><strong>RESULTS:</strong></p>\n<p>(1) made a valid submission with score 0.00. Notebook is <a href=\"https://www.kaggle.com/code/jaredfeng/hotel-id-submission-test\" target=\"_blank\">here</a>.</p>\n<p>Both (2a) and (2b) failed to make valid submissions with a common error. It says the test_df I created only has one row, but the list of predictions has 128 entries. 128 is the batch size I set for the test_loader, but it is also weird that it only has one batch. I previously printed out the 128 predictions in a draft session, it turned out all predictions from row 2-128 were the same, so I assume the corresponding rows in the input tensors were all zeros.<br>\nNotebook is <a href=\"https://www.kaggle.com/code/jaredfeng/hotel-id/notebook?scriptVersionId=94516473\" target=\"_blank\">here</a>.</p>\n<p>Any help would be appreciated.</p>\n<p><strong>EDIT:</strong></p>\n<p>Issue resolved as per analysis and suggestion from the comment. All notebooks from me have been set to private again, as they were set to public for debugging only. (My approaches were basically ill-developed aka trash so not worth viewing by any means)</p>",
      "rawMarkdown": "Hey all, I just resumed my work on this competition after being occupied at school work for a few weeks. I am so stuck now since I don't know how to build submission.csv, even though I carefully checked every piece of suggestion from [this post](https://www.kaggle.com/competitions/hotel-id-to-combat-human-trafficking-2022-fgvc9/discussion/314661). \n\nI tested a few things: (1) I created an empty notebook, called pd.read_csv() on the sample submission csv, and made that as my submission. (2) I followed [this implementation](https://www.kaggle.com/code/michaln/hotel-id-starter-classification-inference) in a notebook that I built previously. To create the test_df, I tried (2a) reading the sample submission csv and (2b) calling os.listdir() on the folder of test images. \n\n**RESULTS:**\n\n(1) made a valid submission with score 0.00. Notebook is [here](https://www.kaggle.com/code/jaredfeng/hotel-id-submission-test).\n\nBoth (2a) and (2b) failed to make valid submissions with a common error. It says the test_df I created only has one row, but the list of predictions has 128 entries. 128 is the batch size I set for the test_loader, but it is also weird that it only has one batch. I previously printed out the 128 predictions in a draft session, it turned out all predictions from row 2-128 were the same, so I assume the corresponding rows in the input tensors were all zeros.\nNotebook is [here](https://www.kaggle.com/code/jaredfeng/hotel-id/notebook?scriptVersionId=94516473).\n\nAny help would be appreciated.\n\n\n**EDIT:**\n\nIssue resolved as per analysis and suggestion from the comment. All notebooks from me have been set to private again, as they were set to public for debugging only. (My approaches were basically ill-developed aka trash so not worth viewing by any means)",
      "votes": null
    },
    {
      "id": "1774187",
      "postDate": "05/02/2022 00:12:54",
      "content": "<p>The notebooks you linked are not accessible (probably set to private) so can't check the code. <br>\nSounds like the output of your inference is not correct (size) and it doesn't set the predictions to the submission right. You could try to make the submission on train images and check if it is created correctly or at least check what is the dimensions/shape of inference output. <br>\nIf you make your notebooks public (or at least some minimal example) it will be easier to give advice.</p>",
      "rawMarkdown": "The notebooks you linked are not accessible (probably set to private) so can't check the code. \nSounds like the output of your inference is not correct (size) and it doesn't set the predictions to the submission right. You could try to make the submission on train images and check if it is created correctly or at least check what is the dimensions/shape of inference output. \nIf you make your notebooks public (or at least some minimal example) it will be easier to give advice.",
      "votes": null
    },
    {
      "id": "1774193",
      "postDate": "05/02/2022 00:31:03",
      "content": "<p>Yes doing that on the train images is another good experiment, will do it tomorrow. Btw the two notebooks I quoted were private indeed and I just made them public.</p>\n<p>Thanks!</p>",
      "rawMarkdown": "Yes doing that on the train images is another good experiment, will do it tomorrow. Btw the two notebooks I quoted were private indeed and I just made them public.\n\nThanks!",
      "votes": null
    },
    {
      "id": "1774201",
      "postDate": "05/02/2022 00:44:56",
      "content": "<p>The problem is your collate function, specifically this line:</p>\n<p><code>img_tensor = torch.empty((BSZ,3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)</code></p>\n<p>You can see it running this:</p>\n<pre><code>print(\"Test data length:\", len(test_data))\nbatch = next(iter(test_loader))\nprint(\"Batch image data shape:\", batch[\"image\"].shape)\n</code></pre>\n<p>The test data have lenght 1 but your batch data has size 128 because in the test_pipe collate function you always create the img_tensor with BSZ (batch size).</p>\n<p>If you replace the line for img_tensor with <br>\n<code>img_tensor = torch.empty((len(data),3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)</code><br>\nit will work.</p>",
      "rawMarkdown": "The problem is your collate function, specifically this line:\n\n`img_tensor = torch.empty((BSZ,3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)`\n\nYou can see it running this:\n\n```\nprint(\"Test data length:\", len(test_data))\nbatch = next(iter(test_loader))\nprint(\"Batch image data shape:\", batch[\"image\"].shape)\n```\nThe test data have lenght 1 but your batch data has size 128 because in the test_pipe collate function you always create the img_tensor with BSZ (batch size).\n\nIf you replace the line for img_tensor with \n`img_tensor = torch.empty((len(data),3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)`\nit will work.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1774187,
      "author_name": "michaln",
      "author_url": "",
      "post_date": "05/02/2022 00:12:54",
      "content": "<p>The notebooks you linked are not accessible (probably set to private) so can't check the code. <br>\nSounds like the output of your inference is not correct (size) and it doesn't set the predictions to the submission right. You could try to make the submission on train images and check if it is created correctly or at least check what is the dimensions/shape of inference output. <br>\nIf you make your notebooks public (or at least some minimal example) it will be easier to give advice.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1774193,
          "author_name": "jaredfeng",
          "author_url": "",
          "post_date": "05/02/2022 00:31:03",
          "content": "<p>Yes doing that on the train images is another good experiment, will do it tomorrow. Btw the two notebooks I quoted were private indeed and I just made them public.</p>\n<p>Thanks!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1774201,
          "author_name": "michaln",
          "author_url": "",
          "post_date": "05/02/2022 00:44:56",
          "content": "<p>The problem is your collate function, specifically this line:</p>\n<p><code>img_tensor = torch.empty((BSZ,3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)</code></p>\n<p>You can see it running this:</p>\n<pre><code>print(\"Test data length:\", len(test_data))\nbatch = next(iter(test_loader))\nprint(\"Batch image data shape:\", batch[\"image\"].shape)\n</code></pre>\n<p>The test data have lenght 1 but your batch data has size 128 because in the test_pipe collate function you always create the img_tensor with BSZ (batch size).</p>\n<p>If you replace the line for img_tensor with <br>\n<code>img_tensor = torch.empty((len(data),3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)</code><br>\nit will work.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1774136": "Hey all, I just resumed my work on this competition after being occupied at school work for a few weeks. I am so stuck now since I don't know how to build submission.csv, even though I carefully checked every piece of suggestion from [this post](https://www.kaggle.com/competitions/hotel-id-to-combat-human-trafficking-2022-fgvc9/discussion/314661). \n\nI tested a few things: (1) I created an empty notebook, called pd.read_csv() on the sample submission csv, and made that as my submission. (2) I followed [this implementation](https://www.kaggle.com/code/michaln/hotel-id-starter-classification-inference) in a notebook that I built previously. To create the test_df, I tried (2a) reading the sample submission csv and (2b) calling os.listdir() on the folder of test images. \n\n**RESULTS:**\n\n(1) made a valid submission with score 0.00. Notebook is [here](https://www.kaggle.com/code/jaredfeng/hotel-id-submission-test).\n\nBoth (2a) and (2b) failed to make valid submissions with a common error. It says the test_df I created only has one row, but the list of predictions has 128 entries. 128 is the batch size I set for the test_loader, but it is also weird that it only has one batch. I previously printed out the 128 predictions in a draft session, it turned out all predictions from row 2-128 were the same, so I assume the corresponding rows in the input tensors were all zeros.\nNotebook is [here](https://www.kaggle.com/code/jaredfeng/hotel-id/notebook?scriptVersionId=94516473).\n\nAny help would be appreciated.\n\n\n**EDIT:**\n\nIssue resolved as per analysis and suggestion from the comment. All notebooks from me have been set to private again, as they were set to public for debugging only. (My approaches were basically ill-developed aka trash so not worth viewing by any means)",
    "1774187": "The notebooks you linked are not accessible (probably set to private) so can't check the code. \nSounds like the output of your inference is not correct (size) and it doesn't set the predictions to the submission right. You could try to make the submission on train images and check if it is created correctly or at least check what is the dimensions/shape of inference output. \nIf you make your notebooks public (or at least some minimal example) it will be easier to give advice.",
    "1774193": "Yes doing that on the train images is another good experiment, will do it tomorrow. Btw the two notebooks I quoted were private indeed and I just made them public.\n\nThanks!",
    "1774201": "The problem is your collate function, specifically this line:\n\n`img_tensor = torch.empty((BSZ,3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)`\n\nYou can see it running this:\n\n```\nprint(\"Test data length:\", len(test_data))\nbatch = next(iter(test_loader))\nprint(\"Batch image data shape:\", batch[\"image\"].shape)\n```\nThe test data have lenght 1 but your batch data has size 128 because in the test_pipe collate function you always create the img_tensor with BSZ (batch size).\n\nIf you replace the line for img_tensor with \n`img_tensor = torch.empty((len(data),3,IMG_SZ,IMG_SZ),dtype=torch.float32).to(device)`\nit will work."
  },
  "source": "meta"
}