Пример #1
0
def test_VDSR_with_sess(epoch, ckpt_path, data_path, sess):
    folder_list = glob.glob(os.path.join(data_path, 'Set*'))
    print('folder_list', folder_list)
    saver.restore(sess, ckpt_path)

    psnr_dict = {}
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        for i in range(len(img_list)):
            input_list, gt_list, scale_list = get_test_image(img_list, i, 1)
            input_y = input_list[0]
            gt_y = gt_list[0]

            img_vdsr_y = sess.run(
                [output_tensor],
                feed_dict={
                    input_tensor:
                    np.resize(input_y,
                              (1, input_y.shape[0], input_y.shape[1], 1))
                })
            img_vdsr_y = np.resize(img_vdsr_y,
                                   (input_y.shape[0], input_y.shape[1]))

            psnr_bicub = psnr(input_y, gt_y, scale_list[0])
            psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
            print("PSNR: bicubic %f\tVDSR %f" % (psnr_bicub, psnr_vdsr))
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
    with open('psnr/%s' % os.path.basename(ckpt_path), 'wb') as f:
        pickle.dump(psnr_dict, f)
Пример #2
0
def test_VDSR_with_sess(epoch, data_path, sess):
    folder_list = glob.glob(os.path.join(data_path, 'Set*'))
    print('folder_list', folder_list)
    saver.restore(sess, tf.train.latest_checkpoint("./checkpoints/"))

    psnr_dict = {}
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        for i in range(len(img_list)):
            input_list, gt_list, scale_list = get_test_image(img_list, i, 1)
            input_y = input_list[0]
            gt_y = gt_list[0]
            start_t = time.time()
            img_vdsr_y = sess.run(
                [output_tensor],
                feed_dict={
                    input_tensor:
                    np.resize(input_y,
                              (1, input_y.shape[0], input_y.shape[1], 1))
                })
            img_vdsr_y = np.resize(img_vdsr_y,
                                   (input_y.shape[0], input_y.shape[1]))
            end_t = time.time()
            print("end_t", end_t, "start_t", start_t)
            print("time consumption", end_t - start_t)
            print("image_size", input_y.shape)

            psnr_bicub = psnr(input_y, gt_y, scale_list[0])
            psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
            print("PSNR: bicubic %f\tVDSR %f" % (psnr_bicub, psnr_vdsr))
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
Пример #3
0
def test_VDSR_with_sess(epoch, ckpt_path, data_path,sess):
    # folder_list = glob.glob(os.path.join(data_path, 'Set*'))
    # print('folder_list', folder_list) # ./data/test/Set5

    folder_list = glob.glob(os.path.join(data_path, SUB_PATH))
    print('folder_list', folder_list)

    saver.restore(sess, ckpt_path)
    
    psnr_dict = {}
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        print("file number in ", folder_path, ": ", len(img_list))
        for i in range(len(img_list)):
            input_list, gt_list, scale_list = get_test_image(img_list, i, 1)
            input_y = input_list[0]
            gt_y = gt_list[0]
            start_t = time.time()
            input_array = np.resize(input_y, (1, input_y.shape[0], input_y.shape[1], 1))
            img_vdsr_y = sess.run([output_tensor], feed_dict={input_tensor: input_array})
            img_vdsr_y = np.resize(img_vdsr_y, (input_y.shape[0], input_y.shape[1]))
            end_t = time.time()
            print("end_t",end_t,"start_t",start_t)
            print("time consumption",end_t-start_t)
            print("image_size", input_y.shape)
            
            psnr_bicub = psnr(input_y, gt_y, scale_list[0])
            psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
            print("PSNR: bicubic %f\tVDSR %f" % (psnr_bicub, psnr_vdsr))
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
    with open('psnr/%s' % os.path.basename(ckpt_path), 'wb') as f:
        pickle.dump(psnr_dict, f)
Пример #4
0
def Show_result(Denoiser, loader, pause, check=False):
    Denoiser.eval()

    plt.ion()
    plt.show()

    #Calcul de la PSNR moyenne
    PSNRmoy = 0
    Compteur = 0

    for i, data in enumerate(loader):
        images, groundtrue = data

        plt.figure(1)
        plt.clf()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(groundtrue, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        print("Image bruitée")
        plt.figure(2)
        plt.clf()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(images, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        A = psnr(groundtrue.numpy(), images.numpy(), check=check)
        plt.title(r'%f ' % A)

        print("Image débruitée")
        plt.figure(3)
        plt.clf()
        images = Denoiser(
            Variable(images, requires_grad=False).type(gpu_dtype)).data.cpu()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(images, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        A = psnr(groundtrue.numpy(), images.numpy(), check=check)
        PSNRmoy += A
        Compteur += 1
        plt.title(r'%f ' % A)

        plt.pause(pause)

    print('PSNR moyen = %f ' % (PSNRmoy / Compteur))
def test_VDSR_with_sess(
    epoch,
    ckpt_path,
    data_path,
    sess,
):
    folder_list = glob.glob(os.path.join(data_path))
    print 'folder_list', folder_list
    saver.restore(sess, ckpt_path)

    psnr_dict = {}
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        for i in range(len(img_list)):
            (input_list, gt_list, scale_list) = get_image_batch(img_list, i, 2)

            input_y = input_list
            gt_y = gt_list
            # print input_y[0].shape
            start_t = time.time()
            # img_vdsr_y = sess.run([output_tensor],
            #                       feed_dict={input_tensor: np.resize(input_y,
            #                       (1, input_y.shape[0],
            #                       input_y.shape[1], 1))})
            img_vdsr_y = sess.run([output_tensor],
                                  feed_dict={input_tensor: input_y})
            print np.asarray(img_vdsr_y).shape
            # img_vdsr_y = np.resize(img_vdsr_y, (2, input_y.shape[1],
            #                        input_y.shape[2],1))
            end_t = time.time()
            print 'end_t', end_t, 'start_t', start_t
            print 'time consumption', end_t - start_t
            print 'image_size', input_y.shape
            img_vdsr_y = np.asarray(img_vdsr_y[0])
            print 'img_vdsr_y', img_vdsr_y.shape
            print 'input_y', input_y.shape
            print 'gt_y', gt_y.shape
            # misc.toimage(np.resize(img_vdsr_y[0],(input_y.shape[1], input_y.shape[2]) ),
            #  cmin=0.0,cmax=1.0).save('outfile_%d.jpg' % i)
            img = util.combine_img_prediction(input_y, gt_y, img_vdsr_y)
            util.save_image(img, 'outfile%d.jpg' % i)
            scipy.io.savemat('outfile%d' % i, mdict={'img': img_vdsr_y})

            # misc.toimage(img_vdsr_y).save('outfile%d.jpg' %i)

            psnr_bicub = psnr(input_y, gt_y, scale_list)
            psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list)
            print 'PSNR: bicubic %f\tVDSR %f' % (psnr_bicub, psnr_vdsr)
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
    with open('psnr/%s' % os.path.basename(ckpt_path), 'wb') as f:
        pickle.dump(psnr_dict, f)
Пример #6
0
def test_VDSR_with_sess(epoch, ckpt_path, data_path, sess):
    folder_list = glob.glob(os.path.join(data_path, 'Set*'))
    print 'folder_list', folder_list
    saver.restore(sess, ckpt_path)

    psnr_dict = {}
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        #print('img_list: ',img_list)
        for i in range(len(img_list)):
            input_list, gt_list, scale_list = get_test_image(img_list, i, 1)
            input_y = input_list[0]
            gt_y = gt_list[0]
            start_t = time.time()
            img_vdsr_y = sess.run(
                [output_tensor],
                feed_dict={
                    input_tensor:
                    np.resize(input_y,
                              (1, input_y.shape[0], input_y.shape[1], 1))
                })
            img_vdsr_y = np.resize(img_vdsr_y,
                                   (input_y.shape[0], input_y.shape[1]))
            end_t = time.time()
            print "end_t", end_t, "start_t", start_t
            print "time consumption", end_t - start_t
            print "image_size", input_y.shape

            img_y = nparryToImage(img_vdsr_y)
            '''
			img_cb = nparryToImage(gt_list[1])
			img_cr = nparryToImage(gt_list[2])

			img_cb = img_cb.resize(img_y.size,Image.BICUBIC)
			img_cr = img_cr.resize(img_y.size,Image.BICUBIC)

			img_rgb = YcrcbToRGB(img_y,img_cb,img_cr)
			img_rgb.show()
			'''
            img_y.show()

            psnr_bicub = psnr(input_y, gt_y, scale_list[0])
            psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
            print "PSNR: bicubic %f\tVDSR %f" % (psnr_bicub, psnr_vdsr)
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
    with open('psnr/%s' % os.path.basename(ckpt_path), 'wb') as f:
        pickle.dump(psnr_dict, f)
Пример #7
0
    def test_VDSR_with_sess(self, ckpt_path, data_path, output_tensor, saver):
        folder_list = glob.glob(os.path.join(data_path, 'Set*'))
        print('folder_list', folder_list)
        saver.restore(self.sess, ckpt_path)
        psnr_dict = {}
        for folder_path in folder_list:
            psnr_list = []
            img_list = self.get_img_list(folder_path)
            print('img_list', img_list)
            for i in range(len(img_list)):
                input_list, gt_list, scale_list = self.get_test_image(
                    img_list, i, 1)

                print(len(input_list))
                input_y = input_list[0]
                gt_y = gt_list[0]

                start_t = time.time()
                img_vdsr_y = self.sess.run(
                    [output_tensor],
                    feed_dict={
                        self.input_tensor:
                        np.resize(input_y,
                                  (1, input_y.shape[0], input_y.shape[1], 1))
                    })
                img_vdsr_y = np.resize(img_vdsr_y,
                                       (input_y.shape[0], input_y.shape[1]))
                end_t = time.time()
                print("end_t", end_t, "start_t", start_t)
                print("time consumption", end_t - start_t)
                print("image_Size", input_y.shape)
                psnr_bicub = psnr(input_y, gt_y, scale_list[0])
                psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
                print("bicubic PSNR: %f \t VDSR PSNR: %f" %
                      (psnr_bicub, psnr_vdsr))
                psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])

            psnr_dict[os.path.basename(folder_path)] = psnr_list
        print("psnr_dict:", psnr_dict)
        with open('./psnr\%s' % os.path.basename(ckpt_path), 'wb') as f:
            pickle.dump(psnr_dict, f)
