cellpose icon indicating copy to clipboard operation
cellpose copied to clipboard

Fix bug with single object masks

Open erjel opened this issue 3 years ago • 3 comments

During one of my GPU model trainings I ran into a problem in cellpose/dynamics.py. The line: https://github.com/MouseLand/cellpose/blob/e6d7d2e73fe27754288de1fb30ea71bf295930e9/cellpose/dynamics.py#L88 fails if a label image contains only a single object since squeeze operates on all singular array dimensions. Here it should operate only on the first dimension:

    mu_torch = np.stack((dy.cpu().squeeze(0), dx.cpu().squeeze(0)), axis=-2)

To verify the bug (and test the fix), I adapted the tox test test runs such that it now can run locally on a GPU via:

tox -e gpu

This only requires an installed NVIDIA GPU and the its drivers. CUDA and pytorch are installed via tox-conda. This btw closes #395 as well.

I also noticed that large fractions of the library installations are not used during the pytest runs and therefore deleted them from the github actions. The GPU test is skipped during the github action runs and the cpu-only version of pytorch is used.

erjel avatar Jun 21 '22 17:06 erjel

Codecov Report

Merging #528 (6a20683) into main (4e82051) will decrease coverage by 0.65%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
- Coverage   37.25%   36.60%   -0.66%     
==========================================
  Files          17       17              
  Lines        5454     5450       -4     
==========================================
- Hits         2032     1995      -37     
- Misses       3422     3455      +33     
Impacted Files Coverage Δ
cellpose/dynamics.py 55.96% <0.00%> (-2.56%) :arrow_down:
cellpose/utils.py 32.87% <0.00%> (-7.96%) :arrow_down:
cellpose/io.py 63.35% <0.00%> (-0.86%) :arrow_down:
cellpose/models.py 85.50% <0.00%> (-0.58%) :arrow_down:
cellpose/transforms.py 70.85% <0.00%> (+0.74%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Jun 21 '22 17:06 codecov-commenter

thanks @erjel ! it looks like your newly added test was skipped, is that because cuda isn't available in github actions / installed correctly?

carsen-stringer avatar Jul 03 '22 20:07 carsen-stringer

Yes, it is skipped since pytorch couldn't find CUDA on the GitHub action machine.

erjel avatar Jul 03 '22 20:07 erjel