Exemple #1
0
def test_run_scoring(test_output_dirs: OutputFolderForTests,
                     is_ensemble: bool) -> None:
    """
    Run the scoring script on an image file.
    This test lives outside the normal Tests folder because it imports "score.py" from the repository root folder.
    If we switched to InnerEye as a package, we would have to treat this import special.
    The inference run here is on a 1-channel model, whereas test_register_and_score_model works with a 2-channel
    model.
    """
    seed_everything(42)
    checkpoint = test_output_dirs.root_dir / "checkpoint.ckpt"
    image_size = (40, 40, 40)
    test_crop_size = image_size
    dummy_config = DummyModel()
    dummy_config.test_crop_size = test_crop_size
    dummy_config.inference_stride_size = (10, 10, 10)
    dummy_config.inference_batch_size = 10
    create_model_and_store_checkpoint(dummy_config, checkpoint)
    all_paths = [checkpoint] * 2 if is_ensemble else [checkpoint]
    inference_pipeline, dummy_config = create_inference_pipeline(dummy_config,
                                                                 all_paths,
                                                                 use_gpu=False)
    image_with_header = io_util.load_nifti_image(test_image)
    image_with_header.image = image_with_header.image[:image_size[
        0], :image_size[1], :image_size[2]]
    result = run_inference([image_with_header, image_with_header],
                           inference_pipeline, dummy_config)
    assert image_with_header.image.shape == result.shape  # type: ignore
    print(f"Unique result values: {np.unique(result)}")
    assert np.all(result == 1)
def test_run_scoring(is_ensemble: bool) -> None:
    checkpoints_paths = checkpoint_full_paths * 2 if is_ensemble else checkpoint_full_paths
    dummy_config = DummyModel()
    inference_pipeline, dummy_config = create_inference_pipeline(dummy_config, checkpoints_paths, use_gpu=False)
    image_with_header = io_util.load_nifti_image(test_image)
    result = run_inference([image_with_header, image_with_header], inference_pipeline, dummy_config)
    assert np.all(result == 1)
    assert image_with_header.image.shape == result.shape  # type: ignore