MannLabs / SPARCSpy

9 stars 6 forks source link

Update workflows.py #23

Closed lucasmiranda42 closed 1 year ago

lucasmiranda42 commented 1 year ago

Fixed potential bug introduced by Cellpose returning different sets of values when loading custom models through cellpose.models.CellposeModel().

masks, _, _, _ = model.eval([input_image], diameter=None, channels=[2, 1]) and similar lines of code fail when using a custom model. The error seems to come from the _read_cellpose_model() method in the same file. When a pretrained model is used, model.eval() returns 4 elements indeed (masks, flows, styles, diams). When a custom model is loaded using models.CellposeModel(), however, diameters are not returned (not sure why, tho, but their API docs may yield some insights).

The introduced fix aims to take the first element of the returned tuple, which corresponds to the masks regardless of the class used to generate it. In my local tests this fixed the issue, but I can't guarantee this doesn't have any side effects, of course.

Best, and hope it helps! Lucas