{
  "id": 48548,
  "title": "Instance segmentation and RLE",
  "url": "/competitions/data-science-bowl-2018/discussion/48548",
  "author_name": "",
  "post_date": "2018-01-29T15:30:49.141157Z",
  "votes": 1,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I'm a little confused (happens all the time). This competition appears to be essentially an instance segmentation task where we predict multiple masks, one for each nucleus. But when we submit the predictions to Kaggle we're supposed to run-length encode everything into a single mask (per test image). How does Kaggle tell apart our individual predictions from this single mask?</p>\n\n<p>For example, if the prediction is:</p>\n\n<pre><code>....XXXXXXXXzzzzz.....\n</code></pre>\n\n<p>where . is the background, X is the first mask, and z is the second mask, then in the RLE data this is encoded as:</p>\n\n<pre><code>4 8 12 5\n</code></pre>\n\n<p>But decoded that becomes,</p>\n\n<pre><code>....XXXXXXXXXXXXX.....\n</code></pre>\n\n<p>because the submission only records at which pixel a mask begins and how long it is, but we do not give each mask a unique identifier.</p>\n\n<p>So how can Kaggle reconstruct my two masks from this submission, for computing the mAP?</p>",
  "messages": [
    {
      "id": "275607",
      "postDate": "01/29/2018 15:30:49",
      "content": "<p>I'm a little confused (happens all the time). This competition appears to be essentially an instance segmentation task where we predict multiple masks, one for each nucleus. But when we submit the predictions to Kaggle we're supposed to run-length encode everything into a single mask (per test image). How does Kaggle tell apart our individual predictions from this single mask?</p>\n\n<p>For example, if the prediction is:</p>\n\n<pre><code>....XXXXXXXXzzzzz.....\n</code></pre>\n\n<p>where . is the background, X is the first mask, and z is the second mask, then in the RLE data this is encoded as:</p>\n\n<pre><code>4 8 12 5\n</code></pre>\n\n<p>But decoded that becomes,</p>\n\n<pre><code>....XXXXXXXXXXXXX.....\n</code></pre>\n\n<p>because the submission only records at which pixel a mask begins and how long it is, but we do not give each mask a unique identifier.</p>\n\n<p>So how can Kaggle reconstruct my two masks from this submission, for computing the mAP?</p>",
      "rawMarkdown": "I'm a little confused (happens all the time). This competition appears to be essentially an instance segmentation task where we predict multiple masks, one for each nucleus. But when we submit the predictions to Kaggle we're supposed to run-length encode everything into a single mask (per test image). How does Kaggle tell apart our individual predictions from this single mask?\n\nFor example, if the prediction is:\n\n\t....XXXXXXXXzzzzz.....\n\nwhere . is the background, X is the first mask, and z is the second mask, then in the RLE data this is encoded as:\n\n    4 8 12 5\n\nBut decoded that becomes,\n\n\t....XXXXXXXXXXXXX.....\n\nbecause the submission only records at which pixel a mask begins and how long it is, but we do not give each mask a unique identifier.\n\nSo how can Kaggle reconstruct my two masks from this submission, for computing the mAP?",
      "votes": null
    },
    {
      "id": "275618",
      "postDate": "01/29/2018 16:33:01",
      "content": "<p>Hello Human :)</p>\n\n<p>In fact, the task is to predict the cell nucleus, but, depending on how is your approach the final step (build the submission file may vary).\nFor example, take a look at the code from @<a href=\"https://www.kaggle.com/keegil/keras-u-net-starter-lb-0-277\">keegil</a>: there is an U-net that predicts one mask with all nucleus, but when you call the prob_to_rles function the image is segmented using the <code>skimage.morphology.label</code> function, then the code encode each segment :</p>\n\n<pre><code>new_test_ids = []\nrles = []\nfor n, id_ in enumerate(test_ids):\n    rle = list(prob_to_rles(preds_test_upsampled[n]))\n    rles.extend(rle)\n    new_test_ids.extend([id_] * len(rle))\n</code></pre>\n\n<p>then create the CSV, one line per labeled object :</p>\n\n<pre><code>sub = pd.DataFrame()\nsub['ImageId'] = new_test_ids\nsub['EncodedPixels'] = pd.Series(rles).apply(lambda x: ' '.join(str(y) for y in x))\nsub.to_csv('sub-dsbowl2018-1.csv', index=False)\n</code></pre>",
      "rawMarkdown": "Hello Human :)\n\nIn fact, the task is to predict the cell nucleus, but, depending on how is your approach the final step (build the submission file may vary).\nFor example, take a look at the code from @[keegil][1]: there is an U-net that predicts one mask with all nucleus, but when you call the prob_to_rles function the image is segmented using the `skimage.morphology.label` function, then the code encode each segment :\n\n\n    new_test_ids = []\n    rles = []\n    for n, id_ in enumerate(test_ids):\n        rle = list(prob_to_rles(preds_test_upsampled[n]))\n        rles.extend(rle)\n        new_test_ids.extend([id_] * len(rle))\n\nthen create the CSV, one line per labeled object :\n\n    sub = pd.DataFrame()\n    sub['ImageId'] = new_test_ids\n    sub['EncodedPixels'] = pd.Series(rles).apply(lambda x: ' '.join(str(y) for y in x))\n    sub.to_csv('sub-dsbowl2018-1.csv', index=False)\n\n\n  [1]: https://www.kaggle.com/keegil/keras-u-net-starter-lb-0-277",
      "votes": null
    },
    {
      "id": "275619",
      "postDate": "01/29/2018 16:34:25",
      "content": "<p>Hi, as I understand the rules each line in the submission file corresponds to one nucleus. So, in your example it would be:\n[ImageId], 4 8\n[ImageId], 12 5</p>",
      "rawMarkdown": "Hi, as I understand the rules each line in the submission file corresponds to one nucleus. So, in your example it would be:\n[ImageId], 4 8\n[ImageId], 12 5",
      "votes": null
    },
    {
      "id": "275620",
      "postDate": "01/29/2018 16:34:33",
      "content": "<p>Ah, so we can submit a separate line in the CSV for each mask. So if image A has 10 masks, it will appear 10 times in the CSV file. That makes sense! :-D</p>",
      "rawMarkdown": "Ah, so we can submit a separate line in the CSV for each mask. So if image A has 10 masks, it will appear 10 times in the CSV file. That makes sense! :-D",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 275618,
      "author_name": "aglotero",
      "author_url": "",
      "post_date": "01/29/2018 16:33:01",
      "content": "<p>Hello Human :)</p>\n\n<p>In fact, the task is to predict the cell nucleus, but, depending on how is your approach the final step (build the submission file may vary).\nFor example, take a look at the code from @<a href=\"https://www.kaggle.com/keegil/keras-u-net-starter-lb-0-277\">keegil</a>: there is an U-net that predicts one mask with all nucleus, but when you call the prob_to_rles function the image is segmented using the <code>skimage.morphology.label</code> function, then the code encode each segment :</p>\n\n<pre><code>new_test_ids = []\nrles = []\nfor n, id_ in enumerate(test_ids):\n    rle = list(prob_to_rles(preds_test_upsampled[n]))\n    rles.extend(rle)\n    new_test_ids.extend([id_] * len(rle))\n</code></pre>\n\n<p>then create the CSV, one line per labeled object :</p>\n\n<pre><code>sub = pd.DataFrame()\nsub['ImageId'] = new_test_ids\nsub['EncodedPixels'] = pd.Series(rles).apply(lambda x: ' '.join(str(y) for y in x))\nsub.to_csv('sub-dsbowl2018-1.csv', index=False)\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 275619,
      "author_name": "kerrydonnyclark",
      "author_url": "",
      "post_date": "01/29/2018 16:34:25",
      "content": "<p>Hi, as I understand the rules each line in the submission file corresponds to one nucleus. So, in your example it would be:\n[ImageId], 4 8\n[ImageId], 12 5</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 275620,
      "author_name": "humananalog",
      "author_url": "",
      "post_date": "01/29/2018 16:34:33",
      "content": "<p>Ah, so we can submit a separate line in the CSV for each mask. So if image A has 10 masks, it will appear 10 times in the CSV file. That makes sense! :-D</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "275607": "I'm a little confused (happens all the time). This competition appears to be essentially an instance segmentation task where we predict multiple masks, one for each nucleus. But when we submit the predictions to Kaggle we're supposed to run-length encode everything into a single mask (per test image). How does Kaggle tell apart our individual predictions from this single mask?\n\nFor example, if the prediction is:\n\n\t....XXXXXXXXzzzzz.....\n\nwhere . is the background, X is the first mask, and z is the second mask, then in the RLE data this is encoded as:\n\n    4 8 12 5\n\nBut decoded that becomes,\n\n\t....XXXXXXXXXXXXX.....\n\nbecause the submission only records at which pixel a mask begins and how long it is, but we do not give each mask a unique identifier.\n\nSo how can Kaggle reconstruct my two masks from this submission, for computing the mAP?",
    "275618": "Hello Human :)\n\nIn fact, the task is to predict the cell nucleus, but, depending on how is your approach the final step (build the submission file may vary).\nFor example, take a look at the code from @[keegil][1]: there is an U-net that predicts one mask with all nucleus, but when you call the prob_to_rles function the image is segmented using the `skimage.morphology.label` function, then the code encode each segment :\n\n\n    new_test_ids = []\n    rles = []\n    for n, id_ in enumerate(test_ids):\n        rle = list(prob_to_rles(preds_test_upsampled[n]))\n        rles.extend(rle)\n        new_test_ids.extend([id_] * len(rle))\n\nthen create the CSV, one line per labeled object :\n\n    sub = pd.DataFrame()\n    sub['ImageId'] = new_test_ids\n    sub['EncodedPixels'] = pd.Series(rles).apply(lambda x: ' '.join(str(y) for y in x))\n    sub.to_csv('sub-dsbowl2018-1.csv', index=False)\n\n\n  [1]: https://www.kaggle.com/keegil/keras-u-net-starter-lb-0-277",
    "275619": "Hi, as I understand the rules each line in the submission file corresponds to one nucleus. So, in your example it would be:\n[ImageId], 4 8\n[ImageId], 12 5",
    "275620": "Ah, so we can submit a separate line in the CSV for each mask. So if image A has 10 masks, it will appear 10 times in the CSV file. That makes sense! :-D"
  },
  "source": "meta"
}