Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tools/cellpose/cellpose.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<description>with Cellpose</description>
<macros>
<token name="@TOOL_VERSION@">3.1.0</token>
<token name="@VERSION_SUFFIX@">0</token>
<token name="@VERSION_SUFFIX@">1</token>
<xml name="channel">
<option value="0" selected="true">grayscale/None</option>
<option value="1">red</option>
Expand All @@ -19,6 +19,7 @@
<version_command>echo "@VERSION@"</version_command>
<command detect_errors="exit_code">
<![CDATA[
export MKL_NUM_THREADS=1 &&
export CELLPOSE_LOCAL_MODELS_PATH='cellpose_models' &&
mkdir -p segmentation &&
ln -s '${img_in}' ./image.${img_in.ext} &&
Expand All @@ -34,7 +35,7 @@
<inputs name="inputs" />
</configfiles>
<inputs>
<param name="img_in" type="data" format="ome.tiff,tiff,jpeg,png" label="Choose the image file for segmention (usually after registration)"/>
<param name="img_in" type="data" format="ome.tiff,tiff,jpg,png" label="Choose the image file for segmention (usually after registration)"/>
<param name="model_type" type="select" label="Choose the pre-trained model type">
<option value="nuclei" selected="true">nuclei</option>
<option value="cyto">cyto</option>
Expand Down Expand Up @@ -115,7 +116,9 @@
<param name="model_type" value="cyto"/>
<param name="chan" value="2"/>
<param name="chan2" value="3"/>
<param name="diameter" value="50"/>
<section name="options">
<param name="diameter" value="50"/>
</section>
<output name="cp_mask" file="img02_cp_masks_diameter.tif" compare="image_diff"/>
<output name="cp_segm" file="img02_cp_segm_diameter.png" compare="image_diff"/>
</test>
Expand Down
11 changes: 11 additions & 0 deletions tools/cellpose/cp_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
import matplotlib.pyplot as plt
import numpy as np
import skimage.io
import torch
from cellpose import models, plot, transforms


# Make sure, that MKL_NUM_THREADS is set to 1, to ensure reproducibility:
# https://forum.image.sc/t/reproducibility-how-we-spent-years-building-containers-and-then-mkl-decided-to-screw-our-results/109599
assert str(os.environ['MKL_NUM_THREADS']) == '1'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of asserting, could we also set this variable here again?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is, at what point MKL is loaded. My guess is that this happens when NumPy is loaded. I have made some adjustments based on your suggestion accordingly in 66fb725.


# Apply PyTorch guidelines for reproducibility
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.deterministic = True
torch.manual_seed(0)


def main(inputs, img_path, img_format, output_dir):
"""
Parameter
Expand Down
Binary file removed tools/cellpose/test-data/img02_cp_masks_rescale.tif
Binary file not shown.
Binary file modified tools/cellpose/test-data/img02_cp_segm_cyto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tools/cellpose/test-data/img02_cp_segm_diameter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tools/cellpose/test-data/img02_cp_segm_gpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading