@@ -16,7 +16,7 @@ def test_cli_test_model(unet2d_nuclei_broad_model):
1616 assert ret .returncode == 0
1717
1818
19- def test_cli_test_model_with_specific_weight_format (unet2d_nuclei_broad_model ):
19+ def test_cli_test_model_with_weight_format (unet2d_nuclei_broad_model ):
2020 ret = subprocess .run (
2121 ["bioimageio" , "test-model" , unet2d_nuclei_broad_model , "--weight-format" , "pytorch_state_dict" ]
2222 )
@@ -28,25 +28,34 @@ def test_cli_test_resource(unet2d_nuclei_broad_model):
2828 assert ret .returncode == 0
2929
3030
31- def test_cli_test_resource_with_specific_weight_format (unet2d_nuclei_broad_model ):
31+ def test_cli_test_resource_with_weight_format (unet2d_nuclei_broad_model ):
3232 ret = subprocess .run (
3333 ["bioimageio" , "test-model" , unet2d_nuclei_broad_model , "--weight-format" , "pytorch_state_dict" ]
3434 )
3535 assert ret .returncode == 0
3636
3737
38- def test_cli_predict_image ( unet2d_nuclei_broad_model , tmp_path ):
39- spec = load_resource_description (unet2d_nuclei_broad_model )
38+ def _test_cli_predict_image ( model , tmp_path , extra_kwargs = None ):
39+ spec = load_resource_description (model )
4040 in_path = spec .test_inputs [0 ]
4141 out_path = tmp_path .with_suffix (".npy" )
42- ret = subprocess .run (
43- ["bioimageio" , "predict-image" , unet2d_nuclei_broad_model , "--inputs" , str (in_path ), "--outputs" , str (out_path )]
44- )
42+ cmd = ["bioimageio" , "predict-image" , model , "--inputs" , str (in_path ), "--outputs" , str (out_path )]
43+ if extra_kwargs is not None :
44+ cmd .extend (extra_kwargs )
45+ ret = subprocess .run (cmd )
4546 assert ret .returncode == 0
4647 assert out_path .exists ()
4748
4849
49- def test_cli_predict_images (unet2d_nuclei_broad_model , tmp_path ):
50+ def test_cli_predict_image (unet2d_nuclei_broad_model , tmp_path ):
51+ _test_cli_predict_image (unet2d_nuclei_broad_model , tmp_path )
52+
53+
54+ def test_cli_predict_image_with_weight_format (unet2d_nuclei_broad_model , tmp_path ):
55+ _test_cli_predict_image (unet2d_nuclei_broad_model , tmp_path , ["--weight-format" , "pytorch_state_dict" ])
56+
57+
58+ def _test_cli_predict_images (model , tmp_path , extra_kwargs = None ):
5059 n_images = 3
5160 shape = (1 , 1 , 128 , 128 )
5261 expected_shape = (1 , 1 , 128 , 128 )
@@ -64,14 +73,25 @@ def test_cli_predict_images(unet2d_nuclei_broad_model, tmp_path):
6473 expected_outputs .append (out_folder / f"im-{ i } .npy" )
6574
6675 input_pattern = str (in_folder / "*.npy" )
67- ret = subprocess .run (["bioimageio" , "predict-images" , unet2d_nuclei_broad_model , input_pattern , str (out_folder )])
76+ cmd = ["bioimageio" , "predict-images" , model , input_pattern , str (out_folder )]
77+ if extra_kwargs is not None :
78+ cmd .extend (extra_kwargs )
79+ ret = subprocess .run (cmd )
6880 assert ret .returncode == 0
6981
7082 for out_path in expected_outputs :
7183 assert out_path .exists ()
7284 assert np .load (out_path ).shape == expected_shape
7385
7486
87+ def test_cli_predict_images (unet2d_nuclei_broad_model , tmp_path ):
88+ _test_cli_predict_images (unet2d_nuclei_broad_model , tmp_path )
89+
90+
91+ def test_cli_predict_images_with_weight_format (unet2d_nuclei_broad_model , tmp_path ):
92+ _test_cli_predict_images (unet2d_nuclei_broad_model , tmp_path , ["--weight-format" , "pytorch_state_dict" ])
93+
94+
7595def test_torch_to_torchscript (unet2d_nuclei_broad_model , tmp_path ):
7696 out_path = tmp_path .with_suffix (".pt" )
7797 ret = subprocess .run (
0 commit comments