for i in range(len(test_dataset)):
    image, gt_mask = test_dataset[i]
    images.append(image)
    gt_masks.append(gt_mask)
images = np.stack(images)
gt_masks = np.stack(gt_masks)

# scale back from args.flu_scale
gt_masks = np.uint8(gt_masks / args.scale * 255)
pr_masks = pr_masks / args.scale * 255
pr_masks = np.uint8(np.clip(pr_masks, 0, 255))

# save prediction examples
plot_fig_file = model_folder + '/pred_examples.png'
nb_images = 10
plot_flu_prediction(plot_fig_file, images, gt_masks, pr_masks, nb_images)
# output_dir = model_folder+'/pred_fl'; generate_folder(output_dir)
# plot_set_prediction(output_dir, images, gt_masks, pr_masks)
# calculate PSNR
mPSNR, psnr_scores = calculate_psnr(gt_masks, pr_masks)
print('PSNR: {:.4f}'.format(mPSNR))

# calculate Pearson correlation coefficient
mPear, pear_scores = calculate_pearsonr(gt_masks, pr_masks)
print('Pearsonr:{:.4f}'.format(mPear))

with open(model_folder + '/metric_summary.txt', 'w+') as f:
    # loss
    f.write("loss {}: {:.5}\n".format(metric.__name__, value))
    # average psnr
    for metric, value in zip(metrics, scores[1:]):
示例#2
0
# # 	maps = np.zeros(masks.shape[:-1])
# 	G2_map = np.logical_and(masks[:,:,:,0],masks[:,:,:,1])
# 	G1_map = np.logical_and(masks[:,:,:,0],np.logical_not(G2_map))
# 	S_map = np.logical_and(masks[:,:,:,1],np.logical_not(G2_map))
# 	maps = G2_map*3 + G1_map*1 + S_map*2
# 	map_rgb = np.stack([G1_map*255, S_map*255, G2_map*255],axis =-1).astype(np.uint8)
# 	return maps, map_rgb
# gt_MAPs, gt_MAPs_rgb = convert2map(gt_MASKs); pr_MAPs, pr_MAPs_rgb = convert2map(pr_MASKs)
# plot_map_prediction(model_folder+'/pred_maps.png', images, gt_MAPs_rgb, pr_MAPs_rgb, nb_images)

# save prediction examples
plot_fig_file = model_folder + '/pred_examples.png'
nb_images = 4
plot_flu_prediction(plot_fig_file,
                    images,
                    gt_masks,
                    pr_masks,
                    nb_images,
                    rand_seed=6)

import grant_helper_function as ghf

ghf.plot_flu_prediction(model_folder + '/pred_examples_colorbar.png',
                        images,
                        gt_masks,
                        pr_masks,
                        nb_images,
                        rand_seed=6)
ghf.plot_flu_prediction2(model_folder + '/grants_fl',
                         images,
                         gt_masks,
                         pr_masks,