{
  "id": 291627,
  "title": "Getting stuck with zero LB score",
  "url": "/competitions/sartorius-cell-instance-segmentation/discussion/291627",
  "author_name": "",
  "post_date": "2021-11-30T08:55:41.654625100Z",
  "votes": 5,
  "comment_count": 3,
  "views": 0,
  "content": "<p>Hi everybody<br>\nCould anyone share with me the functions of decoding and encoding rle by which he was able to achieve successful submission?<br>\nThanks in advance</p>",
  "messages": [
    {
      "id": "1600282",
      "postDate": "11/30/2021 08:55:41",
      "content": "<p>Hi everybody<br>\nCould anyone share with me the functions of decoding and encoding rle by which he was able to achieve successful submission?<br>\nThanks in advance</p>",
      "rawMarkdown": "Hi everybody\nCould anyone share with me the functions of decoding and encoding rle by which he was able to achieve successful submission?\nThanks in advance",
      "votes": null
    },
    {
      "id": "1600441",
      "postDate": "11/30/2021 12:29:38",
      "content": "<p>my successful submissions use code from public notebooks, unsuccessful ones too, but maybe you should try using them?</p>\n<pre><code>def rle_decode(mask_rle, shape=(520, 704)):\n    s = mask_rle.split()\n    starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    for lo, hi in zip(starts, ends):\n        img[lo:hi] = 1\n    return img.reshape(shape)  # Needed to align to RLE direction\n\ndef rle_encode(img):\n    pixels = img.flatten()\n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    runs[1::2] -= runs[::2]\n    return ' '.join(str(x) for x in runs)\n</code></pre>",
      "rawMarkdown": "my successful submissions use code from public notebooks, unsuccessful ones too, but maybe you should try using them?\n\n\n    def rle_decode(mask_rle, shape=(520, 704)):\n        s = mask_rle.split()\n        starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n        starts -= 1\n        ends = starts + lengths\n        img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n        for lo, hi in zip(starts, ends):\n            img[lo:hi] = 1\n        return img.reshape(shape)  # Needed to align to RLE direction\n\n    def rle_encode(img):\n        pixels = img.flatten()\n        pixels = np.concatenate([[0], pixels, [0]])\n        runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n        runs[1::2] -= runs[::2]\n        return ' '.join(str(x) for x in runs)",
      "votes": null
    },
    {
      "id": "1600455",
      "postDate": "11/30/2021 12:44:18",
      "content": "<p>Thank you for your reply<br>\nI have used the first function to decode the rle Masks into PNG images <br>\n<a href=\"https://www.kaggle.com/fatmamazen/sartorius-png-masks\" target=\"_blank\">https://www.kaggle.com/fatmamazen/sartorius-png-masks</a><br>\nAnd this is the code I have used to decode and save PNG images<br>\n<a href=\"https://www.kaggle.com/fatmamazen/run-length-decoding-pngmasks-25-11\" target=\"_blank\">https://www.kaggle.com/fatmamazen/run-length-decoding-pngmasks-25-11</a><br>\nBut when I tried to read one of the PNG mask images and pass it as an input to rle_encode<br>\n,I got different rle from the original one <br>\nI do not know why<br>\nI hope you can help me<br>\nShould I perform any transformations to the test image before passing it to the model?</p>",
      "rawMarkdown": "Thank you for your reply\nI have used the first function to decode the rle Masks into PNG images \nhttps://www.kaggle.com/fatmamazen/sartorius-png-masks\nAnd this is the code I have used to decode and save PNG images\nhttps://www.kaggle.com/fatmamazen/run-length-decoding-pngmasks-25-11\nBut when I tried to read one of the PNG mask images and pass it as an input to rle_encode\n,I got different rle from the original one \nI do not know why\nI hope you can help me\nShould I perform any transformations to the test image before passing it to the model?",
      "votes": null
    },
    {
      "id": "1600489",
      "postDate": "11/30/2021 13:14:33",
      "content": "<p>unfortunately, the page you gave as an example does not exist.<br>\nperhaps this will help you, with a little reworking for your task:</p>\n<pre><code>gt = cv2.imread(gt, -1)\nlabel = np.unique(gt)\nheight, width = img.shape[:2]\nvisual_img = np.zeros((height, width, 3))\nfor lab in label:\n     if lab == 0:\n         continue\n     color = np.random.randint(low=0, high=255, size=3)\n     visual_img[gt==lab, :] = color\n</code></pre>",
      "rawMarkdown": "unfortunately, the page you gave as an example does not exist.\nperhaps this will help you, with a little reworking for your task:\n\n    gt = cv2.imread(gt, -1)\n    label = np.unique(gt)\n    height, width = img.shape[:2]\n    visual_img = np.zeros((height, width, 3))\n    for lab in label:\n         if lab == 0:\n             continue\n         color = np.random.randint(low=0, high=255, size=3)\n         visual_img[gt==lab, :] = color",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1600441,
      "author_name": "zaakciiru",
      "author_url": "",
      "post_date": "11/30/2021 12:29:38",
      "content": "<p>my successful submissions use code from public notebooks, unsuccessful ones too, but maybe you should try using them?</p>\n<pre><code>def rle_decode(mask_rle, shape=(520, 704)):\n    s = mask_rle.split()\n    starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    for lo, hi in zip(starts, ends):\n        img[lo:hi] = 1\n    return img.reshape(shape)  # Needed to align to RLE direction\n\ndef rle_encode(img):\n    pixels = img.flatten()\n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    runs[1::2] -= runs[::2]\n    return ' '.join(str(x) for x in runs)\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 1600455,
          "author_name": "fatmamazen",
          "author_url": "",
          "post_date": "11/30/2021 12:44:18",
          "content": "<p>Thank you for your reply<br>\nI have used the first function to decode the rle Masks into PNG images <br>\n<a href=\"https://www.kaggle.com/fatmamazen/sartorius-png-masks\" target=\"_blank\">https://www.kaggle.com/fatmamazen/sartorius-png-masks</a><br>\nAnd this is the code I have used to decode and save PNG images<br>\n<a href=\"https://www.kaggle.com/fatmamazen/run-length-decoding-pngmasks-25-11\" target=\"_blank\">https://www.kaggle.com/fatmamazen/run-length-decoding-pngmasks-25-11</a><br>\nBut when I tried to read one of the PNG mask images and pass it as an input to rle_encode<br>\n,I got different rle from the original one <br>\nI do not know why<br>\nI hope you can help me<br>\nShould I perform any transformations to the test image before passing it to the model?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1600489,
          "author_name": "zaakciiru",
          "author_url": "",
          "post_date": "11/30/2021 13:14:33",
          "content": "<p>unfortunately, the page you gave as an example does not exist.<br>\nperhaps this will help you, with a little reworking for your task:</p>\n<pre><code>gt = cv2.imread(gt, -1)\nlabel = np.unique(gt)\nheight, width = img.shape[:2]\nvisual_img = np.zeros((height, width, 3))\nfor lab in label:\n     if lab == 0:\n         continue\n     color = np.random.randint(low=0, high=255, size=3)\n     visual_img[gt==lab, :] = color\n</code></pre>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1600282": "Hi everybody\nCould anyone share with me the functions of decoding and encoding rle by which he was able to achieve successful submission?\nThanks in advance",
    "1600441": "my successful submissions use code from public notebooks, unsuccessful ones too, but maybe you should try using them?\n\n\n    def rle_decode(mask_rle, shape=(520, 704)):\n        s = mask_rle.split()\n        starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n        starts -= 1\n        ends = starts + lengths\n        img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n        for lo, hi in zip(starts, ends):\n            img[lo:hi] = 1\n        return img.reshape(shape)  # Needed to align to RLE direction\n\n    def rle_encode(img):\n        pixels = img.flatten()\n        pixels = np.concatenate([[0], pixels, [0]])\n        runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n        runs[1::2] -= runs[::2]\n        return ' '.join(str(x) for x in runs)",
    "1600455": "Thank you for your reply\nI have used the first function to decode the rle Masks into PNG images \nhttps://www.kaggle.com/fatmamazen/sartorius-png-masks\nAnd this is the code I have used to decode and save PNG images\nhttps://www.kaggle.com/fatmamazen/run-length-decoding-pngmasks-25-11\nBut when I tried to read one of the PNG mask images and pass it as an input to rle_encode\n,I got different rle from the original one \nI do not know why\nI hope you can help me\nShould I perform any transformations to the test image before passing it to the model?",
    "1600489": "unfortunately, the page you gave as an example does not exist.\nperhaps this will help you, with a little reworking for your task:\n\n    gt = cv2.imread(gt, -1)\n    label = np.unique(gt)\n    height, width = img.shape[:2]\n    visual_img = np.zeros((height, width, 3))\n    for lab in label:\n         if lab == 0:\n             continue\n         color = np.random.randint(low=0, high=255, size=3)\n         visual_img[gt==lab, :] = color"
  },
  "source": "meta"
}