Esempio n. 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
Esempio n. 2
0
    for atlas_id in xrange(n_files):

        print "Atlas: {}".format(atlas_id)

        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 = np.zeros((n_files,))

    pred_functions = {}
    for atlas_id in xrange(n_files):

        print "Atlas: {}".format(atlas_id)

        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