Exemple #1
0
def ComputeScores(list_rgb,
                  dic_gt,
                  dic_prob,
                  p1,
                  p2,
                  keep_memory=False,
                  path_save='./tmp'):
    res_AJI = []
    res_F1 = []
    res_DSB = []
    res_ps = []
    res_TP = []
    res_FN = []
    res_FP = []
    for path in list_rgb:
        GT = imread(dic_gt[path])
        GT = PostProcess(GT, 1, 0)
        DImg = dic_prob[path]
        DImg[DImg < 0] = 0
        DImg = DImg.astype("uint8")
        S = PostProcess(DImg, p1, p2)
        res_AJI.append(AJI_fast(GT, S))
        res_F1.append(ComputeF1(GT, S))
        scores, p_s, TP, FN, FP = DataScienceBowlMetrics(GT, S)
        res_DSB.append(scores)
        res_ps.append(p_s)
        res_TP.append(TP)
        res_FN.append(FN)
        res_FP.append(FP)
        if keep_memory:
            img_mean = np.mean(imread(path)[:, :, 0:3])
            if img_mean < 125:
                color_cont = False
            else:
                color_cont = True
            OUT = join(path_save, basename(path).replace('.png', ''))
            CheckOrCreate(OUT)
            os.symlink(abspath(path), join(OUT, "rgb.png"))
            os.symlink(abspath(dic_gt[path]), join(OUT, "bin.png"))
            imsave(join(OUT, "colored_bin.png"), color_bin(label(GT)))
            imsave(join(OUT, "colored_pred.png"), color_bin(S))
            imsave(join(OUT, "output_DNN.png"), DImg)
            imsave(join(OUT, "contours_gt.png"),
                   Overlay_with_pred(path, GT, color_cont).astype('uint8'))
            imsave(join(OUT, "contours_pred.png"),
                   Overlay_with_pred(path, S, color_cont).astype('uint8'))


#            pdb.set_trace()
    if keep_memory:
        return res_AJI, res_F1, res_DSB, res_ps, res_TP, res_FN, res_FP
    else:
        return np.mean(res_AJI), np.mean(res_F1), np.mean(res_DSB)
Exemple #2
0
    CheckOrCreate(options.output_sample)
    for key in dic.keys():
        OUT_ID = join(options.output_sample, basename(key).replace('.png', ''))
        CheckOrCreate(OUT_ID)
        dic_prob[key] = np.mean(np.concatenate(dic[key]), axis=0)[:, :, 1]
        dic_final_pred[key] = PostProcess(dic_prob[key], P1, P2)
        # dic_final_pred[key] = (dic_prob[key] > P2).astype('uint8')
        dic_final_pred[key] = label(dic_final_pred[key])
        dic_final_pred[key] = remove_small_objects(dic_final_pred[key], 32)
        img_mean = np.mean(imread(key)[:, :, 0:3])
        if img_mean < 125:
            color_cont = False
        else:
            color_cont = True
        #put rgb image
        os.symlink(abspath(key), join(OUT_ID, "rgb.png"))
        imsave(join(OUT_ID, "colored_pred.png"),
               color_bin(dic_final_pred[key]))
        imsave(join(OUT_ID, "output_DNN_mean.png"),
               img_as_ubyte(dic_prob[key]))
        for k, el in enumerate(dic[key]):
            imsave(
                join(OUT_ID, "output_DNN_{}.png").format(k),
                img_as_ubyte(el[0, :, :, 1]))
        imsave(
            join(OUT_ID, "contours_pred.png"),
            Overlay_with_pred(key, dic_final_pred[key],
                              color_cont).astype('uint8'))

    WriteEvaluation(outcsv, dic_final_pred)
Exemple #3
0
        tf.reset_default_graph() # so that it can restore properly the next model

    dic_final_pred = {}
    dic_prob = {}
    CheckOrCreate(options.output_sample)
    for key in dic.keys():
        OUT_ID = join(options.output_sample, basename(key).replace('.png', ''))
        CheckOrCreate(OUT_ID)
        dic_prob[key] = np.mean(np.concatenate(dic[key]), axis=0)[:,:,1] 
        dic_final_pred[key] = PostProcess(dic_prob[key], P1, P2)
        # dic_final_pred[key] = (dic_prob[key] > P2).astype('uint8')
        dic_final_pred[key] = label(dic_final_pred[key])
        dic_final_pred[key] = remove_small_objects(dic_final_pred[key], 32)
        img_mean = np.mean(imread(key)[:,:,0:3])
        if img_mean < 125:
            color_cont = False
        else:
            color_cont = True
        #put rgb image
        os.symlink(abspath(key), join(OUT_ID, "rgb.png"))            
        imsave(join(OUT_ID, "colored_pred.png"), color_bin(dic_final_pred[key])) 
        imsave(join(OUT_ID, "output_DNN_mean.png"), img_as_ubyte(dic_prob[key]))
        for k, el in enumerate(dic[key]):
            imsave(join(OUT_ID, "output_DNN_{}.png").format(k), img_as_ubyte(el[0,:,:,1])) 
        imsave(join(OUT_ID, "contours_pred.png"), Overlay_with_pred(key, dic_final_pred[key], color_cont).astype('uint8'))




    WriteEvaluation(outcsv, dic_final_pred)