{
  "id": 232321,
  "title": " visualization",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/232321",
  "author_name": "",
  "post_date": "2021-04-13T08:44:15.851935700Z",
  "votes": 1,
  "comment_count": 7,
  "views": 0,
  "content": "<p>How can I visualize the predicted outputs?</p>",
  "messages": [
    {
      "id": "1272124",
      "postDate": "04/13/2021 08:44:15",
      "content": "<p>How can I visualize the predicted outputs?</p>",
      "rawMarkdown": "How can I visualize the predicted outputs?",
      "votes": null
    },
    {
      "id": "1272128",
      "postDate": "04/13/2021 08:51:25",
      "content": "<p>fig, ax = plt.subplots(figsize=(15,15))<br>\nax.imshow(cv2.resize(result[:].astype(np.uint8), (1024, 1024)))<br>\nplt.show()</p>",
      "rawMarkdown": "fig, ax = plt.subplots(figsize=(15,15))\n    ax.imshow(cv2.resize(result[:].astype(np.uint8), (1024, 1024)))\n    plt.show()",
      "votes": null
    },
    {
      "id": "1272331",
      "postDate": "04/13/2021 12:05:41",
      "content": "<p>You must first convert the predicted <code>rle</code> to a <code>mask</code> with the following function. Then plot with <code>matplotlib</code>.</p>\n<pre><code>def rle2mask(mask_rle, shape=(1600,256)):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (width,height) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n    Source: https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\n    '''\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).T\n</code></pre>\n<p>Make sure you input the correct <code>shape</code>. So for example if you wish to visualize the mask for test image <code>aa05346ff.tiff</code>, then type</p>\n<pre><code>import matplotlib.pyplot as plt\nmask = rle2mask( PREDICTED_RLE_STRING, shape=(30720,47340) )\nplt.figure(figsize=(20,10))\nplt.imshow(mask[::10,::10])\nplt.show()\n</code></pre>",
      "rawMarkdown": "You must first convert the predicted `rle` to a `mask` with the following function. Then plot with `matplotlib`.\n\n    def rle2mask(mask_rle, shape=(1600,256)):\n        '''\n        mask_rle: run-length as string formated (start length)\n        shape: (width,height) of array to return \n        Returns numpy array, 1 - mask, 0 - background\n        Source: https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\n        '''\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).T\n\nMake sure you input the correct `shape`. So for example if you wish to visualize the mask for test image `aa05346ff.tiff`, then type\n\n    import matplotlib.pyplot as plt\n    mask = rle2mask( PREDICTED_RLE_STRING, shape=(30720,47340) )\n    plt.figure(figsize=(20,10))\n    plt.imshow(mask[::10,::10])\n    plt.show()",
      "votes": null
    },
    {
      "id": "1272423",
      "postDate": "04/13/2021 13:14:23",
      "content": "<p>thank you for your help, i try it now</p>",
      "rawMarkdown": "thank you for your help, i try it now",
      "votes": null
    },
    {
      "id": "1272424",
      "postDate": "04/13/2021 13:16:32",
      "content": "<p>thank you for your help, there may be another way to get it.</p>",
      "rawMarkdown": "thank you for your help, there may be another way to get it.",
      "votes": null
    },
    {
      "id": "1272427",
      "postDate": "04/13/2021 13:18:45",
      "content": "<p>Here are the shapes for the 5 public test images</p>\n<p>2ec3f1bb9 (23990, 47723)<br>\n3589adb90 (29433, 22165)<br>\nd488c759a (46660, 29020)<br>\naa05346ff (30720, 47340)<br>\n57512b7f1 (33240, 43160)</p>",
      "rawMarkdown": "Here are the shapes for the 5 public test images\n\n2ec3f1bb9 (23990, 47723)\n3589adb90 (29433, 22165)\nd488c759a (46660, 29020)\naa05346ff (30720, 47340)\n57512b7f1 (33240, 43160)",
      "votes": null
    },
    {
      "id": "1272474",
      "postDate": "04/13/2021 13:59:21",
      "content": "<p>oh yes, thanks a lot.</p>",
      "rawMarkdown": "oh yes, thanks a lot.",
      "votes": null
    },
    {
      "id": "1272516",
      "postDate": "04/13/2021 14:43:47",
      "content": "<p>Heym bro, it seems to be different between the predicted mask and test image.</p>\n<p><a href=\"https://www.kaggle.com/gjzhongdf163com/humap-visualization\" target=\"_blank\">https://www.kaggle.com/gjzhongdf163com/humap-visualization</a></p>",
      "rawMarkdown": "Heym bro, it seems to be different between the predicted mask and test image.\n\nhttps://www.kaggle.com/gjzhongdf163com/humap-visualization",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1272128,
      "author_name": "zavodrobotov",
      "author_url": "",
      "post_date": "04/13/2021 08:51:25",
      "content": "<p>fig, ax = plt.subplots(figsize=(15,15))<br>\nax.imshow(cv2.resize(result[:].astype(np.uint8), (1024, 1024)))<br>\nplt.show()</p>",
      "votes": null,
      "replies": [
        {
          "id": 1272424,
          "author_name": "gjzhongdf163com",
          "author_url": "",
          "post_date": "04/13/2021 13:16:32",
          "content": "<p>thank you for your help, there may be another way to get it.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1272331,
      "author_name": "cdeotte",
      "author_url": "",
      "post_date": "04/13/2021 12:05:41",
      "content": "<p>You must first convert the predicted <code>rle</code> to a <code>mask</code> with the following function. Then plot with <code>matplotlib</code>.</p>\n<pre><code>def rle2mask(mask_rle, shape=(1600,256)):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (width,height) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n    Source: https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\n    '''\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).T\n</code></pre>\n<p>Make sure you input the correct <code>shape</code>. So for example if you wish to visualize the mask for test image <code>aa05346ff.tiff</code>, then type</p>\n<pre><code>import matplotlib.pyplot as plt\nmask = rle2mask( PREDICTED_RLE_STRING, shape=(30720,47340) )\nplt.figure(figsize=(20,10))\nplt.imshow(mask[::10,::10])\nplt.show()\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 1272423,
          "author_name": "gjzhongdf163com",
          "author_url": "",
          "post_date": "04/13/2021 13:14:23",
          "content": "<p>thank you for your help, i try it now</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1272427,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "04/13/2021 13:18:45",
          "content": "<p>Here are the shapes for the 5 public test images</p>\n<p>2ec3f1bb9 (23990, 47723)<br>\n3589adb90 (29433, 22165)<br>\nd488c759a (46660, 29020)<br>\naa05346ff (30720, 47340)<br>\n57512b7f1 (33240, 43160)</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1272474,
          "author_name": "gjzhongdf163com",
          "author_url": "",
          "post_date": "04/13/2021 13:59:21",
          "content": "<p>oh yes, thanks a lot.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1272516,
          "author_name": "gjzhongdf163com",
          "author_url": "",
          "post_date": "04/13/2021 14:43:47",
          "content": "<p>Heym bro, it seems to be different between the predicted mask and test image.</p>\n<p><a href=\"https://www.kaggle.com/gjzhongdf163com/humap-visualization\" target=\"_blank\">https://www.kaggle.com/gjzhongdf163com/humap-visualization</a></p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1272124": "How can I visualize the predicted outputs?",
    "1272128": "fig, ax = plt.subplots(figsize=(15,15))\n    ax.imshow(cv2.resize(result[:].astype(np.uint8), (1024, 1024)))\n    plt.show()",
    "1272331": "You must first convert the predicted `rle` to a `mask` with the following function. Then plot with `matplotlib`.\n\n    def rle2mask(mask_rle, shape=(1600,256)):\n        '''\n        mask_rle: run-length as string formated (start length)\n        shape: (width,height) of array to return \n        Returns numpy array, 1 - mask, 0 - background\n        Source: https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\n        '''\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).T\n\nMake sure you input the correct `shape`. So for example if you wish to visualize the mask for test image `aa05346ff.tiff`, then type\n\n    import matplotlib.pyplot as plt\n    mask = rle2mask( PREDICTED_RLE_STRING, shape=(30720,47340) )\n    plt.figure(figsize=(20,10))\n    plt.imshow(mask[::10,::10])\n    plt.show()",
    "1272423": "thank you for your help, i try it now",
    "1272424": "thank you for your help, there may be another way to get it.",
    "1272427": "Here are the shapes for the 5 public test images\n\n2ec3f1bb9 (23990, 47723)\n3589adb90 (29433, 22165)\nd488c759a (46660, 29020)\naa05346ff (30720, 47340)\n57512b7f1 (33240, 43160)",
    "1272474": "oh yes, thanks a lot.",
    "1272516": "Heym bro, it seems to be different between the predicted mask and test image.\n\nhttps://www.kaggle.com/gjzhongdf163com/humap-visualization"
  },
  "source": "meta"
}