1818}
1919
2020
21- def check_segmentation_model (model_name , checkpoint_path = None ):
21+ def check_segmentation_model (model_name , checkpoint_path = None , input_path = None , check_prediction = False , ** kwargs ):
2222 output_folder = f"result_{ model_name } "
2323 os .makedirs (output_folder , exist_ok = True )
24- input_path = os .path .join (output_folder , f"{ model_name } .tif" )
25- if not os .path .exists (input_path ):
26- data_path = _sample_registry ().fetch (data_dict [model_name ])
27- copyfile (data_path , input_path )
24+ if input_path is None :
25+ input_path = os .path .join (output_folder , f"{ model_name } .tif" )
26+ if not os .path .exists (input_path ):
27+ data_path = _sample_registry ().fetch (data_dict [model_name ])
28+ copyfile (data_path , input_path )
2829
2930 output_path = os .path .join (output_folder , "segmentation.zarr" )
3031 if not os .path .exists (output_path ):
31- cmd = ["flamingo_tools.run_segmentation" , "-i" , input_path , "-o" , output_folder , "-m" , model_name ]
32+ cmd = [
33+ "flamingo_tools.run_segmentation" , "-i" , input_path , "-o" , output_folder , "-m" , model_name ,
34+ "--disable_masking" , "--min_size" , "5" ,
35+ ]
36+ for name , val in kwargs .items ():
37+ cmd .extend ([f"--{ name } " , str (val )])
3238 if checkpoint_path is not None :
3339 cmd .extend (["-c" , checkpoint_path ])
3440 subprocess .run (cmd )
@@ -38,6 +44,9 @@ def check_segmentation_model(model_name, checkpoint_path=None):
3844 image = imageio .imread (input_path )
3945 v = napari .Viewer ()
4046 v .add_image (image )
47+ if check_prediction :
48+ prediction = zarr .open (os .path .join (output_folder , "predictions.zarr" ))["prediction" ][:]
49+ v .add_image (prediction )
4150 v .add_labels (segmentation , name = f"{ model_name } -segmentation" )
4251 napari .run ()
4352
@@ -77,11 +86,13 @@ def main():
7786 # - Prediction works well on the GPU.
7887 # check_segmentation_model("IHC")
7988
80- # TODO: Update model.
8189 # SGN segmentation (lowres):
82- # - Prediction does not work well on the CPU.
83- # - Prediction does not work well on the GPU.
84- check_segmentation_model ("SGN-lowres" , checkpoint_path = "SGN-lowres.pt" )
90+ # - Prediction works well on the CPU.
91+ # - Prediction works well on the GPU.
92+ check_segmentation_model (
93+ "SGN-lowres" ,
94+ # boundary_distance_threshold=0.5, center_distance_threshold=None,
95+ )
8596
8697 # IHC segmentation (lowres):
8798 # - Prediction works well on the CPU.
0 commit comments