{
  "id": 353878,
  "title": "[placeholder] Start to build a 3d solution with MONAI",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/353878",
  "author_name": "Yiheng Wang",
  "post_date": "2022-09-20T09:31:19.564000",
  "votes": 15,
  "comment_count": 9,
  "views": 0,
  "content": "<p>I'm starting to take part in this competition, and my main purpose is to build a 3d solution with MONAI.</p>\n<p>progress:</p>\n<ul>\n<li>built a notebook to introduce how to load 3d dicom images and masks (see <a href=\"https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai\" target=\"_blank\">here</a>)</li>\n<li>create a dataset that contains all gif files to visualize the images and masks (see <a href=\"https://www.kaggle.com/datasets/yiheng/rsna-2022-mask-visualize\" target=\"_blank\">here</a>)</li>\n<li>built a notebook to show how to save nii format images (see <a href=\"https://www.kaggle.com/yiheng/prepare-nii-format-data-with-monai\" target=\"_blank\">here</a>)</li>\n</ul>",
  "messages": [
    {
      "id": 1947134,
      "postDate": "2022-09-20T09:31:19.563Z",
      "content": "<p>I'm starting to take part in this competition, and my main purpose is to build a 3d solution with MONAI.</p>\n<p>progress:</p>\n<ul>\n<li>built a notebook to introduce how to load 3d dicom images and masks (see <a href=\"https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai\" target=\"_blank\">here</a>)</li>\n<li>create a dataset that contains all gif files to visualize the images and masks (see <a href=\"https://www.kaggle.com/datasets/yiheng/rsna-2022-mask-visualize\" target=\"_blank\">here</a>)</li>\n<li>built a notebook to show how to save nii format images (see <a href=\"https://www.kaggle.com/yiheng/prepare-nii-format-data-with-monai\" target=\"_blank\">here</a>)</li>\n</ul>",
      "rawMarkdown": "I'm starting to take part in this competition, and my main purpose is to build a 3d solution with MONAI.\n\nprogress:\n- built a notebook to introduce how to load 3d dicom images and masks (see [here](https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai))\n- create a dataset that contains all gif files to visualize the images and masks (see [here](https://www.kaggle.com/datasets/yiheng/rsna-2022-mask-visualize))\n- built a notebook to show how to save nii format images (see [here](https://www.kaggle.com/yiheng/prepare-nii-format-data-with-monai))",
      "votes": 15
    },
    {
      "id": 1949775,
      "postDate": "2022-09-21T22:00:01.943Z",
      "content": "<p>i spend several weeks on 3d solution. But 3d is (much worse?) worse than 2d, which i cannot understand why.<br>\nthis is the same case for the previous UW-Madison GI Tract Image Segmentation. </p>",
      "rawMarkdown": "i spend several weeks on 3d solution. But 3d is (much worse?) worse than 2d, which i cannot understand why.\nthis is the same case for the previous UW-Madison GI Tract Image Segmentation. ",
      "votes": 3,
      "replies": [
        {
          "id": 1951951,
          "postDate": "2022-09-23T11:08:37.707Z",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> , I'm not sure but according to my experience in <code>UW-Madison GI Tract Image Segmentation</code>, tune a 3d model is much hard than 2d model. I also put weeks to get a reasonable performance.</p>",
          "rawMarkdown": "Hi @hengck23 , I'm not sure but according to my experience in ` UW-Madison GI Tract Image Segmentation`, tune a 3d model is much hard than 2d model. I also put weeks to get a reasonable performance.",
          "votes": 1
        }
      ]
    },
    {
      "id": 1951988,
      "postDate": "2022-09-23T11:30:02.093Z",
      "content": "<p>Update 2: I already trained a segmentation model based on 87 samples that have masks. I randomly picked 80% data for train, and the mean dice score on validation set is around 0.9.</p>\n<p>An inference example of <code>1.2.826.0.1.3680043.5596</code> is attached.</p>\n<p>Now, I will try to make use of this model for the final task. I will share the code later (after I build the full pipeline).</p>",
      "rawMarkdown": "Update 2: I already trained a segmentation model based on 87 samples that have masks. I randomly picked 80% data for train, and the mean dice score on validation set is around 0.9.\n\nAn inference example of `1.2.826.0.1.3680043.5596` is attached.\n\nNow, I will try to make use of this model for the final task. I will share the code later (after I build the full pipeline).\n\n",
      "votes": 1
    },
    {
      "id": 1947136,
      "postDate": "2022-09-20T09:32:40.483Z",
      "content": "<p>Update 1:</p>\n<p>I built a notebook which shows how to use MONAI transforms to load dicom images as well as masks.</p>\n<p>From the data section, we know that:</p>\n<blockquote>\n  <p>the NIFTI files consist of segmentation in the sagittal plane, while the DICOM files are in the axial plane</p>\n</blockquote>\n<p>With the help of the <code>ResampleToMatchd</code> transform, the masks will be adjusted to match up with the images, thus we do not need to worry about the orientations.</p>\n<p>The link of the notebook is in:<br>\n<a href=\"https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai\" target=\"_blank\">https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai</a><br>\nI refer to <a href=\"https://www.kaggle.com/itsuki9180\" target=\"_blank\">@itsuki9180</a> 's <a href=\"https://www.kaggle.com/code/itsuki9180/a-segmentation-is-in-reverse-order\" target=\"_blank\">notebook</a> (Thanks itsuki! ) , and create the animation to show that on my method, images and masks are consistent.</p>",
      "rawMarkdown": "Update 1:\n\nI built a notebook which shows how to use MONAI transforms to load dicom images as well as masks.\n\nFrom the data section, we know that:\n> the NIFTI files consist of segmentation in the sagittal plane, while the DICOM files are in the axial plane\n\nWith the help of the `ResampleToMatchd` transform, the masks will be adjusted to match up with the images, thus we do not need to worry about the orientations.\n\nThe link of the notebook is in:\nhttps://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai\nI refer to @itsuki9180 's [notebook](https://www.kaggle.com/code/itsuki9180/a-segmentation-is-in-reverse-order) (Thanks itsuki! ) , and create the animation to show that on my method, images and masks are consistent.",
      "votes": 1,
      "replies": [
        {
          "id": 1950007,
          "postDate": "2022-09-22T04:24:13.360Z",
          "content": "<p>Thanks for sharing! Is there a way to transfer DICOM to nii.gz? Then maybe we can use some of your previous public notebook (training/inference).</p>",
          "rawMarkdown": "Thanks for sharing! Is there a way to transfer DICOM to nii.gz? Then maybe we can use some of your previous public notebook (training/inference).",
          "votes": 1
        },
        {
          "id": 1951817,
          "postDate": "2022-09-23T09:04:56.730Z",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/leonshangguan\" target=\"_blank\">@leonshangguan</a> , yes, I will share the script soon.</p>",
          "rawMarkdown": "Hi @leonshangguan , yes, I will share the script soon."
        }
      ]
    },
    {
      "id": 1947143,
      "postDate": "2022-09-20T09:43:59.110Z",
      "content": "<p>be careful that some of the dicom images are of different orientation.<br>\ni find a couple of  orientations:</p>\n<pre><code>    [-1, 0, 0, 0],\n    [ 0,-1, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n\n\nand\n\n\n    [0, -1, 0, 0],\n    [ -1, 0, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n</code></pre>",
      "rawMarkdown": "be careful that some of the dicom images are of different orientation.\ni find a couple of  orientations:\n\n```\n    [-1, 0, 0, 0],\n    [ 0,-1, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n\n\nand\n\n\n    [0, -1, 0, 0],\n    [ -1, 0, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n\n\n```",
      "votes": 2,
      "replies": [
        {
          "id": 1947163,
          "postDate": "2022-09-20T10:07:30.080Z",
          "content": "<p>Thanks <a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> , glad to see you in this challenge : ) <br>\nLet me update the notebook, and add the <code>Orientationd</code> transform which is about to unify the orientation for all samples.</p>",
          "rawMarkdown": "Thanks @hengck23 , glad to see you in this challenge : ) \nLet me update the notebook, and add the `Orientationd` transform which is about to unify the orientation for all samples."
        }
      ]
    },
    {
      "id": 1962252,
      "postDate": "2022-09-29T15:23:30.070Z",
      "content": "<p>I had written  a converter which reads a dicomdirectory and converts it into NifTi formats, all orientations are taken care natively.</p>\n<pre><code># ! pip install nekton\n\nfrom nekton.dcm2nii import Dcm2Nii\nconverter = Dcm2Nii()\nconverted_files = converter.run(dicom_directory='/test_files/CT5N',  out_directory='/test_files/CT5N', name='Test')\n# Converted 5 DCM to Nifti; Output stored @ /test_files/CT5N\nprint(converted_files)\n# ['/test_files/CT5N/Test_SmartScore_-_Gated_0.5_sec_20010101000000_5.nii.gz']\n</code></pre>\n<p>More details are here <a href=\"https://github.com/deepc-health/nekton\" target=\"_blank\">https://github.com/deepc-health/nekton</a></p>\n<p>Also if you dont want to convert to Numpy array without converting to NifTi you can use the Monai <code>PydicomReader</code> too it takes care of the orientation too.</p>\n<p>an example snippet</p>\n<pre><code>from  monai.data.image_reader import PydicomReader\nreader = PydicomReader(swap_ij=True)\n\n# # Read a Series as Numpy array\nx = reader.get_data(path_to_series)[0]\n</code></pre>",
      "rawMarkdown": "I had written  a converter which reads a dicomdirectory and converts it into NifTi formats, all orientations are taken care natively.\n\n```python\n# ! pip install nekton\n\nfrom nekton.dcm2nii import Dcm2Nii\nconverter = Dcm2Nii()\nconverted_files = converter.run(dicom_directory='/test_files/CT5N',  out_directory='/test_files/CT5N', name='Test')\n# Converted 5 DCM to Nifti; Output stored @ /test_files/CT5N\nprint(converted_files)\n# ['/test_files/CT5N/Test_SmartScore_-_Gated_0.5_sec_20010101000000_5.nii.gz']\n```\nMore details are here [https://github.com/deepc-health/nekton](https://github.com/deepc-health/nekton)\n\nAlso if you dont want to convert to Numpy array without converting to NifTi you can use the Monai `PydicomReader` too it takes care of the orientation too.\n\nan example snippet\n```python\nfrom  monai.data.image_reader import PydicomReader\nreader = PydicomReader(swap_ij=True)\n\n# # Read a Series as Numpy array\nx = reader.get_data(path_to_series)[0]\n\n```"
    }
  ],
  "comments": [
    {
      "id": 1949775,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2022-09-21T22:00:01.943000",
      "content": "<p>i spend several weeks on 3d solution. But 3d is (much worse?) worse than 2d, which i cannot understand why.<br>\nthis is the same case for the previous UW-Madison GI Tract Image Segmentation. </p>",
      "votes": 3,
      "replies": [
        {
          "id": 1951951,
          "author_name": "Yiheng Wang",
          "author_url": "",
          "post_date": "2022-09-23T11:08:37.707000",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> , I'm not sure but according to my experience in <code>UW-Madison GI Tract Image Segmentation</code>, tune a 3d model is much hard than 2d model. I also put weeks to get a reasonable performance.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1951988,
      "author_name": "Yiheng Wang",
      "author_url": "",
      "post_date": "2022-09-23T11:30:02.093000",
      "content": "<p>Update 2: I already trained a segmentation model based on 87 samples that have masks. I randomly picked 80% data for train, and the mean dice score on validation set is around 0.9.</p>\n<p>An inference example of <code>1.2.826.0.1.3680043.5596</code> is attached.</p>\n<p>Now, I will try to make use of this model for the final task. I will share the code later (after I build the full pipeline).</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1947136,
      "author_name": "Yiheng Wang",
      "author_url": "",
      "post_date": "2022-09-20T09:32:40.483000",
      "content": "<p>Update 1:</p>\n<p>I built a notebook which shows how to use MONAI transforms to load dicom images as well as masks.</p>\n<p>From the data section, we know that:</p>\n<blockquote>\n  <p>the NIFTI files consist of segmentation in the sagittal plane, while the DICOM files are in the axial plane</p>\n</blockquote>\n<p>With the help of the <code>ResampleToMatchd</code> transform, the masks will be adjusted to match up with the images, thus we do not need to worry about the orientations.</p>\n<p>The link of the notebook is in:<br>\n<a href=\"https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai\" target=\"_blank\">https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai</a><br>\nI refer to <a href=\"https://www.kaggle.com/itsuki9180\" target=\"_blank\">@itsuki9180</a> 's <a href=\"https://www.kaggle.com/code/itsuki9180/a-segmentation-is-in-reverse-order\" target=\"_blank\">notebook</a> (Thanks itsuki! ) , and create the animation to show that on my method, images and masks are consistent.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1950007,
          "author_name": "Zhongkai Shangguan",
          "author_url": "",
          "post_date": "2022-09-22T04:24:13.360000",
          "content": "<p>Thanks for sharing! Is there a way to transfer DICOM to nii.gz? Then maybe we can use some of your previous public notebook (training/inference).</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1951817,
          "author_name": "Yiheng Wang",
          "author_url": "",
          "post_date": "2022-09-23T09:04:56.730000",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/leonshangguan\" target=\"_blank\">@leonshangguan</a> , yes, I will share the script soon.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1947143,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2022-09-20T09:43:59.110000",
      "content": "<p>be careful that some of the dicom images are of different orientation.<br>\ni find a couple of  orientations:</p>\n<pre><code>    [-1, 0, 0, 0],\n    [ 0,-1, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n\n\nand\n\n\n    [0, -1, 0, 0],\n    [ -1, 0, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n</code></pre>",
      "votes": 2,
      "replies": [
        {
          "id": 1947163,
          "author_name": "Yiheng Wang",
          "author_url": "",
          "post_date": "2022-09-20T10:07:30.080000",
          "content": "<p>Thanks <a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> , glad to see you in this challenge : ) <br>\nLet me update the notebook, and add the <code>Orientationd</code> transform which is about to unify the orientation for all samples.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1962252,
      "author_name": "abhijeetparida",
      "author_url": "",
      "post_date": "2022-09-29T15:23:30.070000",
      "content": "<p>I had written  a converter which reads a dicomdirectory and converts it into NifTi formats, all orientations are taken care natively.</p>\n<pre><code># ! pip install nekton\n\nfrom nekton.dcm2nii import Dcm2Nii\nconverter = Dcm2Nii()\nconverted_files = converter.run(dicom_directory='/test_files/CT5N',  out_directory='/test_files/CT5N', name='Test')\n# Converted 5 DCM to Nifti; Output stored @ /test_files/CT5N\nprint(converted_files)\n# ['/test_files/CT5N/Test_SmartScore_-_Gated_0.5_sec_20010101000000_5.nii.gz']\n</code></pre>\n<p>More details are here <a href=\"https://github.com/deepc-health/nekton\" target=\"_blank\">https://github.com/deepc-health/nekton</a></p>\n<p>Also if you dont want to convert to Numpy array without converting to NifTi you can use the Monai <code>PydicomReader</code> too it takes care of the orientation too.</p>\n<p>an example snippet</p>\n<pre><code>from  monai.data.image_reader import PydicomReader\nreader = PydicomReader(swap_ij=True)\n\n# # Read a Series as Numpy array\nx = reader.get_data(path_to_series)[0]\n</code></pre>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1947134": "I'm starting to take part in this competition, and my main purpose is to build a 3d solution with MONAI.\n\nprogress:\n- built a notebook to introduce how to load 3d dicom images and masks (see [here](https://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai))\n- create a dataset that contains all gif files to visualize the images and masks (see [here](https://www.kaggle.com/datasets/yiheng/rsna-2022-mask-visualize))\n- built a notebook to show how to save nii format images (see [here](https://www.kaggle.com/yiheng/prepare-nii-format-data-with-monai))",
    "1949775": "i spend several weeks on 3d solution. But 3d is (much worse?) worse than 2d, which i cannot understand why.\nthis is the same case for the previous UW-Madison GI Tract Image Segmentation. ",
    "1951988": "Update 2: I already trained a segmentation model based on 87 samples that have masks. I randomly picked 80% data for train, and the mean dice score on validation set is around 0.9.\n\nAn inference example of `1.2.826.0.1.3680043.5596` is attached.\n\nNow, I will try to make use of this model for the final task. I will share the code later (after I build the full pipeline).\n\n",
    "1947136": "Update 1:\n\nI built a notebook which shows how to use MONAI transforms to load dicom images as well as masks.\n\nFrom the data section, we know that:\n> the NIFTI files consist of segmentation in the sagittal plane, while the DICOM files are in the axial plane\n\nWith the help of the `ResampleToMatchd` transform, the masks will be adjusted to match up with the images, thus we do not need to worry about the orientations.\n\nThe link of the notebook is in:\nhttps://www.kaggle.com/code/yiheng/loading-3d-image-and-mask-with-monai\nI refer to @itsuki9180 's [notebook](https://www.kaggle.com/code/itsuki9180/a-segmentation-is-in-reverse-order) (Thanks itsuki! ) , and create the animation to show that on my method, images and masks are consistent.",
    "1947143": "be careful that some of the dicom images are of different orientation.\ni find a couple of  orientations:\n\n```\n    [-1, 0, 0, 0],\n    [ 0,-1, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n\n\nand\n\n\n    [0, -1, 0, 0],\n    [ -1, 0, 0, 0],\n    [ 0, 0, 1, 0],\n    [ 0, 0, 0, 1],\n\n\n```",
    "1962252": "I had written  a converter which reads a dicomdirectory and converts it into NifTi formats, all orientations are taken care natively.\n\n```python\n# ! pip install nekton\n\nfrom nekton.dcm2nii import Dcm2Nii\nconverter = Dcm2Nii()\nconverted_files = converter.run(dicom_directory='/test_files/CT5N',  out_directory='/test_files/CT5N', name='Test')\n# Converted 5 DCM to Nifti; Output stored @ /test_files/CT5N\nprint(converted_files)\n# ['/test_files/CT5N/Test_SmartScore_-_Gated_0.5_sec_20010101000000_5.nii.gz']\n```\nMore details are here [https://github.com/deepc-health/nekton](https://github.com/deepc-health/nekton)\n\nAlso if you dont want to convert to Numpy array without converting to NifTi you can use the Monai `PydicomReader` too it takes care of the orientation too.\n\nan example snippet\n```python\nfrom  monai.data.image_reader import PydicomReader\nreader = PydicomReader(swap_ij=True)\n\n# # Read a Series as Numpy array\nx = reader.get_data(path_to_series)[0]\n\n```"
  }
}