l1 = np.mean(np.abs(t))
    real_center = (real_center + 1) * 127.5
    fake = (fake + 1) * 127.5

    def psnr(img1, img2):
        mse = np.mean((img1 - img2)**2)
        if mse == 0:
            return 100
        PIXEL_MAX = 255.0
        return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))

    for i in range(1):
        p = p + psnr(real_center[i].transpose(1, 2, 0), fake[i].transpose(
            1, 2, 0))

    ssim_none = ssim(out_crop, target_crop)
    sum_l1 = sum_l1 + l1
    sum_l2 = sum_l2 + l2
    sum_psnr_2 = sum_psnr_2 + p
    sum_ssim_2 = sum_ssim_2 + ssim_none

    outstr = "[Global-local] [%4d]-> " % count
    outstr = outstr + "l1:\t%f\t" % l1
    outstr = outstr + "l2:\t%f\t" % l2
    outstr = outstr + "psnr:\t%f\t" % p
    outstr = outstr + "ssim_img :\t%f\t \n" % ssim_none
    print(outstr)
    f.write(outstr)

outresultstr = "[Global-local] Total-> psnr:\t%f\t" % (sum_psnr_2 / count)
outresultstr = outresultstr + "ssim_img :\t%f\t \n" % (sum_ssim_2 / count)
Пример #2
0
for batch in testing_data_loader:
    input, target, input_masked = Variable(batch[0], volatile=True), Variable(batch[1], volatile=True), Variable(
        batch[2], volatile=True)

    if opt.cuda:
        netG = netG.cuda()
        input_masked = input_masked.cuda()
        target = target.cuda()

    out = netG(input_masked)
    count = count + 1

    mse = criterionMSE(out, target)
    psnr = 10 * math.log10(1 / mse.data[0])
    ssim_none = ssim(out, target)

    sum_psnr = sum_psnr + psnr
    sum_ssim = sum_ssim + ssim_none

    outstr = "[%4d]-> " % count
    outstr = outstr + "psnr:\t%f\t" % psnr
    outstr = outstr + "ssim_img :\t%f\t \n" % ssim_none
    print(outstr)
    f.write(outstr)


    out = out.cpu()
    out_img = out.data[0]

    def ToPilImage(image_tensor):
Пример #3
0
def torch_ssim(img, ref):  #input [28,256,256]
    return ssim(torch.unsqueeze(img, 0), torch.unsqueeze(ref, 0))
Пример #4
0
    ############## Stage_1 ##############
    if opt.cuda:
        netG_1st = netG_1st.cuda()
        input_masked = input_masked.cuda()
        target = target.cuda()
        input_2ndmasked =input_2ndmasked.cuda()

    input_small = down_sample(input)
    target_small = down_sample(target)
    out_1st = netG_1st(down_sample(input_masked))
    out_1st_up = up_sample(out_1st)

    mse = criterionMSE(out_1st, target_small)
    psnr = 10 * math.log10(1 / mse.data[0])
    ssim_none = ssim(out_1st, target_small)

    sum_psnr_1 = sum_psnr_1 + psnr
    sum_ssim_1 = sum_ssim_1 + ssim_none

    outstr = "[stage 1] [%4d]-> " % count
    outstr = outstr + "psnr:\t%f\t" % psnr
    outstr = outstr + "ssim_img :\t%f\t \n" % ssim_none
    print(outstr)
    f.write(outstr)

    input_small = input_small.cpu().data[0]
    out_1st = out_1st.cpu().data[0]
    target_small = target_small.cpu().data[0]
    merged_result_1st = torch.cat((input_small, out_1st, target_small), 1)
    #save_img(merged_result_1st, "result/{}/{}_{}_{}.jpg".format(opt.dataset, opt.model_1st, count, opt.dataset))