-
Notifications
You must be signed in to change notification settings - Fork 32
Fix prediction check to handle None values in model output #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Running into the same issue, which would be fixed by this pull request. |
|
Is there any hope on this simple but really necessary merge? It's such an obvious bug and fix which would help me make |
|
You could use my forked branch via:
|
|
Hi @rossbar, Any chance you could review this and take care of it? It seems that the checking criterion ( Could you please merge the PR here? :) (seems like a critical bug to me when the model does not find any objects) |
|
Yes this is obviously a bug - I have some trepidation about changing it without testing to ensure that it doesn't negatively affect the tiled workflow with Can you share a minimal reproducing example of how you hit this code branch so we can use it to design this test? |
|
Hi @rossbar, Thanks for your response. And first of all, congratulations on the publication! ;) And I totally understand your anxiousness! (especially at the time of year we are rn haha) Two points from my side:
[nim00007] nimanwai@glogin10 cellSAM $ git remote -v
origin https://github.com/vanvalenlab/cellSAM (fetch)
origin https://github.com/vanvalenlab/cellSAM (push)
[nim00007] nimanwai@glogin10 cellSAM $ git diff
diff --git a/cellSAM/model.py b/cellSAM/model.py
index b124581..5633335 100644
--- a/cellSAM/model.py
+++ b/cellSAM/model.py
@@ -163,7 +163,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 all(p is None for p in preds):
warn("No cells detected in the image.")
return np.zeros(img.shape[1:], dtype=np.int32), None, NoneThe check is super simple - you always return tuples in
import imageio.v3 as imageio
from cellSAM import cellsam_pipeline
image = imageio.imread("test.tif")
segmentation = cellsam_pipeline(image, use_wsi=False)PS. I came across another issues just now: an array with all ones or all zeros breaks down too (ik ik it's not the way-to-go, but helps debug stuff if these two cases don't break, but rather return no segmentations) e.g. import numpy as np
from cellSAM import cellsam_pipeline
image = np.zeros((512, 512))
segmentation = cellsam_pipeline(image, use_wsi=False)Let me know how it goes! :) |
the check
preds is Nonewas not working, sincepredwas a tuple(None, None, None, None)