Skip to content

Commit 7a4e31f

Browse files
C-Achardjeylau
andauthored
Improved Utilities (#44)
* Utils improvements - Set new results path now remains across utils - Utils generate one layer and update it on subsequent runs - Layer choice tries to be conserved across utils * Cleanup + CRF fixes * Fragmenting utility * Temp fix for CRF (#46) * Update plugin_convert.py * Update test_and_deploy.yml * Update test_inference.py * Fix tests + new weights * Update test_models.py * Fix dir for saving in tests * Docstring update * CRF and utils colormap adjustment * Update plugin_crf.py * Fix typo in crf.py Co-authored-by: Jessy Lauer <[email protected]> * Fix Pathlib typo in plugin_convert.py Co-authored-by: Jessy Lauer <[email protected]> * Fixed filepaths + comments cleanup * Fixed merge comment deletion --------- Co-authored-by: Jessy Lauer <[email protected]>
1 parent 1f71ea7 commit 7a4e31f

File tree

12 files changed

+398
-140
lines changed

12 files changed

+398
-140
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
branches:
99
- main
10+
- cy/utils
1011
tags:
1112
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
1213
pull_request:

napari_cellseg3d/code_models/crf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
Philipp Krähenbühl and Vladlen Koltun
88
NIPS 2011
99
10-
Implemented using the pydense libary available at https://github.com/kodalli/pydensecrf.
10+
Implemented using the pydense library available at https://github.com/kodalli/pydensecrf.
1111
"""
12+
1213
from warnings import warn
1314

1415
try:

napari_cellseg3d/code_models/workers_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(self, file_location):
151151
except ImportError as e:
152152
logger.error("ONNX is not installed but ONNX model was loaded")
153153
logger.error(e)
154-
msg = "PLEASE INSTALL ONNX CPU OR GPU USING pip install napari-cellseg3d[onnx-cpu] OR napari-cellseg3d[onnx-gpu]"
154+
msg = "PLEASE INSTALL ONNX CPU OR GPU USING: pip install napari-cellseg3d[onnx-cpu] OR pip install napari-cellseg3d[onnx-gpu]"
155155
logger.error(msg)
156156
raise ImportError(msg) from e
157157

@@ -177,6 +177,8 @@ def to(self, device):
177177

178178

179179
class QuantileNormalizationd(MapTransform):
180+
"""MONAI-style dict transform to normalize each image in a batch individually by quantile normalization."""
181+
180182
def __init__(self, keys, allow_missing_keys: bool = False):
181183
super().__init__(keys, allow_missing_keys)
182184

@@ -199,6 +201,8 @@ def normalizer(self, image: torch.Tensor):
199201

200202

201203
class QuantileNormalization(Transform):
204+
"""MONAI-style transform to normalize each image in a batch individually by quantile normalization."""
205+
202206
def __call__(self, img):
203207
return utils.quantile_normalization(img)
204208

napari_cellseg3d/code_plugins/plugin_base.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,10 @@ def _update_default_paths(self, path=None):
446446
self.extract_dataset_paths(self.labels_filepaths),
447447
self.results_path,
448448
]
449-
return
449+
return utils.parse_default_path(self._default_path)
450450
if Path(path).is_dir():
451451
self._default_path.append(path)
452+
return utils.parse_default_path(self._default_path)
452453

453454
@staticmethod
454455
def extract_dataset_paths(paths):
@@ -458,3 +459,37 @@ def extract_dataset_paths(paths):
458459
if paths[0] is None:
459460
return None
460461
return str(Path(paths[0]).parent)
462+
463+
464+
class BasePluginUtils(BasePluginFolder):
465+
"""Small subclass used to have centralized widgets layer and result path selection in utilities"""
466+
467+
save_path = None
468+
utils_default_paths = [Path.home() / "cellseg3d"]
469+
470+
def __init__(
471+
self,
472+
viewer: napari.viewer.Viewer,
473+
parent=None,
474+
loads_images=True,
475+
loads_labels=True,
476+
):
477+
super().__init__(
478+
viewer=viewer,
479+
loads_images=loads_images,
480+
loads_labels=loads_labels,
481+
parent=parent,
482+
)
483+
if parent is not None:
484+
self.setParent(parent)
485+
self.parent = parent
486+
487+
self.layer = None
488+
"""Should contain the layer associated with the results of the utility widget"""
489+
490+
def _update_default_paths(self, path=None):
491+
"""Override to also update utilities' pool of default paths"""
492+
default_path = super()._update_default_paths(path)
493+
logger.debug(f"Trying to update default with {default_path}")
494+
if default_path is not None:
495+
self.utils_default_paths.append(default_path)

0 commit comments

Comments
 (0)