{
  "id": 202997,
  "title": "How to submit predictions",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/202997",
  "author_name": "",
  "post_date": "2020-12-13T06:23:48.914461100Z",
  "votes": null,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I've been trying to submit my first prediction to no avial. I have a very basic minimal model and am saving the output \"submission.csv\" to the working directory. I've done Commit &amp; Run All several times, but when I view my notebook, i only see the actual images as Output, not my prediction file.</p>\n<p>Can anyone tell me what I'm missing ?</p>\n<p><a href=\"https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49194630\" target=\"_blank\">https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49194630</a></p>",
  "messages": [
    {
      "id": "1110853",
      "postDate": "12/13/2020 06:23:48",
      "content": "<p>I've been trying to submit my first prediction to no avial. I have a very basic minimal model and am saving the output \"submission.csv\" to the working directory. I've done Commit &amp; Run All several times, but when I view my notebook, i only see the actual images as Output, not my prediction file.</p>\n<p>Can anyone tell me what I'm missing ?</p>\n<p><a href=\"https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49194630\" target=\"_blank\">https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49194630</a></p>",
      "rawMarkdown": "I've been trying to submit my first prediction to no avial. I have a very basic minimal model and am saving the output \"submission.csv\" to the working directory. I've done Commit & Run All several times, but when I view my notebook, i only see the actual images as Output, not my prediction file.\n\nCan anyone tell me what I'm missing ?\n\nhttps://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49194630",
      "votes": null
    },
    {
      "id": "1110957",
      "postDate": "12/13/2020 08:33:58",
      "content": "<p>It looks like you are getting the test images name directly from the directory <code>cassava-leaf-disease-classification/test_images</code>:</p>\n<pre><code>test_image_names = []\n\nfor i in os.listdir(test_path):\n    test_image_names.append(i)\n</code></pre>\n<p>It is probably better to read the <code>sample_submission.csv</code> to get the image paths as you won't be able to tell the order in which the image paths are presented in the <code>sample_submission.csv</code> of the private test set.</p>\n<p>One way to do it could be:</p>\n<pre><code>test_imgs_folder = '../input/cassava-leaf-disease-classification/test_images/'\ntest_csv = '../input/cassava-leaf-disease-classification/sample_submission.csv'\nsubmission = pd.read_csv(test_csv)  # Read the sample_submission.csv.\n\npreds = []  # Create an array to store the prediction for each image.\n# ---------- your code to loop through each entry in `submission` ---------- #\n# can do something like (in *pseudo-code*):\nfor img in submission['image_id']:\n    pred = model(os.path.join(test_imgs_folder, img))\n    preds.append(pred)\n# ---------- /your code to loop through each entry in `submission` ---------- #\n\nsubmission['label'] = preds  # Replace the labels column with your preds.\nsubmission.to_csv('submission.csv', index=False)  # Write the dataframe into a csv for submission.\n</code></pre>",
      "rawMarkdown": "It looks like you are getting the test images name directly from the directory `cassava-leaf-disease-classification/test_images`:\n```\ntest_image_names = []\n\nfor i in os.listdir(test_path):\n    test_image_names.append(i)\n```\n\nIt is probably better to read the `sample_submission.csv` to get the image paths as you won't be able to tell the order in which the image paths are presented in the `sample_submission.csv` of the private test set.\n\nOne way to do it could be:\n```\ntest_imgs_folder = '../input/cassava-leaf-disease-classification/test_images/'\ntest_csv = '../input/cassava-leaf-disease-classification/sample_submission.csv'\nsubmission = pd.read_csv(test_csv)  # Read the sample_submission.csv.\n\npreds = []  # Create an array to store the prediction for each image.\n# ---------- your code to loop through each entry in `submission` ---------- #\n# can do something like (in *pseudo-code*):\nfor img in submission['image_id']:\n    pred = model(os.path.join(test_imgs_folder, img))\n    preds.append(pred)\n# ---------- /your code to loop through each entry in `submission` ---------- #\n\nsubmission['label'] = preds  # Replace the labels column with your preds.\nsubmission.to_csv('submission.csv', index=False)  # Write the dataframe into a csv for submission.\n```",
      "votes": null
    },
    {
      "id": "1112075",
      "postDate": "12/14/2020 09:03:58",
      "content": "<p>Thank you for your response - I tried what you said, but still I'm not seeing an Output file.<br>\nThe only thing I see is an Output visualization - not sure where that is coming from.</p>\n<p>Any other ideas ? </p>\n<p><a href=\"https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49285376\" target=\"_blank\">https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49285376</a></p>",
      "rawMarkdown": "Thank you for your response - I tried what you said, but still I'm not seeing an Output file.\nThe only thing I see is an Output visualization - not sure where that is coming from.\n\nAny other ideas ? \n\nhttps://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49285376",
      "votes": null
    },
    {
      "id": "1112368",
      "postDate": "12/14/2020 14:15:51",
      "content": "<p>Why are you saving <code>submission.csv</code> twice?:</p>\n<pre><code>submission.to_csv('submission.csv', index = False)\nsubmission.to_csv('/kaggle/working/submission.csv', index = False)\n</code></pre>\n<p>I think just this will do:</p>\n<pre><code>submission.to_csv('submission.csv', index = False)\n</code></pre>",
      "rawMarkdown": "Why are you saving `submission.csv` twice?:\n```\nsubmission.to_csv('submission.csv', index = False)\nsubmission.to_csv('/kaggle/working/submission.csv', index = False)\n```\nI think just this will do:\n```\nsubmission.to_csv('submission.csv', index = False)\n```",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1110957,
      "author_name": "polars",
      "author_url": "",
      "post_date": "12/13/2020 08:33:58",
      "content": "<p>It looks like you are getting the test images name directly from the directory <code>cassava-leaf-disease-classification/test_images</code>:</p>\n<pre><code>test_image_names = []\n\nfor i in os.listdir(test_path):\n    test_image_names.append(i)\n</code></pre>\n<p>It is probably better to read the <code>sample_submission.csv</code> to get the image paths as you won't be able to tell the order in which the image paths are presented in the <code>sample_submission.csv</code> of the private test set.</p>\n<p>One way to do it could be:</p>\n<pre><code>test_imgs_folder = '../input/cassava-leaf-disease-classification/test_images/'\ntest_csv = '../input/cassava-leaf-disease-classification/sample_submission.csv'\nsubmission = pd.read_csv(test_csv)  # Read the sample_submission.csv.\n\npreds = []  # Create an array to store the prediction for each image.\n# ---------- your code to loop through each entry in `submission` ---------- #\n# can do something like (in *pseudo-code*):\nfor img in submission['image_id']:\n    pred = model(os.path.join(test_imgs_folder, img))\n    preds.append(pred)\n# ---------- /your code to loop through each entry in `submission` ---------- #\n\nsubmission['label'] = preds  # Replace the labels column with your preds.\nsubmission.to_csv('submission.csv', index=False)  # Write the dataframe into a csv for submission.\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1112075,
      "author_name": "lrmeulman",
      "author_url": "",
      "post_date": "12/14/2020 09:03:58",
      "content": "<p>Thank you for your response - I tried what you said, but still I'm not seeing an Output file.<br>\nThe only thing I see is an Output visualization - not sure where that is coming from.</p>\n<p>Any other ideas ? </p>\n<p><a href=\"https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49285376\" target=\"_blank\">https://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49285376</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1112368,
          "author_name": "polars",
          "author_url": "",
          "post_date": "12/14/2020 14:15:51",
          "content": "<p>Why are you saving <code>submission.csv</code> twice?:</p>\n<pre><code>submission.to_csv('submission.csv', index = False)\nsubmission.to_csv('/kaggle/working/submission.csv', index = False)\n</code></pre>\n<p>I think just this will do:</p>\n<pre><code>submission.to_csv('submission.csv', index = False)\n</code></pre>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1110853": "I've been trying to submit my first prediction to no avial. I have a very basic minimal model and am saving the output \"submission.csv\" to the working directory. I've done Commit & Run All several times, but when I view my notebook, i only see the actual images as Output, not my prediction file.\n\nCan anyone tell me what I'm missing ?\n\nhttps://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49194630",
    "1110957": "It looks like you are getting the test images name directly from the directory `cassava-leaf-disease-classification/test_images`:\n```\ntest_image_names = []\n\nfor i in os.listdir(test_path):\n    test_image_names.append(i)\n```\n\nIt is probably better to read the `sample_submission.csv` to get the image paths as you won't be able to tell the order in which the image paths are presented in the `sample_submission.csv` of the private test set.\n\nOne way to do it could be:\n```\ntest_imgs_folder = '../input/cassava-leaf-disease-classification/test_images/'\ntest_csv = '../input/cassava-leaf-disease-classification/sample_submission.csv'\nsubmission = pd.read_csv(test_csv)  # Read the sample_submission.csv.\n\npreds = []  # Create an array to store the prediction for each image.\n# ---------- your code to loop through each entry in `submission` ---------- #\n# can do something like (in *pseudo-code*):\nfor img in submission['image_id']:\n    pred = model(os.path.join(test_imgs_folder, img))\n    preds.append(pred)\n# ---------- /your code to loop through each entry in `submission` ---------- #\n\nsubmission['label'] = preds  # Replace the labels column with your preds.\nsubmission.to_csv('submission.csv', index=False)  # Write the dataframe into a csv for submission.\n```",
    "1112075": "Thank you for your response - I tried what you said, but still I'm not seeing an Output file.\nThe only thing I see is an Output visualization - not sure where that is coming from.\n\nAny other ideas ? \n\nhttps://www.kaggle.com/lrmeulman/cassava-notebook?scriptVersionId=49285376",
    "1112368": "Why are you saving `submission.csv` twice?:\n```\nsubmission.to_csv('submission.csv', index = False)\nsubmission.to_csv('/kaggle/working/submission.csv', index = False)\n```\nI think just this will do:\n```\nsubmission.to_csv('submission.csv', index = False)\n```"
  },
  "source": "meta"
}