def test_get_ncr_net(volume): just_ncr_net = brats_labels.get_ncr_net(volume.copy()) plot_3_view("ncr_net", just_ncr_net[:, :, :], 100, save=True) plot_3_view("whole", volume[:, :, :], 100, save=True) assert [0, 1] == list(np.unique(just_ncr_net))
def tta_uncertainty_loop(model, images, device, brain_mask, iterations=2, monte_carlo=False): prediction_labels_maps, prediction_score_vectors = [], [] data_transformations = _get_transforms() range_transforms = range(0, len(data_transformations)) for i in tqdm(range(iterations), desc="Predicting.."): random_transform_idx = np.random.choice(range_transforms) transform = data_transformations[random_transform_idx] subject, _, _ = transform((images, None, brain_mask)) prediction_four_channels, vector_prediction_scores = predict.predict( model, subject.astype(float), device, monte_carlo=monte_carlo) pred_map = predict.get_prediction_map(prediction_four_channels) plot_3_view(f"pred_map_{i}_{random_transform_idx}", pred_map[:, :, :], 40, save=True) plot_3_view(f"subject_{i}_{random_transform_idx}", subject[0, :, :, :], 40, save=True) prediction_labels_maps.append(pred_map) prediction_score_vectors.append(vector_prediction_scores) return prediction_labels_maps, prediction_score_vectors
def test_visual_test(): volume, volume_patch, seg_patch = patching_strategy(patching, (64, 64, 64)) # plot_3_view("random_tumor_flair", volume[0, :, :, :], 100, save=save) plot_3_view("random_tumor_patch_flair", volume_patch[0, :, :, :], 32, save=save) plot_3_view("random_tumor_path_seg", seg_patch[:, :, :], 32, save=save)
def test_random_rotation_90_real_patient(patient): volume, seg, brain_mask = patient rot = RandomRotation90(p=1) rot_volume, rot_seg, _ = rot.__call__(img_and_mask=(volume, seg, brain_mask)) plot_3_view("rotated_volume", rot_volume[0, :, :, :], 100, save=True) plot_3_view("rotated_seg", rot_seg[:, :, :], 100, save=True) plot_3_view("volume", volume[0, :, :, :], 100, save=True) plot_3_view("seg", seg[:, :, :], 100, save=True)
def plot(volume: np.ndarray, patch: np.ndarray, volume_slice: int = 100): plot_3_view("flair", volume[0, :, :, :], volume_slice, save=True) plot_3_view("patch_flair", patch[0, :, :, :], volume_slice, save=True)
def test_visual_test(): volume, volume_patch, seg_patch = patching_strategy(patching, (80, 80, 80)) plot_3_view("equal_flair", volume[0, :, :, :], 100, save=save) plot_3_view("equal_patch_flair", volume_patch[0, :, :, :], 40, save=save) plot_3_view("equal_path_seg", seg_patch[:, :, :], 40, save=save)
def test_visual_test(): volume, volume_patch, seg_patch = patching_strategy( patching, (160, 160, 128)) plot_3_view("center_flair", volume[0, :, :, :], 100, save=save) plot_3_view("center_patch_flair", volume_patch[0, :, :, :], 100, save=save) plot_3_view("center_path_seg", seg_patch[:, :, :], 100, save=save)