Skip to content

Commit 2d671a0

Browse files
C-AchardStRigaud
andauthored
Fix Swin for latest MONAI (#113)
* Fix napari-hub shield in README * Update News and Citation with eLife data * Update README.md * Update README.md * Update model_SwinUNetR.py Remove deprecated img_size argument for latest MONAI * Revert "Update model_SwinUNetR.py" This reverts commit 504ee6d. * Test with new env and latest MONAI * Add monai optional reader for tiff to dependencies * Prospective test fixes * Update test_and_deploy.yml * Update model_SwinUNetR.py * Update test_and_deploy.yml * Move tifffile deps to MONAI install only * Fix Swin args + try to get tifffile installed in CI * update pyclesperanto dependency (#117) * Update README.md (#114) Fix napari-hub shield in README Update News and Citation with eLife data Update README.md * remove prototype --------- Co-authored-by: Cyril Achard <94955160+C-Achard@users.noreply.github.com> * Fix Swin feature size --------- Co-authored-by: Stephane Rigaud <Stephane.rigaud@pasteur.fr>
1 parent f19bb36 commit 2d671a0

File tree

11 files changed

+237
-232
lines changed

11 files changed

+237
-232
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
run: |
5252
python -m pip install --upgrade pip
5353
python -m pip install setuptools tox tox-gh-actions
54+
python -m pip install tifffile
55+
python -m pip install monai[nibabel,einops,tifffile]
5456
# pip install git+https://github.com/lucasb-eyer/pydensecrf.git@master#egg=pydensecrf
5557

5658
# this runs the platform-specific tests declared in tox.ini

conda/napari_CellSeg3D_ARM64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
- monai[nibabel, einops]>=0.9.0
1919
- tqdm
2020
- scikit-image
21-
- pyclesperanto-prototype
21+
- pyclesperanto
2222
- tqdm
2323
- matplotlib
2424
- napari_cellseg3d

docs/welcome.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ This plugin additionally uses the following libraries and software:
168168
.. _PyTorch: https://pytorch.org/
169169
.. _MONAI project: https://monai.io/
170170
.. _on their website: https://docs.monai.io/en/stable/networks.html#nets
171-
.. _pyclEsperanto: https://github.com/clEsperanto/pyclesperanto_prototype
171+
.. _pyclEsperanto: https://github.com/clEsperanto/pyclesperanto
172172
.. _WNet: https://arxiv.org/abs/1711.08506
173173

174174
.. rubric:: References

napari_cellseg3d/code_models/instance_segmentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import List
77

88
import numpy as np
9-
import pyclesperanto_prototype as cle
9+
import pyclesperanto as cle
1010
from qtpy.QtWidgets import QWidget
1111
from skimage.measure import label, regionprops
1212
from skimage.morphology import remove_small_objects
@@ -287,7 +287,7 @@ def voronoi_otsu(
287287
BASED ON CODE FROM : napari_pyclesperanto_assistant by Robert Haase
288288
https://github.com/clEsperanto/napari_pyclesperanto_assistant
289289
Original code at :
290-
https://github.com/clEsperanto/pyclesperanto_prototype/blob/master/pyclesperanto_prototype/_tier9/_voronoi_otsu_labeling.py.
290+
https://github.com/clEsperanto/pyclesperanto/blob/d1990e28b1da44a7921890b7bd809d522d3198b8/pyclesperanto/_tier7.py#L409-L448.
291291
292292
Args:
293293
volume (np.ndarray): volume to segment

napari_cellseg3d/code_models/models/model_SwinUNetR.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""SwinUNetR wrapper for napari_cellseg3d."""
22

3+
import inspect
4+
35
from monai.networks.nets import SwinUNETR
46

57
from napari_cellseg3d.utils import LOGGER
@@ -30,30 +32,30 @@ def __init__(
3032
use_checkpoint (bool): whether to use checkpointing during training.
3133
**kwargs: additional arguments to SwinUNETR.
3234
"""
35+
parent_init = super().__init__
36+
sig = inspect.signature(parent_init)
37+
init_kwargs = dict(
38+
in_channels=in_channels,
39+
out_channels=out_channels,
40+
use_checkpoint=use_checkpoint,
41+
feature_size=48,
42+
drop_rate=0.5,
43+
attn_drop_rate=0.5,
44+
use_v2=True,
45+
**kwargs,
46+
)
47+
if "img_size" in sig.parameters:
48+
# since MONAI API changes depending on py3.8 or py3.9
49+
init_kwargs["img_size"] = input_img_size
50+
if "dropout_prob" in kwargs:
51+
init_kwargs["drop_rate"] = kwargs["dropout_prob"]
52+
init_kwargs.pop("dropout_prob")
3353
try:
34-
super().__init__(
35-
input_img_size,
36-
in_channels=in_channels,
37-
out_channels=out_channels,
38-
feature_size=48,
39-
use_checkpoint=use_checkpoint,
40-
drop_rate=0.5,
41-
attn_drop_rate=0.5,
42-
use_v2=True,
43-
**kwargs,
44-
)
54+
parent_init(**init_kwargs)
4555
except TypeError as e:
4656
logger.warning(f"Caught TypeError: {e}")
47-
super().__init__(
48-
input_img_size,
49-
in_channels=1,
50-
out_channels=1,
51-
feature_size=48,
52-
use_checkpoint=use_checkpoint,
53-
drop_rate=0.5,
54-
attn_drop_rate=0.5,
55-
use_v2=True,
56-
)
57+
init_kwargs["in_channels"] = 1
58+
parent_init(**init_kwargs)
5759

5860
# def forward(self, x_in):
5961
# y = super().forward(x_in)

napari_cellseg3d/dev_scripts/sliding_window_voronoi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test script for sliding window Voronoi-Otsu segmentation.""."""
22
import numpy as np
3-
import pyclesperanto_prototype as cle
3+
import pyclesperanto as cle
44
from tqdm import tqdm
55

66

0 commit comments

Comments
 (0)