Пример #8
0
def test_VDSR_with_sess(epoch, ckpt_path, data_path, sess):
    folder_list = glob.glob(os.path.join(data_path, 'Set*'))
    print 'folder_list', folder_list
    input_tensor = tf.placeholder(tf.float32, shape=(1, None, None, 1))
    output_tensor, weights = model(input_tensor)
    #output_tensor, weights 	= model_factorized(input_tensor)
    tf.get_variable_scope().reuse_variables()
    saver = tf.train.Saver(weights)
    tf.initialize_all_variables().run()
    saver.restore(sess, ckpt_path)

    psnr_dict = {}
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        for i in range(len(img_list)):
            input_list, gt_list, scale_list = get_test_image(img_list, i, 1)
            input_y = input_list[0]
            gt_y = gt_list[0]

            img_vdsr_y = sess.run(
                [output_tensor],
                feed_dict={
                    input_tensor:
                    np.resize(input_y,
                              (1, input_y.shape[0], input_y.shape[1], 1))
                })
            img_vdsr_y = np.resize(img_vdsr_y,
                                   (input_y.shape[0], input_y.shape[1]))

            psnr_bicub = psnr(input_y, gt_y, scale_list[0])
            psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
            print "PSNR: bicubic %f\tVDSR %f" % (psnr_bicub, psnr_vdsr)
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
    with open('psnr/%s' % os.path.basename(ckpt_path), 'wb') as f:
        pickle.dump(psnr_dict, f)
Пример #9
0
def test_with_sess(epoch, ckpt_path, data_path,sess):
	psnr_list = []
	for i in range(2):
		psnr_list.append([])
	for i in range(3):
		psnr_list[0].append([])
		psnr_list[1].append([])
	saver.restore(sess, ckpt_path)
	for i, item in enumerate(file_list):
		file_name = os.path.splitext(item)
		img_raw = imread(path_dir+item)
		width = img_raw.shape[1]
		height = img_raw.shape[0]
		if len(img_raw.shape) == 3:
			im_gt_ycbcr = np.round(rgb2ycbcr(img_raw)).astype('uint8')
			im_gt_ycbcr = cropping(im_gt_ycbcr,height,width)
			img_raw = im_gt_ycbcr[:,:,0]/255.0
			is_gray = False
		elif len(img_raw.shape) == 2:
			im_gt_ycbcr = 0
			img_raw = img_raw/255.0
			is_gray = True
		img_raw = cropping(img_raw, height, width).astype(np.float32)
		for x in range(2,5):#About scale X2, X3, X4
			im_gt_y = imresize(imresize(img_raw, 1/x, interp='bicubic', mode='F'), [img_raw.shape[0], img_raw.shape[1]], interp='bicubic', mode='F')
			result_y = sess.run([output_tensor], feed_dict={input_tensor: np.resize(im_gt_y, (1, im_gt_y.shape[0], im_gt_y.shape[1], 1)), keep_prob: 1.0})

			result_y = np.resize(result_y, (im_gt_y.shape[0], im_gt_y.shape[1]))
			result_y = result_y.clip(16/255, 235/255)
			image = colorize(result_y, im_gt_ycbcr, is_gray)
			image.save(result_path_dir+file_name[0]+"X"+str(x)+file_name[1])

			psnr_list[0][x - 2].append(psnr(result_y, img_raw, x))
			psnr_list[1][x - 2].append(psnr(im_gt_y, img_raw, x))
	print("OURS\nX2 : %f db \nX3 : %f db \nX4 : %f db \n" % (np.mean(psnr_list[0][0]), np.mean(psnr_list[0][1]), np.mean(psnr_list[0][2])))
	print("BICUBIC\nX2 : %f db \nX3 : %f db \nX4 : %f db \n" % (np.mean(psnr_list[1][0]), np.mean(psnr_list[1][1]), np.mean(psnr_list[1][2])))
