From 7e3e1112640990b4ab63b9f9dd340bd39861a808 Mon Sep 17 00:00:00 2001 From: koddenbrock Date: Fri, 3 Oct 2025 22:20:43 +0200 Subject: [PATCH 1/2] Fix prediction check to handle None values in model output --- cellSAM/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cellSAM/model.py b/cellSAM/model.py index 7475b64..8dc3924 100644 --- a/cellSAM/model.py +++ b/cellSAM/model.py @@ -165,7 +165,7 @@ def segment_cellular_image( model, img = model.to(device), img.to(device) preds = model.predict(img, boxes_per_heatmap=bounding_boxes) - if preds is None: + if preds is None or preds[0] is None: warn("No cells detected in the image.") return np.zeros(img.shape[1:], dtype=np.int32), None, None From 341f2dcc0c273e62b71d002bd0ff80fb8014d7ab Mon Sep 17 00:00:00 2001 From: koddenbrock Date: Tue, 7 Oct 2025 10:51:38 +0200 Subject: [PATCH 2/2] Refactor model configuration loading to use importlib.resources --- cellSAM/model.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cellSAM/model.py b/cellSAM/model.py index 8dc3924..58bd2d1 100644 --- a/cellSAM/model.py +++ b/cellSAM/model.py @@ -9,7 +9,8 @@ from pathlib import Path import yaml import pkgutil -from pkg_resources import resource_filename +import importlib.resources as resources + from skimage.morphology import ( @@ -40,7 +41,7 @@ def get_local_model(model_path: str) -> nn.Module: """ Returns a loaded CellSAM model from a local path. """ - config_path = resource_filename(__name__, 'modelconfig.yaml') + config_path = resources.files(__package__) / 'modelconfig.yaml' with open(config_path, 'r') as config_file: config = yaml.safe_load(config_file) @@ -91,7 +92,7 @@ def get_model(model="cellsam_general", version=None) -> nn.Module: model_version_dir = cellsam_assets_dir / f"cellsam_v{version}" model_path = model_version_dir / f"{model}.pt" - config_path = resource_filename(__name__, 'modelconfig.yaml') + config_path = resources.files(__package__) / 'modelconfig.yaml' with open(config_path, 'r') as config_file: config = yaml.safe_load(config_file)