77from elf .io import open_file
88
99
10+ def _load_n5 (path , key , lazy ):
11+ data = open_file (path , "r" )[key ]
12+ if not lazy :
13+ data = data [:]
14+ return data
15+
16+
1017# will not work for very large images
11- def check_prediction (input_path , output_folder , check_downsampled = False , input_key = None ):
18+ def check_prediction (input_path , output_folder , check_downsampled = False , input_key = None , lazy = False ):
1219 if input_key is None :
1320 input_ = imageio .imread (input_path )
1421 else :
15- input_ = open_file (input_path , "r" )[ input_key ][:]
22+ input_ = _load_n5 (input_path , input_key , lazy )
1623
1724 if check_downsampled :
1825
1926 pred_path = os .path .join (output_folder , "predictions.zarr" )
20- with open_file (pred_path , "r" ) as f :
21- prediction = f ["prediction" ][:]
27+ prediction = _load_n5 (pred_path , "prediction" , lazy )
2228
2329 seg_path = os .path .join (output_folder , "seg_downscaled.zarr" )
24- with open_file (seg_path , "r" ) as f :
25- segmentation = f ["segmentation" ][:]
30+ segmentation = _load_n5 (seg_path , "segmentation" , lazy )
2631
2732 scale = (0.5 , 0.5 , 0.5 )
2833
2934 else :
3035 seg_path = os .path .join (output_folder , "segmentation.zarr" )
36+ segmentation = _load_n5 (seg_path , "segmentation" , lazy )
3137 with open_file (seg_path , "r" ) as f :
32- segmentation = f ["segmentation" ][:]
3338 if "segmentation_postprocessed" in f :
34- seg_pp = f [ "segmentation_postprocessed" ][:]
39+ seg_pp = _load_n5 ( seg_path , "segmentation_postprocessed" , lazy )
3540 else :
3641 seg_pp = None
3742
@@ -54,9 +59,13 @@ def main():
5459 parser .add_argument ("-o" , "--output_folder" , required = True )
5560 parser .add_argument ("-k" , "--input_key" , default = None )
5661 parser .add_argument ("-c" , "--check_downsampled" , action = "store_true" )
62+ parser .add_argument ("--lazy" , action = "store_true" )
5763
5864 args = parser .parse_args ()
59- check_prediction (args .input , args .output_folder , check_downsampled = args .check_downsampled , input_key = args .input_key )
65+ check_prediction (
66+ args .input , args .output_folder , check_downsampled = args .check_downsampled ,
67+ input_key = args .input_key , lazy = args .lazy
68+ )
6069
6170
6271if __name__ == "__main__" :
0 commit comments