def test_segment_2d():
    from keras import backend as K
    K.set_image_data_format(
        "channels_last"
    )  # Set at channels_first in test_deepseg_lesion.test_segment()

    contrast_test = 't2'
    model_path = os.path.join(sct.__sct_dir__, 'data', 'deepseg_sc_models',
                              '{}_sc.h5'.format(contrast_test))

    fname_t2 = os.path.join(sct.__sct_dir__, 'sct_testing_data/t2/t2.nii.gz'
                            )  # install: sct_download_data -d sct_testing_data
    fname_t2_seg = os.path.join(
        sct.__sct_dir__, 'sct_testing_data/t2/t2_seg.nii.gz'
    )  # install: sct_download_data -d sct_testing_data

    img, gt = _preprocess_segment(fname_t2, fname_t2_seg, contrast_test)

    seg = deepseg_sc.segment_2d(model_fname=model_path,
                                contrast_type=contrast_test,
                                input_size=(64, 64),
                                im_in=img)
    assert seg.dtype == np.dtype('float32')

    seg_im = img.copy()
    seg_im.data = (seg > 0.5).astype(np.uint8)
    assert msct_image.compute_dice(seg_im, gt) > 0.80
def test_segment_2d():
    from keras import backend as K
    K.set_image_data_format("channels_last")  # Set at channels_first in test_deepseg_lesion.test_segment()

    contrast_test = 't2'
    model_path = os.path.join(sct.__sct_dir__, 'data', 'deepseg_sc_models', '{}_sc.h5'.format(contrast_test))   

    fname_t2 = os.path.join(sct.__sct_dir__, 'sct_testing_data/t2/t2.nii.gz')  # install: sct_download_data -d sct_testing_data
    fname_t2_seg = os.path.join(sct.__sct_dir__, 'sct_testing_data/t2/t2_seg.nii.gz')  # install: sct_download_data -d sct_testing_data

    img, gt = _preprocess_segment(fname_t2, fname_t2_seg, contrast_test)

    seg = deepseg_sc.segment_2d(model_fname=model_path, contrast_type=contrast_test, input_size=(64,64), im_in=img)
    seg_im = img.copy()
    seg_im.data = seg

    assert msct_image.compute_dice(seg_im, gt) > 0.80