Пример #10
0
                        learning_rate,
                        global_step,
                    ],
                                 feed_dict=feed_dict)

                    # del input_data, gt_data, cbcr_data

                print output.shape
                img = util.combine_img_prediction(input_data, gt_data,
                                                  output + input_data)
                name = 'epoch_%s' % epoch
                util.save_image(img, '%s/%s.jpg' % (prediction_path, name))
                print '[epoch %2.4f] loss %.4f\t acc %.4f\t lr %.7f' \
                    % (epoch + float(step) * BATCH_SIZE
                       / len(train_list), np.sum(l), accuracy, lr)
                psnr_bicub = psnr(input_data, gt_data, 0)
                psnr_vdsr = psnr(output + input_data, gt_data, 0)
                print 'PSNR: bicubic %f\U-NET %f' % (psnr_bicub, psnr_vdsr)

                # print "[epoch %2.4f] loss %.4f\t lr %.7f"%(epoch+(float(step)*BATCH_SIZE/len(train_list)), np.sum(l)/BATCH_SIZE, lr)

                # saver.save(sess, "./checkpoints/VDSR_const_clip_0.01_epoch_%03d.ckpt" % epoch ,global_step=global_step)

                saver.save(sess, ckpt_path)

                # test_VDSR(epoch, ckpt_path, TEST_DATA_PATH)

                img_list = get_train_list(TEST_DATA_PATH)

                # print img_list
