Esempio n. 1
0
        data[0, 15:20] = cbv_img[z - 2:z + 3]
        pred = pred_fn(data).transpose((0, 2, 3, 1)).reshape(
            (t1km_img.shape[1] - t1km_img.shape[1] % 16,
             t1km_img.shape[2] - t1km_img.shape[2] % 16, 5))
        res[z] = pred
        z += 1

    res = res[2:t1km_img.shape[0] - 2]
    seg_combined = seg_combined[2:t1km_img.shape[0] - 2]
    res_img = res.argmax(-1)

    print "calculating metrics"
    acc, metrics_by_class = calculate_validation_metrics(
        res, seg_combined, {
            0: 'background',
            1: 'brain',
            2: 'edema',
            3: 'ce_tumor',
            4: 'necrosis'
        })
    with open(os.path.join(output_folder, "validation_metrics.txt"), 'w') as f:
        f.write("The overall accuracy on this dataset was: \t%f\n\n" % acc)
        for c in metrics_by_class.keys():
            f.write("Results for label: %s\n" % c)
            for metric in metrics_by_class[c].keys():
                f.write("%s: \t%f\n" % (metric, metrics_by_class[c][metric]))
            f.write("\n")

    output_folder_images = os.path.join(output_folder, "segmentation_slices")
    if not os.path.isdir(output_folder_images):
        os.mkdir(output_folder_images)
Esempio n. 2
0
    res = np.zeros((t1km_img.shape[0], output_shape[0], output_shape[1], 6))
    while z < t1km_img.shape[0]-2:
        data[0,0:5] = t1_img[z-2:z+3]
        data[0,5:10] = t1km_img[z-2:z+3]
        data[0,10:15] = t2_img[z-2:z+3]
        data[0,15:20] = flair_img[z-2:z+3]
        pred = pred_fn(data).transpose((0,2,3,1)).reshape((output_shape[0], output_shape[1], 6))
        res[z] = pred
        z += 1

    res = res[2:t1km_img.shape[0]-2]
    seg_combined = seg_combined[2:t1km_img.shape[0]-2]
    res_img = res.argmax(-1)

    print "calculating metrics"
    acc, metrics_by_class = calculate_validation_metrics(res, seg_combined, {0: 'background', 1: 'brain', 2: 'necrosis', 3: 'edema', 4: 'non-enhancing tumor', 5:'enhancing tumor'}, 6)
    with open(os.path.join(output_folder, "validation_metrics.txt"), 'w') as f:
        f.write("The overall accuracy on this dataset was: \t%f\n\n" % acc)
        for c in metrics_by_class.keys():
            f.write("Results for label: %s\n" % c)
            for metric in metrics_by_class[c].keys():
                f.write("%s: \t%f\n" % (metric, metrics_by_class[c][metric]))
            f.write("\n")

    output_folder_images = os.path.join(output_folder, "segmentation_slices")
    if not os.path.isdir(output_folder_images):
        os.mkdir(output_folder_images)

    np.save(os.path.join(output_folder, "seg_gt.npy"), seg_combined)
    np.save(os.path.join(output_folder, "seg_pred.npy"), res_img)