MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.4k stars 403 forks source link

[BUG] Issue when running with post-release version of PyTorch #1054

Open MeyerBender opened 1 week ago

MeyerBender commented 1 week ago

Describe the bug Running cellpose with PyTorch version 2.5.1.post303 leads to the following error:

File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/spatialproteomics/tl/tool.py", line 86, in cellpose
    masks_pred, _, _, _ = model.eval(
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/models.py", line 187, in eval
    diams, _ = self.sz.eval(x, channels=channels, channel_axis=channel_axis,
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/models.py", line 776, in eval
    masks = self.cp.eval(
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/models.py", line 534, in eval
    masks = self._compute_masks(x.shape, dP, cellprob, flow_threshold=flow_threshold,
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/models.py", line 620, in _compute_masks
    outputs = dynamics.resize_and_compute_masks(
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/dynamics.py", line 839, in resize_and_compute_masks
    mask = compute_masks(dP, cellprob, niter=niter,
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/dynamics.py", line 913, in compute_masks
    mask = remove_bad_flow_masks(mask, dP, threshold=flow_threshold,
  File "/g/huber/users/meyerben/notebooks/spatialproteomics_pipelines/celestimo/.snakemake/conda/4057a625210cbf20c14eec4e61ec3417_/lib/python3.9/site-packages/cellpose/dynamics.py", line 623, in remove_bad_flow_masks
    major_version, minor_version, _ = torch.__version__.split(".")
ValueError: too many values to unpack (expected 3)

Should be fairly easy to fix by simple replacing the corresponding line with something like this:

torch_version = torch.__version__.split(".")
major_version, minor_version = torch_version[0], torch_version[1]