Пример #11
0
def Show_burst2(Denoiser, SFD, loader, pause, framerate=0.1, check=False):
    Denoiser.eval()
    SFD.eval()

    with torch.no_grad():

        plt.ion()
        plt.show()

        #Calcul de la PSNR moyenne
        PSNRmoyLast = 0
        PSNRmoyFirst = 0
        PSNRmoyMSFDLast = 0
        PSNRmoyMSFDFirst = 0
        PSNRmoySFDLast = 0
        PSNRmoySFDFirst = 0

        Compteur = 0

        for t, (x, y) in enumerate(loader):

            x_var = Variable(torch.transpose(x.type(gpu_dtype), 0, 1),
                             requires_grad=False)
            y = torch.transpose(y, 0, 1)
            i = 0

            for frame, target in zip(x_var, y):
                if i == 0:

                    images = target[0]
                    plt.figure(1)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)
                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')

                    c, h, w = images.shape

                    images = frame.data[0].cpu()
                    print("Image bruitée 1")
                    plt.figure(2)
                    plt.clf()

                    images = np.clip(images.numpy(), 0, 1)
                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    A = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % A)

                    mfinit1, mfinit2, mfinit3, mfinit4, mfinit5, mfinit6, mfinit7 = torch.zeros(
                        7, loader.batch_size, 64, h, w,
                        requires_grad=False).cuda()
                    mfinit8 = torch.zeros(loader.batch_size,
                                          c,
                                          h,
                                          w,
                                          requires_grad=False).cuda()

                    i += 1
                    frame1, mf1, mf2, mf3, mf4, mf5, mf6, mf7, mf8 = Denoiser(
                        frame, mfinit1, mfinit2, mfinit3, mfinit4, mfinit5,
                        mfinit6, mfinit7, mfinit8)

                    frame = SFD(frame)

                    images = frame1.data[0].cpu()
                    print("Image 1 debruité MSFD")
                    plt.figure(3)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    A = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % A)

                    PSNRmoyMSFDFirst += A

                    images = frame.data[0].cpu()
                    print("Image 1 debruité MSFD")
                    plt.figure(4)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    A = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % A)

                    PSNRmoySFDFirst += A

                    images = mf8.data[0].cpu()
                    print("Image 1 debruité MFD")
                    plt.figure(5)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    A = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % A)

                    PSNRmoyFirst += A

                    torch.cuda.empty_cache()

                else:
                    i += 1
                    images = target[0]
                    plt.figure(6)
                    plt.clf()
                    images = np.clip(images, 0, 1)
                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')

                    images = frame.data[0].cpu()
                    print("Image %d bruitée" % i)
                    plt.figure(7)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    A = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % A)

                    frame1, mf1, mf2, mf3, mf4, mf5, mf6, mf7, mf8 = Denoiser(
                        frame, mf1, mf2, mf3, mf4, mf5, mf6, mf7, mf8)

                    frame = SFD(frame)

                    images = frame1.data[0].cpu()
                    print("Image %d debruitée MSFD" % i)
                    plt.figure(8)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    B = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % B)

                    images = frame.data[0].cpu()
                    print("Image %d debruité SFD" % i)
                    plt.figure(9)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    D = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % D)

                    images = mf8.data[0].cpu()
                    print("Image %d debruitée MFD " % i)
                    plt.figure(10)
                    plt.clf()
                    images = np.clip(images.numpy(), 0, 1)

                    plt.imshow(np.transpose(images, (1, 2, 0)))
                    plt.axis('off')
                    A = psnr(target[0].numpy(), images, check=check)
                    plt.title(r'%f ' % A)

                    torch.cuda.empty_cache()
                    plt.pause(framerate)

            PSNRmoyMSFDLast += B
            PSNRmoyLast += A
            PSNRmoySFDLast += D
            Compteur += 1
            plt.pause(pause)

        print(' Mean PSNR MFD First = %f ' % (PSNRmoyFirst / Compteur))
        print(' Mean PSNR MFD Last = %f ' % (PSNRmoyLast / Compteur))
        print(' Mean PSNR MSFD Last = %f ' % (PSNRmoyMSFDLast / Compteur))
        print(' Mean PSNR SFD First = %f ' % (PSNRmoyMSFDFirst / Compteur))
        print(' Mean PSNR SFD Last = %f ' % (PSNRmoySFDLast / Compteur))
        print(' Mean PSNR SFD First = %f ' % (PSNRmoySFDFirst / Compteur))
Пример #12
0
def Show_result2(Denoiser1, Denoiser2, loader, pause, check=False):
    Denoiser1.eval()
    Denoiser2.eval()

    plt.ion()
    plt.show()

    #Calcul de la PSNR moyenne
    PSNRmoy1 = 0
    PSNRmoy2 = 0
    Compteur = 0

    for i, data in enumerate(loader):
        images, groundtrue = data

        plt.figure(1)
        plt.clf()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(groundtrue, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        print("Image bruitée")
        plt.figure(2)
        plt.clf()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(images, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        A = psnr(groundtrue.numpy(), images.numpy(), check=check)
        plt.title(r'%f ' % A)

        print("Image débruitée par 1")
        plt.figure(3)
        plt.clf()
        images1 = Denoiser1(
            Variable(images, requires_grad=False).type(gpu_dtype)).data.cpu()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(images1, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        A = psnr(groundtrue.numpy(), images1.numpy(), check=check)
        PSNRmoy1 += A
        Compteur += 1
        plt.title(r' Denoiseur1 PSNR=%f ' % A)

        print("Image débruitée par 2")
        plt.figure(4)
        plt.clf()
        images2 = Denoiser2(
            Variable(images, requires_grad=False).type(gpu_dtype)).data.cpu()
        plt.imshow(
            np.clip(
                np.transpose(
                    tu.make_grid(images2, range=(0, 1), nrow=4).numpy(),
                    (1, 2, 0)), 0, 1))
        plt.axis('off')

        A = psnr(groundtrue.numpy(), images2.numpy())
        PSNRmoy2 += A
        plt.title(r' Denoiseur2 PSNR= %f ' % A)

        plt.pause(pause)

    print(' Mean PSNR denoiseur1 = %f ' % (PSNRmoy1 / Compteur))
    print(' Mean PSNR denoiseur2 = %f ' % (PSNRmoy2 / Compteur))
Пример #13
0
def test_VDSR_with_sess(epoch, ckpt_path, data_path, sess):
    folder_list = glob.glob(os.path.join(data_path, 'Set*'))  #'Set*'
    print('folder_list', folder_list)  #folder_list [./data/test//Set14]
    if not os.path.exists('./output_img'):
        os.mkdir('./output_img')
    saver.restore(sess, ckpt_path)

    psnr_dict = {}
    psnr_bicub_cnt_2 = 0
    psnr_bicub_sum_2 = 0
    psnr_bicub_total_2 = 0

    psnr_bicub_cnt_3 = 0
    psnr_bicub_sum_3 = 0
    psnr_bicub_total_3 = 0
    #
    psnr_bicub_cnt_4 = 0
    psnr_bicub_sum_4 = 0
    psnr_bicub_total_4 = 0

    psnr_vdsr_cnt_2 = 0
    psnr_vdsr_sum_2 = 0
    psnr_vdsr_total_2 = 0

    psnr_vdsr_cnt_3 = 0
    psnr_vdsr_sum_3 = 0
    psnr_vdsr_total_3 = 0

    psnr_vdsr_cnt_4 = 0
    psnr_vdsr_sum_4 = 0
    psnr_vdsr_total_4 = 0
    input_cnt = 0
    vdsr_cnt = 0
    gt_cnt = 0
    for folder_path in folder_list:
        psnr_list = []
        img_list = get_img_list(folder_path)
        for i in range(len(img_list)):
            input_list, gt_list, scale_list = get_test_image(img_list, i, 1)
            input_y = input_list[0]
            gt_y = gt_list[0]
            start_t = time.time()
            img_vdsr_y = sess.run(
                [output_tensor],
                feed_dict={
                    input_tensor:
                    np.resize(input_y,
                              (1, input_y.shape[0], input_y.shape[1], 1))
                })
            img_vdsr_y = np.resize(img_vdsr_y,
                                   (input_y.shape[0], input_y.shape[1]))
            end_t = time.time()

            print("end_t", end_t, "start_t", start_t)
            print("time consumption", end_t - start_t)
            print("image_size", input_y.shape)

            input_count = str(input_cnt)
            vdsr_count = str(vdsr_cnt)
            gt_count = str(gt_cnt)
            #save test image and results
            id = img_list[i][1].split('/')[-1].split('.')[0]
            #			output_id = 'output'+id+'.png'
            #			input_id = 'input' + id + '.png'

            filename = os.path.basename(
                model_ckpt.split('/')[-1].split('.')[0])
            #print('filename=', filename)
            #scipy.misc.imsave(os.path.join('./output_img', 'image.png'),img_vdsr_y)
            #scipy.misc.imsave('image.png',img_vdsr_y)

            #			scipy.misc.imsave(os.path.join('./output_img', filename+'_input'+input_count+'.png'),input_y)   #image 생성
            #			scipy.misc.imsave(os.path.join('./output_img', 'gt'+'_'+gt_count+'.png'),gt_y) #image 생성

            #			scipy.misc.imsave(os.path.join('./output_img',input_id),input_y)
            #			scipy.misc.imsave(os.path.join('/output_img',output_id),img_vdsr_y)

            if scale_list[0] == 2:
                psnr_bicub = psnr(input_y, gt_y, scale_list[0])
                psnr_bicub_cnt_2 += 1
                psnr_bicub_sum_2 += psnr_bicub
                psnr_bicub_total_2 = psnr_bicub_sum_2 / psnr_bicub_cnt_2
                psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
                psnr_vdsr_cnt_2 += 1
                psnr_vdsr_sum_2 += psnr_vdsr
                psnr_vdsr_total_2 = psnr_vdsr_sum_2 / psnr_vdsr_cnt_2
                scipy.misc.imsave(
                    os.path.join(
                        './output_img', filename + '_ground_truth' + '_x2' +
                        gt_count + '.png'), gt_y)
                scipy.misc.imsave(
                    os.path.join(
                        './output_img',
                        filename + '_outputx2' + '_' + vdsr_count + '.png'),
                    img_vdsr_y)
                scipy.misc.imsave(
                    os.path.join(
                        './output_img',
                        filename + '_bicubicx2' + '_' + input_count + '.png'),
                    input_y)
                #				print("%d 번째 Average PSNR x2 scale: bicubic %f\tVDSR %f" %(psnr_bicub_cnt_2,psnr_bicub_total_2, psnr_vdsr_total_2))
                print("PSNR x2 scale : bicubic %f\tVDSR %f" %
                      (psnr_bicub, psnr_vdsr))

            if scale_list[0] == 3:
                psnr_bicub = psnr(input_y, gt_y, scale_list[0])
                psnr_bicub_cnt_3 += 1
                psnr_bicub_sum_3 += psnr_bicub
                psnr_bicub_total_3 = psnr_bicub_sum_3 / psnr_bicub_cnt_3
                psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
                psnr_vdsr_cnt_3 += 1
                psnr_vdsr_sum_3 += psnr_vdsr
                psnr_vdsr_total_3 = psnr_vdsr_sum_3 / psnr_vdsr_cnt_3
                scipy.misc.imsave(
                    os.path.join('./output_img',
                                 'ground_truth' + '_x3' + gt_count + '.png'),
                    gt_y)
                scipy.misc.imsave(
                    os.path.join(
                        './output_img',
                        filename + '_outputx3' + '_' + vdsr_count + '.png'),
                    img_vdsr_y)
                scipy.misc.imsave(
                    os.path.join(
                        './output_img',
                        filename + '_bicubicx3' + '_' + input_count + '.png'),
                    input_y)
                #				print("%d 번째 Average PSNR x3 scale: bicubic %f\tVDSR %f" %(psnr_bicub_cnt_3,psnr_bicub_total_3, psnr_vdsr_total_3))
                print("PSNR x3 scale : bicubic %f\tVDSR %f" %
                      (psnr_bicub, psnr_vdsr))

            if scale_list[0] == 4:
                psnr_bicub = psnr(input_y, gt_y, scale_list[0])
                psnr_bicub_cnt_4 += 1
                psnr_bicub_sum_4 += psnr_bicub
                psnr_bicub_total_4 = psnr_bicub_sum_4 / psnr_bicub_cnt_4
                psnr_vdsr = psnr(img_vdsr_y, gt_y, scale_list[0])
                psnr_vdsr_cnt_4 += 1
                psnr_vdsr_sum_4 += psnr_vdsr
                psnr_vdsr_total_4 = psnr_vdsr_sum_4 / psnr_vdsr_cnt_4
                scipy.misc.imsave(
                    os.path.join('./output_img',
                                 'ground_truth' + '_x4' + gt_count + '.png'),
                    gt_y)
                scipy.misc.imsave(
                    os.path.join(
                        './output_img',
                        filename + '_outputx4' + '_' + vdsr_count + '.png'),
                    img_vdsr_y)
                scipy.misc.imsave(
                    os.path.join(
                        './output_img',
                        filename + '_bicubicx4' + '_' + input_count + '.png'),
                    input_y)
                #				print("%d 번째 Average PSNR x4 scale: bicubic %f\tVDSR %f" %(psnr_bicub_cnt_4, psnr_bicub_total_4, psnr_vdsr_total_4))
                print("PSNR x4 scale : bicubic %f\tVDSR %f" %
                      (psnr_bicub, psnr_vdsr))

            input_cnt += 1
            vdsr_cnt += 1
            gt_cnt += 1

            #			print ("PSNR: bicubic %f\tVDSR %f" % (psnr_bicub, psnr_vdsr)
            psnr_list.append([psnr_bicub, psnr_vdsr, scale_list[0]])
        psnr_dict[os.path.basename(folder_path)] = psnr_list
    if not os.path.exists('./psnr'):
        os.mkdir('psnr')
    with open('psnr/%s' % os.path.basename(ckpt_path), 'wb') as f:
        pickle.dump(psnr_dict, f)
Пример #14
0
def evaluate():
    ## create folders to save result images
    save_dir = "samples/{}".format(tl.global_flag['mode'])
    tl.files.exists_or_mkdir(save_dir)
    checkpoint_dir = "checkpoint"

    ###====================== PRE-LOAD DATA ===========================###

    valid_hr_img_list = glob.glob(os.path.join(config.VALID.hr_img_path, "*"))
    valid_hr_img_list = [
        f for f in valid_hr_img_list if os.path.splitext(f)[-1] == '.png'
    ]
    #valid_hr_imgs = tl.vis.read_images(valid_hr_img_list, path=config.VALID.hr_img_path, n_threads=32)
    valid_hr_imgs = []
    for f in valid_hr_img_list:
        #print(f)
        img = cv2.imread(f, cv2.IMREAD_UNCHANGED)
        #print(img[1:10,1:10,0])
        max_value = np.max(img)
        print('max_value:{}'.format(max_value))
        valid_hr_imgs.append(img)

    ###========================== DEFINE MODEL ============================###
    G = get_G([1, None, None, 3])
    #G.load_weights(checkpoint_dir + '/g_{}.h5'.format(tl.global_flag['mode']))
    G.load_weights(checkpoint_dir + '/g_{}.h5'.format('srgan'))
    G.eval()
    for imid in range(8):
        #imid =7

        valid_hr_img = valid_hr_imgs[imid]
        valid_hr_img = cv2.resize(valid_hr_img, (500, 218),
                                  interpolation=cv2.INTER_CUBIC)
        valid_lr_img = tf.floor(valid_hr_img / 4096.0)
        valid_lr_img = valid_lr_img * 4096.0

        valid_lr_img = (valid_lr_img / 32767.5) - 1  # rescale to [-1, 1]
        valid_lr_img = tf.cast(valid_lr_img, dtype=tf.float32)
        valid_lr_img_input = tf.reshape(valid_lr_img, [
            1, valid_lr_img.shape[0], valid_lr_img.shape[1],
            valid_lr_img.shape[2]
        ])
        # print(valid_lr_img.min(), valid_lr_img.max())
        #        print(valid_lr_img.shape)

        #        G = get_G([1, None, None, 3])
        #        #G.load_weights(checkpoint_dir + '/g_{}.h5'.format(tl.global_flag['mode']))
        #        G.load_weights(checkpoint_dir + '/g_{}.h5'.format('srgan'))
        #        G.eval()

        out = G(valid_lr_img_input).numpy()
        print(np.min(out), np.max(out))
        #        cv2.imshow('out',out[0])
        #        cv2.waitKey(0)

        #        print("[*] save images")
        #        tl.vis.save_image(out[0], save_dir + '/valid_gen_{}.png'.format(str(imid)))
        #        tl.vis.save_image(valid_lr_img, save_dir + '/valid_lr_{}.png'.format(str(imid)))
        #        tl.vis.save_image(valid_hr_img, save_dir + '/valid_hr_{}.png'.format(str(imid)))
        '''do not use tl.vis.save_image,for which do not support 16bit mode'''
        out = tf.cast((out[0] + 1) * 32767.5, dtype=tf.uint16).numpy()
        #out=out.eval()
        valid_lr_img = tf.cast((valid_lr_img + 1) * 32767.5,
                               dtype=tf.uint16).numpy()
        valid_hr_img = tf.cast(valid_hr_img, dtype=tf.uint16).numpy()
        #        cv2.imshow('out',out)
        #        cv2.waitKey(0)
        #        print(np.max(out))
        #        print(np.min(out))
        psnr_gen = psnr(np.float32(out), np.float32(valid_hr_img), 2)
        psnr_zp = psnr(np.float32(valid_lr_img), np.float32(valid_hr_img), 2)
        print('psnr_gen:{}   psnr_zp:{}'.format(psnr_gen, psnr_zp))
        cv2.imwrite(save_dir + '/valid_gen_{}.png'.format(str(imid)), out,
                    [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
        cv2.imwrite(save_dir + '/valid_lr_{}.png'.format(str(imid)),
                    valid_lr_img, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
        cv2.imwrite(save_dir + '/valid_hr_{}.png'.format(str(imid)),
                    valid_hr_img, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
Пример #15
0
            avg_psnr_predicted = 0.0
            avg_psnr_bicubic = 0.0
            avg_elapsed_time = 0.0
            count = 0.0
            for image_name in image_list:
                # print("image name: ", image_name)
                if str(scale) in image_name:
                    print("Processing ", image_name)
                    # keys: 'im_gt_y', 'im_b_y', 'im_gt', 'im_b', 'im_l_ycbcr', 'im_l_y', 'im_l'
                    im_gt_y = sio.loadmat(image_name)['im_gt_y']
                    im_b_y = sio.loadmat(image_name)['im_b_y']

                    im_gt_y = im_gt_y.astype(float) / 255.
                    im_b_y = im_b_y.astype(float) / 255.

                    psnr_bicubic = psnr(im_gt_y, im_b_y, scale)
                    avg_psnr_bicubic += psnr_bicubic

                    input_array = np.resize(
                        im_b_y, (1, im_b_y.shape[0], im_b_y.shape[1], 1))
                    start_t = time.time()
                    img_vdsr = sess.run(train_output,
                                        feed_dict={train_input: input_array})
                    end_t = time.time()
                    img_vdsr = np.resize(img_vdsr,
                                         (im_b_y.shape[0], im_b_y.shape[1]))

                    elapsed_time = end_t - start_t
                    avg_elapsed_time += elapsed_time

                    psnr_predicted = psnr(im_gt_y, img_vdsr, scale)