diff cp_segmentation.py @ 5:5251ce4c4a11 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/cellpose commit 5846f23282167df28e6cc00e1bda31523b66b5b4
author bgruening
date Sat, 15 Mar 2025 17:24:09 +0000
parents 32153c43126c
children
line wrap: on
line diff
--- a/cp_segmentation.py	Tue Feb 11 14:48:08 2025 +0000
+++ b/cp_segmentation.py	Sat Mar 15 17:24:09 2025 +0000
@@ -3,11 +3,24 @@
 import os
 import warnings
 
+# 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
+if str(os.environ['MKL_NUM_THREADS']) != '1':
+    warnings.warn('MKL_NUM_THREADS must be set to 1 to ensure reproducibility, and will be adjusted accordingly for now.')
+    os.environ['MKL_NUM_THREADS'] = '1'
+
+# Load the remaining packages *after* adjusting `MKL_NUM_THREADS` (this likely necessary for it to take effect)
 import matplotlib.pyplot as plt
 import numpy as np
 import skimage.io
+import torch
 from cellpose import models, plot, transforms
 
+# 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):
     """