Skip to content
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

Scale flows to correct shape #775

Merged
merged 4 commits into from
Nov 8, 2023

Conversation

mrariden
Copy link
Collaborator

@mrariden mrariden commented Sep 1, 2023

Per #774, when resize is not None, masks get resized but the flows don't in dynamics.compute_masks(). This isn't immediately an issue, except that if no putative cellpix are found (here), zero-filled arrays of the original size are returned.

The result is that, depending on if putative cellpix are found, iterating through the images (here) produces a list of inconsistent np array shapes. Finally, trying to convert the list-of-arrays into a stack of arrays fails at line 663.

This fix reshapes the flows to the correct shape.

Should we think about tests that address this?

@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Merging #775 (00d0ed1) into main (95f8d98) will increase coverage by 0.02%.
Report is 33 commits behind head on main.
The diff coverage is 78.94%.

@@            Coverage Diff             @@
##             main     #775      +/-   ##
==========================================
+ Coverage   63.39%   63.41%   +0.02%     
==========================================
  Files          14       14              
  Lines        2964     2966       +2     
==========================================
+ Hits         1879     1881       +2     
  Misses       1085     1085              
Files Coverage Δ
cellpose/models.py 86.12% <100.00%> (ø)
cellpose/dynamics.py 56.79% <76.47%> (+0.23%) ⬆️

@carsen-stringer
Copy link
Member

technically the correct thing to do is to leave them in the unresized form, so let's return a resized array if cellpix is none

@mrariden
Copy link
Collaborator Author

I think I see, my solution works but it shouldn't because compute_masks should respect the resize or rescale arguments? (I am still unsure what the convention is for rescale, vs resize, reshape, resample.)

Here's the data in case I didn't describe it well enough before. This is the state 5 loops through the iterator on line 655 in _run_cp()

The input dP being processed has a shape of (2, 59, 77, 77) after tiling:

>>>[dPi.shape for dPi in dP[0][0:5]]
[(77, 77), (77, 77), (77, 77), (77, 77), (77, 77)]

>>>[dPi.shape for dPi in dP[1][0:5]]
[(77, 77), (77, 77), (77, 77), (77, 77), (77, 77)]

And the output masks are reshaped because of this line:

>>>[m.shape for m in masks]
[(232, 232), (232, 232), (232, 232), (232, 232), (232, 232)]

But the p array is not reshaped and has inconsistent size as a result:

>>>[pi.shape for pi in p]
[(2, 232, 232), (2, 232, 232), (2, 77, 77), (2, 232, 232), (2, 77, 77)]

So, I have two thoughts, (1) should the resize be the opposite here to be resize = [shape[1], shape[2]] if resample else None (remove the not) ? And (2), I think we should remove the resizing from compute_masks() since that seems to be a different function.

@mrariden mrariden closed this Sep 22, 2023
@mrariden mrariden reopened this Oct 19, 2023
@mrariden
Copy link
Collaborator Author

Okay new solution refactors dynamics.compute_masks() to dynamics.reshape_and_compute_masks() which calls dynamics.compute_masks() which has no internal reshaping behavior.

@carsen-stringer carsen-stringer merged commit 8b9896a into MouseLand:main Nov 8, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants