Example #1
0
    def stat_of_all_models(self, img_true, n_out):
        '''
            return two lists of dice coefficient and error of all models in the ensemble
        '''
        dices = []
        errs = []
        count = 1
        for pred_raw in self.pred_raws:
            # Compute img_pred
            pred_all = np.argmax(pred_raw, axis=1)
            img_pred = create_img_from_pred(self.vx_all, pred_all,
                                            img_true.shape)

            # Compute the dice coefficient and the error
            non_zo = img_pred.nonzero() or img_true.nonzero()
            pred = img_pred[non_zo]
            true = img_true[non_zo]
            dice_regions = compute_dice(pred, true, n_out)
            dices.append(dice_regions.mean())
            err_global = error_rate(pred, true)
            errs.append(err_global)
            count = count + 1

        return dices, errs
Example #2
0
        brain_batches = data_gen.generate_single_atlas(atlas_id, None,
                                                       region_centroids,
                                                       batch_size, True)

        vx_all, pred_all = net.predict_from_generator(brain_batches, scaler,
                                                      pred_functions)

        # Construct the predicted image
        img_true = data_gen.atlases[atlas_id][1]
        img_pred = create_img_from_pred(vx_all, pred_all, img_true.shape)

        # Compute the dice coefficient and the error
        non_zo = img_pred.nonzero() or img_true.nonzero()
        pred = img_pred[non_zo]
        true = img_true[non_zo]
        dice_regions = compute_dice(pred, true, n_out)
        err_global = error_rate(pred, true)

        end_time = time.clock()
        print "It took {} seconds to evaluate the whole brain.".format(
            end_time - start_time)
        print "The mean dice is {}".format(dice_regions.mean())
        print "The error rateis {}".format(err_global)

        # Save the results
        errors[atlas_id] = err_global
        dices[atlas_id, :] = dice_regions

        # Diff Image
        img_diff = (img_pred == img_true).astype(np.uint8)
        img_diff += 1
from spynet.utils.utilities import open_h5file

if __name__ == '__main__':
    """
    Evaluate a trained network (without approximating the centroids)
    """

    experiment_path = "./experiments/paper_ultimate_conv/"
    data_path = "./datasets/paper_ultimate_conv/"

    # Load the network
    net = NetworkUltimateConv()
    net.init(33, 29, 5, 134, 135)
    net.load_parameters(open_h5file(experiment_path + "net.net"))
    n_out = net.n_out

    # Load the scaler
    scaler = pickle.load(open(experiment_path + "s.scaler", "rb"))

    testing_data_path = data_path + "test.h5"
    ds_testing = DatasetBrainParcellation()
    ds_testing.read(testing_data_path)
    scaler.scale(ds_testing.inputs)

    out_pred = net.predict(ds_testing.inputs, 1000)
    errors = np.argmax(out_pred, axis=1) != np.argmax(ds_testing.outputs,
                                                      axis=1)
    dice = compute_dice(np.argmax(out_pred, axis=1),
                        np.argmax(ds_testing.outputs, axis=1), 134)
    print np.mean(dice)
    print np.mean(errors)
        ls_vx = []
        ls_pred = []
        brain_batches = data_gen.generate_single_atlas(atlas_id, None, region_centroids, batch_size, True)

        vx_all, pred_all = net.predict_from_generator(brain_batches, scaler, pred_functions)

        # Construct the predicted image
        img_true = data_gen.atlases[atlas_id][1]
        img_pred = create_img_from_pred(vx_all, pred_all, img_true.shape)

        # Compute the dice coefficient and the error
        non_zo = img_pred.nonzero() or img_true.nonzero()
        pred = img_pred[non_zo]
        true = img_true[non_zo]
        dice_regions = compute_dice(pred, true, n_out)
        err_global = error_rate(pred, true)

        end_time = time.clock()
        print "It took {} seconds to evaluate the whole brain.".format(end_time - start_time)
        print "The mean dice is {}".format(dice_regions.mean())
        print "The error rateis {}".format(err_global)

        # Save the results
        errors[atlas_id] = err_global
        dices[atlas_id, :] = dice_regions

        # Diff Image
        img_diff = (img_pred == img_true).astype(np.uint8)
        img_diff += 1
        img_diff[img_pred == 0] = 0
Example #5
0
from data_brain_parcellation import DatasetBrainParcellation, DataGeneratorBrain, list_miccai_files, RegionCentroids
from spynet.utils.utilities import open_h5file


if __name__ == '__main__':
    """
    Evaluate a trained network (without approximating the centroids)
    """

    experiment_path = "./experiments/paper_ultimate_conv/"
    data_path = "./datasets/paper_ultimate_conv/"

    # Load the network
    net = NetworkUltimateConv()
    net.init(33, 29, 5, 134, 135)
    net.load_parameters(open_h5file(experiment_path + "net.net"))
    n_out = net.n_out

    # Load the scaler
    scaler = pickle.load(open(experiment_path + "s.scaler", "rb"))

    testing_data_path = data_path + "test.h5"
    ds_testing = DatasetBrainParcellation()
    ds_testing.read(testing_data_path)
    scaler.scale(ds_testing.inputs)

    out_pred = net.predict(ds_testing.inputs, 1000)
    errors = np.argmax(out_pred, axis=1) != np.argmax(ds_testing.outputs, axis=1)
    dice = compute_dice(np.argmax(out_pred, axis=1), np.argmax(ds_testing.outputs, axis=1), 134)
    print np.mean(dice)
    print np.mean(errors)