{
  "id": 264402,
  "title": "How do you make the submission? ",
  "url": "/competitions/body-morphometry-kidney-and-tumor/discussion/264402",
  "author_name": "",
  "post_date": "2021-08-12T03:20:06.561806300Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I tried to make the submission and I have a few questions:</p>\n<ul>\n<li>the test folder has more than 166 files, why the submission file has only 166 rows?</li>\n<li>how many labels we have? 0 for background, 1 for kidney, 2 for tumor, please correct me if i'm wrong.</li>\n</ul>\n<p>Thank you very much!</p>",
  "messages": [
    {
      "id": "1467522",
      "postDate": "08/12/2021 03:20:06",
      "content": "<p>I tried to make the submission and I have a few questions:</p>\n<ul>\n<li>the test folder has more than 166 files, why the submission file has only 166 rows?</li>\n<li>how many labels we have? 0 for background, 1 for kidney, 2 for tumor, please correct me if i'm wrong.</li>\n</ul>\n<p>Thank you very much!</p>",
      "rawMarkdown": "I tried to make the submission and I have a few questions:\n- the test folder has more than 166 files, why the submission file has only 166 rows?\n- how many labels we have? 0 for background, 1 for kidney, 2 for tumor, please correct me if i'm wrong.\n\nThank you very much!",
      "votes": null
    },
    {
      "id": "1469880",
      "postDate": "08/13/2021 06:56:13",
      "content": "<p>You can use this code for submission.</p>\n<p><code>preds</code> are the predictions of the model.</p>\n<p><code>preds</code> shape : (5312, 512, 512) <br>\nIt has  0,1,2 values</p>\n<pre><code>def rle_encode(mask_image):\n    pixels = mask_image.flatten()\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 2\n    runs[1::2] = runs[1::2] - runs[:-1:2]\n    return runs\n\n\ndef rle_to_string(runs):\n    return ' '.join(str(x) for x in runs)\n\n\npreds_string=[]\nfor i in tqdm(range(0, len(preds), 64)):\n    sample = preds[i:i+64].copy()\n    for label_code in [1,2]:\n        tmp=[]\n        for s in sample:\n            s = np.equal(s, label_code).flatten()*1\n            tmp+=s.tolist()\n        enc = rle_to_string(rle_encode(np.array(tmp)))\n\n        preds_string.append(enc)\n\n\nsample_submission = pd.read_csv('dataset/sample_submission.csv')\nsample_submission['EncodedPixels'] = preds_string\nsample_submission.to_csv('submission.csv', index=False)\n</code></pre>",
      "rawMarkdown": "You can use this code for submission.\n\n```preds``` are the predictions of the model.\n\n```preds``` shape : (5312, 512, 512) \nIt has  0,1,2 values\n```\ndef rle_encode(mask_image):\n    pixels = mask_image.flatten()\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 2\n    runs[1::2] = runs[1::2] - runs[:-1:2]\n    return runs\n\n\ndef rle_to_string(runs):\n    return ' '.join(str(x) for x in runs)\n\n\npreds_string=[]\nfor i in tqdm(range(0, len(preds), 64)):\n    sample = preds[i:i+64].copy()\n    for label_code in [1,2]:\n        tmp=[]\n        for s in sample:\n            s = np.equal(s, label_code).flatten()*1\n            tmp+=s.tolist()\n        enc = rle_to_string(rle_encode(np.array(tmp)))\n\n        preds_string.append(enc)\n\n\nsample_submission = pd.read_csv('dataset/sample_submission.csv')\nsample_submission['EncodedPixels'] = preds_string\nsample_submission.to_csv('submission.csv', index=False)\n\n```",
      "votes": null
    },
    {
      "id": "1469974",
      "postDate": "08/13/2021 07:51:59",
      "content": "<p>thank you 🙏 </p>",
      "rawMarkdown": "thank you 🙏",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1469880,
      "author_name": "jeongmyeong",
      "author_url": "",
      "post_date": "08/13/2021 06:56:13",
      "content": "<p>You can use this code for submission.</p>\n<p><code>preds</code> are the predictions of the model.</p>\n<p><code>preds</code> shape : (5312, 512, 512) <br>\nIt has  0,1,2 values</p>\n<pre><code>def rle_encode(mask_image):\n    pixels = mask_image.flatten()\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 2\n    runs[1::2] = runs[1::2] - runs[:-1:2]\n    return runs\n\n\ndef rle_to_string(runs):\n    return ' '.join(str(x) for x in runs)\n\n\npreds_string=[]\nfor i in tqdm(range(0, len(preds), 64)):\n    sample = preds[i:i+64].copy()\n    for label_code in [1,2]:\n        tmp=[]\n        for s in sample:\n            s = np.equal(s, label_code).flatten()*1\n            tmp+=s.tolist()\n        enc = rle_to_string(rle_encode(np.array(tmp)))\n\n        preds_string.append(enc)\n\n\nsample_submission = pd.read_csv('dataset/sample_submission.csv')\nsample_submission['EncodedPixels'] = preds_string\nsample_submission.to_csv('submission.csv', index=False)\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1469974,
      "author_name": "tuvovan211",
      "author_url": "",
      "post_date": "08/13/2021 07:51:59",
      "content": "<p>thank you 🙏 </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1467522": "I tried to make the submission and I have a few questions:\n- the test folder has more than 166 files, why the submission file has only 166 rows?\n- how many labels we have? 0 for background, 1 for kidney, 2 for tumor, please correct me if i'm wrong.\n\nThank you very much!",
    "1469880": "You can use this code for submission.\n\n```preds``` are the predictions of the model.\n\n```preds``` shape : (5312, 512, 512) \nIt has  0,1,2 values\n```\ndef rle_encode(mask_image):\n    pixels = mask_image.flatten()\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 2\n    runs[1::2] = runs[1::2] - runs[:-1:2]\n    return runs\n\n\ndef rle_to_string(runs):\n    return ' '.join(str(x) for x in runs)\n\n\npreds_string=[]\nfor i in tqdm(range(0, len(preds), 64)):\n    sample = preds[i:i+64].copy()\n    for label_code in [1,2]:\n        tmp=[]\n        for s in sample:\n            s = np.equal(s, label_code).flatten()*1\n            tmp+=s.tolist()\n        enc = rle_to_string(rle_encode(np.array(tmp)))\n\n        preds_string.append(enc)\n\n\nsample_submission = pd.read_csv('dataset/sample_submission.csv')\nsample_submission['EncodedPixels'] = preds_string\nsample_submission.to_csv('submission.csv', index=False)\n\n```",
    "1469974": "thank you 🙏"
  },
  "source": "meta"
}