Skip to content

Colab inference demo incompatible with current MONAI and NumPy #119

Description

@msayr

Hi there,

I was trying out the Colab inference notebook ([here])(https://colab.research.google.com/github/MMathisLab/CellSeg3d/blob/main/Notebooks/Colab_inference_demo.ipynb#scrollTo=IFbmZ3_zAm-1) and I've gotten the following error. All original code above this line ran without error:

result = cs3d.inference_on_images(
    demo_image,
    config=inference_config,
)
WARNING:napari_cellseg3d.utils:Caught TypeError: SwinUNETR.__init__() got multiple values for argument 'in_channels'
ERROR:napari_cellseg3d.utils:SwinUNETR.__init__() got multiple values for argument 'in_channels'
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/dist-packages/napari_cellseg3d/code_models/models/model_SwinUNetR.py", line 34, in __init__
    super().__init__(
TypeError: SwinUNETR.__init__() got multiple values for argument 'in_channels'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/dist-packages/napari_cellseg3d/code_models/worker_inference.py", line 859, in inference
    model = model_class(
            ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/napari_cellseg3d/code_models/models/model_SwinUNetR.py", line 47, in __init__
    super().__init__(
TypeError: SwinUNETR.__init__() got multiple values for argument 'in_channels'
--------------------
Parameters summary :
Model is : SwinUNetR
Window inference is enabled
Window size is 64
Window overlap is 0.25
Dataset loaded on cuda device
--------------------
MODEL DIMS : [64, 64, 64]
Model name : SwinUNetR
Instantiating model...

Changing numpy and monai versions solved the issue for me:

!pip install -U "numpy>=2.1,<2.6" "monai==1.3.2"

import numpy, monai
print("NumPy:", numpy.__version__)
print("MONAI:", monai.__version__)

NumPy: 2.4.6
MONAI: 1.3.2

Then updating reshape to shape to match different numpy version:

from pathlib import Path

p = Path("/usr/local/lib/python3.12/dist-packages/napari_cellseg3d/code_models/worker_inference.py")
s = p.read_text()
s = s.replace("np.reshape(volume, newshape=(1, *volume.shape))",
              "np.reshape(volume, (1, *volume.shape))")
p.write_text(s)

print("Patched:", p)

Activity

  1. added theissue type on May 19, 2026
  2. C-Achard commented on May 19, 2026

    @C-Achard
    Collaborator

    Hello @msayr,

    Thanks a lot for reporting; I’m currently updating the package to run properly on Python 3.12 and to fix several deprecated/old calls, including the newshape issue.

    The SwinUNETR.__init__() got multiple values for argument 'in_channels' error looks related to MONAI API/version compatibility, so I’m checking that as part of the update as well. In my limited local testing, the plugin is now running reasonably well with recent napari/MONAI versions, but I remember this being broken by a MONAI update, they might have fixed it in a subsequent release however as I got it to run locally. Will investigate this further.

    Thanks again!

    Best,
    Cyril

  3. C-Achard commented on May 19, 2026

    @C-Achard
    Collaborator

    Closed automatically by #120, re-opening until released/fix is confirmed

  4. C-Achard commented on May 21, 2026

    @C-Achard
    Collaborator

    Hello @msayr,

    Version 0.2.4 is now live, which moves the supported Python versions to 3.10-3.12.

    This fixes all deprecation errors, and I've confirmed that all models run properly locally.
    Please let me know if it still fails on Colab with the latest!

    Thanks again,
    Cyril

  5. msayr commented on May 21, 2026

    @msayr
    Author

    Hi @C-Achard thank you very much for the prompt response! I just tested the notebook and it looks like pyclesperanto is required but now missing:

    # @title Load libraries
    import napari_cellseg3d
    from tifffile import imread
    from pathlib import Path
    from napari_cellseg3d.dev_scripts import remote_inference as cs3d
    from napari_cellseg3d.utils import LOGGER as logger
    
    import logging
    
    logger.setLevel(logging.INFO)
    

    output:

    _/usr/local/lib/python3.12/dist-packages/pyclesperanto/__init__.py:29: RuntimeWarning: No pyclesperanto backend installed.
    Install one with:
      pip install pyclesperanto[opencl]   # for OpenCL
      pip install pyclesperanto[cuda]     # for CUDA
      pip install pyclesperanto[metal]    # for Metal
      pip install pyclesperanto[all]      # for both
      warnings.warn(_
    
    

    ###########

    demo_image_path = "/content/CellSeg3D/examples/c5image.tif"
    demo_image = imread(demo_image_path)
    inference_config = cs3d.CONFIG
    post_process_config = cs3d.PostProcessConfig()
    # select cle device for colab
    import pyclesperanto_prototype as cle
    cle.select_device("cupy")
    

    output:

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    [/tmp/ipykernel_5093/3519197974.py](https://localhost:8080/#) in <cell line: 0>()
          4 post_process_config = cs3d.PostProcessConfig()
          5 # select cle device for colab
    ----> 6 import pyclesperanto_prototype as cle
          7 cle.select_device("cupy")
    
    ModuleNotFoundError: No module named 'pyclesperanto_prototype'
    
    ---------------------------------------------------------------------------
    NOTE: If your import is failing due to a missing package, you can
    manually install dependencies using either !pip or !apt.
    
    To view examples of installing some common dependencies, click the
    "Open Examples" button below.
    ---------------------------------------------------------------------------
    
  6. C-Achard commented on May 21, 2026

    @C-Achard
    Collaborator

    Hi @msayr,

    Yes, apologies, we are no longer using the prototype version, this should work by removing the _prototype suffix.

    There was a small issue with the release that required immediate attention, I will check the Colab notebook more thoroughly soon.

    Best,
    Cyril

  7. C-Achard commented on May 21, 2026

    @C-Achard
    Collaborator

    Okay, the issue was a bit sneakier: the Open in Colab URL was pointing to the MMathisLab fork instead of this repo, so it was not showing the latest version.

    I will PR a new version with uv, check it works fine, and get back to you!

  8. linked a pull request that will close this issueUpdate Colab demo notebook #128on May 21, 2026
  9. C-Achard commented on May 22, 2026

    @C-Achard
    Collaborator

    @msayr Here is the link to the updated notebook:
    https://colab.research.google.com/github/AdaptiveMotorControlLab/CellSeg3D/blob/main/notebooks/Colab_inference_demo.ipynb

    Let me know if there are any issues! Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions