Coder Social home page Coder Social logo

Comments (13)

fepegar avatar fepegar commented on July 19, 2024 1

For reference, here's a Colab notebook in which I manage to run the segmentation (using TorchIO): https://colab.research.google.com/drive/1XprcAZ59dAYBGFjawgb7h9mx0Y9N6pTj?usp=sharing

I assumed a spacing of 1 x 1 x 9 mm and LPS orientation.

Results look like this:
download (2)
download (3)

from brain-segmentation-pytorch.

mateuszbuda avatar mateuszbuda commented on July 19, 2024

Hi @fepegar, thanks for trying the model.
The notebook on PyTorch Hub runs inference on one slice.
This can be done, but the model was trained on images normalized per MRI volume.

from brain-segmentation-pytorch.

fepegar avatar fepegar commented on July 19, 2024

Thanks. I think that it's detrimental for you and for PyTorch that the provided example is not representative of the original model's performance. Could you update the example with a more appropriate image or with the preprocessing needed for this specific slice? If not? Could you please do that here?

from brain-segmentation-pytorch.

mateuszbuda avatar mateuszbuda commented on July 19, 2024

The problem is that it would require loading the entire 4D MRI volume in the code sample which is run as a test every time there is a PR to pytorch/hub repository.
Another option is that I hardcode the mean and standard deviation computed on a volume for the example slice.
However, I wanted to show that you have to normalize the input.
The fact that you have to normalize the input per volume is described at the beginning of the Example section: https://github.com/pytorch/hub/blob/master/mateuszbuda_brain-segmentation-pytorch_unet.md#example
There is also a link to the dataset that contains complete volumes.
Anyway, I will compute the mean and std that give expected predictions.

from brain-segmentation-pytorch.

fepegar avatar fepegar commented on July 19, 2024

The problem is that it would require loading the entire 4D MRI volume in the code sample which is run as a test every time there is a PR to pytorch/hub repository.

In my first suggestion (which I just edited, because there was a word missing), I meant that you could replace the current link with one to an already preprocessed slice of that 4D image.

Another option is that I hardcode the mean and standard deviation computed on a volume for the example slice.

This is what I meant by "the preprocessing needed for this specific slice".

The fact that you have to normalize the input per volume is described at the beginning of the Example section: https://github.com/pytorch/hub/blob/master/mateuszbuda_brain-segmentation-pytorch_unet.md#example
There is also a link to the dataset that contains complete volumes.

Sure, but I think that it would help you and the users if the example was self-contained, especially if you're explicitly using a sample image for it.

Let me know if I can help.

from brain-segmentation-pytorch.

fepegar avatar fepegar commented on July 19, 2024

By the way, the image I used, assuming 32 bits per voxel, takes 18 MB in memory. The frequency of PRs on pytorch/hub doesn't seem very high, so I think it would be fine to upload the actual 4D image, ideally in a format that supports 4D images such as NIfTI or NRRD. You could use TorchIO to convert the images to any of those formats.

from brain-segmentation-pytorch.

kruthikakr avatar kruthikakr commented on July 19, 2024

The problem is that it would require loading the entire 4D MRI volume in the code sample which is run as a test every time there is a PR to pytorch/hub repository.
Another option is that I hardcode the mean and standard deviation computed on a volume for the example slice.
However, I wanted to show that you have to normalize the input.
The fact that you have to normalize the input per volume is described at the beginning of the Example section: https://github.com/pytorch/hub/blob/master/mateuszbuda_brain-segmentation-pytorch_unet.md#example
There is also a link to the dataset that contains complete volumes.
Anyway, I will compute the mean and std that give expected predictions.

If i need to upload a 4D data test image and get the segmentation on that ? How to do it ?

from brain-segmentation-pytorch.

kruthikakr avatar kruthikakr commented on July 19, 2024

Hi, and thanks for sharing your work! I have run the notebook you shared on PyTorch Hub and added one cell:

import scipy.ndimage as ndi
import matplotlib.pyplot as plt

pred = output[0, 0].cpu().numpy()
pred_bin = pred > 0.5
pred -= pred.min()
pred /= pred.max()
pred *= 255;
borders = ndi.binary_dilation(pred_bin) ^ pred_bin
input_array = np.array(input_image).copy()
input_array[borders] = input_array.max()

fig, axes = plt.subplots(1, 3, figsize=(12, 8))
axes[0].imshow(input_image)
axes[1].imshow(pred)
axes[2].imshow(input_array)

The segmentation is very inaccurate. Am I doing something wrong?

download

@fepegar I tried this on few samples, it works great . But can the output be displayed as something like this using torchio ? can you please give inputs for this ?

TCGA_CS_4944_20010208-09 ie overlapping the segmented part with the Brain MRI image

from brain-segmentation-pytorch.

fepegar avatar fepegar commented on July 19, 2024

Yes, you could potentially use TorchIO for that visualization. But it would probably be easier (or more powerful) to use SimpleITK and then matplotlib.

from brain-segmentation-pytorch.

AK391 avatar AK391 commented on July 19, 2024

Hi, and thanks for sharing your work! I have run the notebook you shared on PyTorch Hub and added one cell:

import scipy.ndimage as ndi
import matplotlib.pyplot as plt

pred = output[0, 0].cpu().numpy()
pred_bin = pred > 0.5
pred -= pred.min()
pred /= pred.max()
pred *= 255;
borders = ndi.binary_dilation(pred_bin) ^ pred_bin
input_array = np.array(input_image).copy()
input_array[borders] = input_array.max()

fig, axes = plt.subplots(1, 3, figsize=(12, 8))
axes[0].imshow(input_image)
axes[1].imshow(pred)
axes[2].imshow(input_array)

The segmentation is very inaccurate. Am I doing something wrong?
download

@fepegar I tried this on few samples, it works great . But can the output be displayed as something like this using torchio ? can you please give inputs for this ?

TCGA_CS_4944_20010208-09 ie overlapping the segmented part with the Brain MRI image

could you please share a colab notebook for this result @kruthikakr @fepegar

from brain-segmentation-pytorch.

kruthikakr avatar kruthikakr commented on July 19, 2024

There is no co lab notebook done for this . As said i just used the ITK only

from brain-segmentation-pytorch.

AK391 avatar AK391 commented on July 19, 2024

@kruthikakr can you share your notebook to get the above result?

from brain-segmentation-pytorch.

chamecall avatar chamecall commented on July 19, 2024

I've made the appropriate normalization.
Check the colab.

TCGA_CS_4944_20010208.zip

from brain-segmentation-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.