Exemplo n.º 1
0
def test_only(args, model, sess, saver):

    saver.restore(sess, args.pre_trained_model)
    graph = sess.graph
    print("saved model is loaded for test only!")
    print("model path is %s" % args.pre_trained_model)

    inp_img_name = sorted(os.listdir(args.test_inp_path))

    input_imgs = util.image_loader_new(args.test_inp_path,
                                       args.test_focus_path, args.load_X,
                                       args.load_Y)

    for i, ele in enumerate(input_imgs):
        inp = np.expand_dims(ele, axis=0)

        if args.chop_forward:
            output = util.recursive_forwarding(inp, args.chop_size, sess,
                                               model, args.chop_shave)
            output = Image.fromarray(output[0])

        else:
            output = sess.run(model.output, feed_dict={model.inp: inp})
            output = Image.fromarray(output[0])

        split_name = inp_img_name[i].split('.')
        output.save(
            os.path.join(
                args.result_path,
                '%s_radiance.png' % (''.join(map(str, split_name[:-1])))))
Exemplo n.º 2
0
def test_only(args, model, sess, saver):
    
    saver.restore(sess,args.pre_trained_model)
    print("saved model is loaded for test only!")
    print("model path is %s"%args.pre_trained_model)
    
    blur_img_name = sorted(os.listdir(args.test_Blur_path))

    if args.in_memory :
        
        blur_imgs = util.image_loader(args.test_Blur_path, args.load_X, args.load_Y, is_train = False)
        
        for i, ele in enumerate(blur_imgs):
            blur = np.expand_dims(ele, axis = 0)
            
            if args.chop_forward:
                output = util.recursive_forwarding(blur, args.chop_size, sess, model, args.chop_shave)
                output = Image.fromarray(output[0])
            
            else:
                output = sess.run(model.output, feed_dict = {model.blur : blur})
                output = Image.fromarray(output[0])
            
            split_name = blur_img_name[i].split('.')
            output.save(os.path.join(args.result_path, '%s_sharp.png'%(''.join(map(str, split_name[:-1])))))

    else:
        
        sess.run(model.data_loader.init_op['te_init'])

        for i in range(len(blur_img_name)):
            output = sess.run(model.output)
            output = Image.fromarray(output[0])
            split_name = blur_img_name[i].split('.')
            output.save(os.path.join(args.result_path, '%s_sharp.png'%(''.join(map(str, split_name[:-1])))))    
Exemplo n.º 3
0
def test_only(args, model, sess):

    loader = tf.train.Saver(max_to_keep=None)
    loader.restore(sess, args.pre_trained_model)

    print("saved model is loaded for test only!")
    print("model path is %s" % args.pre_trained_model)

    val_LR = sorted(os.listdir(args.test_LR_path))
    val_LR_imgs = util.image_loader(args.test_LR_path)

    if args.in_memory:

        for i, img_LR in enumerate(val_LR_imgs):

            batch_img_LR = np.expand_dims(img_LR, axis=0)

            if args.self_ensemble:
                output = util.self_ensemble(args,
                                            model,
                                            sess,
                                            batch_img_LR,
                                            is_recursive=args.chop_forward)

            else:
                if args.chop_forward:
                    output = util.recursive_forwarding(batch_img_LR,
                                                       args.scale,
                                                       args.chop_size, sess,
                                                       model, args.chop_shave)
                    output = output[0]
                else:
                    output = sess.run(model.output,
                                      feed_dict={model.LR: batch_img_LR})
                    output = output[0]

            im = Image.fromarray(output)
            split_name = val_LR[i].split(".")
            im.save(
                os.path.join(
                    args.result_path,
                    "%sX%d.%s" % (''.join(map(
                        str, split_name[:-1])), args.scale, split_name[-1])))

    else:

        sess.run(model.data_loader.init_op['val_init'])

        for i in range(len(val_LR)):
            output = sess.run([model.output])
            output = output[0]

            im = Image.fromarray(output)
            split_name = val_LR[i].split(".")
            im.save(
                os.path.join(
                    args.result_path,
                    "%sX%d.%s" % (''.join(map(
                        str, split_name[:-1])), args.scale, split_name[-1])))
Exemplo n.º 4
0
def test(args, model, sess):

    loader = tf.train.Saver(max_to_keep=None)

    loader.restore(sess, args.pre_trained_model)
    print("saved model is loaded for test!")
    print("model path is %s" % args.pre_trained_model)

    val_LR = sorted(os.listdir(args.test_LR_path))
    val_HR = sorted(os.listdir(args.test_GT_path))

    val_LR_imgs = util.image_loader(args.test_LR_path)
    val_GT_imgs = util.image_loader(args.test_GT_path)

    Y_PSNR_list = []
    Y_SSIM_list = []

    file = open('./ARDN_X%d_%s_result.txt' % (args.scale, args.test_set), 'w')

    if args.in_memory:

        for i, img_LR in enumerate(val_LR_imgs):

            batch_img_LR = np.expand_dims(img_LR, axis=0)
            img_HR = val_GT_imgs[i]

            if args.self_ensemble:
                output = util.self_ensemble(args,
                                            model,
                                            sess,
                                            batch_img_LR,
                                            is_recursive=args.chop_forward)

            else:
                if args.chop_forward:
                    output = util.recursive_forwarding(batch_img_LR,
                                                       args.scale,
                                                       args.chop_size, sess,
                                                       model, args.chop_shave)
                    output = output[0]
                else:
                    output = sess.run(model.output,
                                      feed_dict={model.LR: batch_img_LR})
                    output = output[0]

            h, w, c = output.shape
            val_gt = img_HR[:h, :w]

            y_psnr, y_ssim = util.compare_measure(val_gt, output, args)

            Y_PSNR_list.append(y_psnr)
            Y_SSIM_list.append(y_ssim)
            file.write('file name : %s PSNR : %04f SSIM : %04f \n' %
                       (val_LR[i], y_psnr, y_ssim))

            if args.save_test_result:
                im = Image.fromarray(output)
                split_name = val_LR[i].split(".")
                im.save(
                    os.path.join(
                        args.result_path,
                        "%sX%d.%s" % (''.join(map(str, split_name[:-1])),
                                      args.scale, split_name[-1])))

    else:

        sess.run(model.data_loader.init_op['val_init'])

        for i in range(len(val_LR)):

            output, val_gt = sess.run([model.output, model.label])
            output = output[0]
            val_gt = val_gt[0]
            h, w, c = output.shape
            val_gt = val_gt[:h, :w]
            val_gt = val_gt.astype(np.uint8)

            y_psnr, y_ssim = util.compare_measure(val_gt, output, args)

            Y_PSNR_list.append(y_psnr)
            Y_SSIM_list.append(y_ssim)
            file.write('file name : %s PSNR : %04f SSIM : %04f \n' %
                       (val_LR[i], y_psnr, y_ssim))

            if args.save_test_result:
                im = Image.fromarray(output)
                split_name = val_LR[i].split(".")
                im.save(
                    os.path.join(
                        args.result_path,
                        "%sX%d.%s" % (''.join(map(str, split_name[:-1])),
                                      args.scale, split_name[-1])))

    length = len(val_LR)
    mean_Y_PSNR = sum(Y_PSNR_list) / length
    mean_SSIM = sum(Y_SSIM_list) / length

    file.write("Y_PSNR : %0.4f SSIM : %0.4f \n" % (mean_Y_PSNR, mean_SSIM))
    file.close()
    print('############Test completed!############')