Project-MONAI / tutorials

MONAI Tutorials
https://monai.io/started.html
Apache License 2.0
1.71k stars 659 forks source link

Kernel hangs in "TCIA_PROSTATEx_Prostate_MRI_Anatomy_Model.ipynb" #1694

Open KumoLiu opened 2 months ago

KumoLiu commented 2 months ago

Describe the bug Kernel hangs after itkwidgets visualization in jupyter notebook https://github.com/Project-MONAI/tutorials/blob/main/model_zoo/TCIA_PROSTATEx_Prostate_MRI_Anatomy_Model.ipynb

To Reproduce

  1. docker pull projectmonai/monai:latest
  2. create a new container
  3. run into container
  4. pip install 'itkwidgets[notebook]>=1.0a49'
    from monai.transforms import LoadImage
    root_dir = "/opt/monai/workspace/Data"
    data_dir = os.path.join(root_dir, "Task09_Spleen")
    train_images = sorted(glob.glob(os.path.join(data_dir, "imagesTr", "*.nii.gz")))
    out = LoadImage(ensure_channel_first=True)(train_images[0])
    view(image=out)

Expected behavior Kernal will not hangs after using view.

Screenshots

Screen Shot 2024-04-17 at 15 46 44

Additional context

KumoLiu commented 2 months ago

cc @kirbyju @aylward and @thewtex, in case you can shed any light on this issue, it would be greatly appreciated.

Also created a ticket here https://github.com/InsightSoftwareConsortium/itkwidgets/issues/743 Thanks.

KumoLiu commented 2 months ago

Also tried this notebook with pytorch container: nvcr.io/nvidia/pytorch:24.03-py3. See the same issue. https://github.com/InsightSoftwareConsortium/itkwidgets/blob/v1.0a50/examples/integrations/MONAI/transform_visualization.ipynb

aylward commented 2 months ago

Thank you for the detailed report on the itkwidget repo. Matt and Brianna are looking into it!

thewtex commented 2 months ago

Hello :wave: ,

With itkwidgets 1.0a50, itkwidgets supports JupyterLab 4 and Jupyter Notebook 7. The Jupyter project made these versions major breaking changes. So, there are a few approaches:

a) Update the JupyterLab and Jupyter Notebook version b) Set the itkwidgets dependency to itkwidgets==1.0a49 until a) can be performed.

After install itkwidgets[notebook]>=1.0a49, look like there will be a requirement compatibility issues for pandas, not sure whether it's related the issue.

This seems to be unrelated in the transitive dependency arena, but a patch is here:

https://github.com/InsightSoftwareConsortium/itkwidgets/pull/744

Testing and feedback to see if it addresses your use cause are appreciated. :pray: Thanks!

KumoLiu commented 2 months ago

Hi @thewtex, thanks for the quick response. I update the notebook version but the same issue occurred. Step to reproduce:

docker run -it --ipc=host --rm --net host --gpus all  nvcr.io/nvidia/pytorch:24.03-py3
pip install -U notebook
Then run this notebook: https://github.com/InsightSoftwareConsortium/itkwidgets/blob/v1.0a50/examples/integrations/MONAI/transform_visualization.ipynb

You can see from the screen shot after view even import numpy as not be executed. Also can see the output from view.

Screen Shot 2024-04-17 at 23 54 21

BTW, where can I find the requirement for the notebook, I didn't find it in the requirement. Perhaps I want to try the version which can run in notebook 6. Thanks!

thewtex commented 2 months ago

@KumoLiu thanks for the reproducible example!

Addressed here:

https://github.com/InsightSoftwareConsortium/itkwidgets/pull/745

After it is released, it will be better to install itkwidgets in the containers so all javascript is loaded at startup.

thewtex commented 2 months ago

BTW, where can I find the requirement for the notebook, I didn't find it in the requirement. Perhaps I want to try the version which can run in notebook 6.

The dependencies are here:

https://github.com/InsightSoftwareConsortium/itkwidgets/blob/5d83f28c4c076e6227ff4434484e105d57614aa8/pyproject.toml#L37-L92

We keep them as small and light and universal as possible.

thewtex commented 2 months ago

Hi @KumoLiu , these improvements have now been released in itkwidgets 1.0a51.

Please try:

docker run -it --ipc=host --rm --net host --gpus all  nvcr.io/nvidia/pytorch:24.03-py3
pip install -U notebook
pip install 'itkwidgets[notebook]==1.0a51'
# Start the notebook
KumoLiu commented 2 months ago

Hi @thewtex, thanks for the quick fix. I tried with 1.0a51, and the same issue occurred. In addition, after this command pip install 'itkwidgets[notebook]==1.0a51' and jupyter notebook can not even launched correctly.

Screen Shot 2024-04-18 at 11 29 37
thewtex commented 2 months ago

@KumoLiu thanks for testing.

I also observed that error in my testing when I tried installing widgetsnbextension (a different, unrelated package), made for notebook==6 when notebook==7 was installed.

I am wondering if there is something else in your installation?

Could you please try:

docker run -it -p 8888:8888 --ipc=host --rm --net host --gpus all thewtex/monai-1694

or simply build and run the following Dockerfile:

FROM nvcr.io/nvidia/pytorch:24.03-py3

RUN pip install -U notebook
RUN pip install 'itkwidgets[notebook]==1.0a51'
RUN curl -L -o /transform_visualization.ipynb https://raw.github.com/InsightSoftwareConsortium/itkwidgets/main/examples/integrations/MONAI/transform_visualization.ipynb
CMD jupyter notebook /transform_visualization.ipynb

?

You should see:

image

(there is an issue with the last cell, but I have a fix in progress for that).

thewtex commented 2 months ago

(there is an issue with the last cell, but I have a fix in progress for that).

This was a side-effect of fixing the pandas dependency issue, but it has been addressed in itkwidgets 1.0a52.