基于keras的DeblurGAN实现运动图像的去模糊化---复现


环境:Keras                  2.1.6

         tensorflow-gpu   1.8.0

         python                3.6


github链接:https://github.com/RaphaelMeudec/deblur-gan

 

基于keras的DeblurGAN实现运动图像的去模糊化---复现_第1张图片数据集百度云链接:链接:https://pan.baidu.com/s/1V3lm5Bt0vJXNXOk7eSJwAQ    提取码:4g3t

 


个人的目录树:

基于keras的DeblurGAN实现运动图像的去模糊化---复现_第2张图片

测试代码: 

import numpy as np
from PIL import Image
import click
import cv2

from deblurgan.model import generator_model
from deblurgan.utils import load_images, deprocess_image
import tensorflow as tf
from keras import backend as K
config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)
K.set_session(sess)



def test(batch_size):
    data = load_images('./images/test', batch_size)
    y_test, x_test = data['B'], data['A']
    g = generator_model()
    g.load_weights('generator.h5')
    generated_images = g.predict(x=x_test, batch_size=batch_size)
    generated = np.array([deprocess_image(img) for img in generated_images])
    x_test = deprocess_image(x_test)
    
    y_test = deprocess_image(y_test)
  
    for i in range(generated_images.shape[0]):
        y = y_test[i, :, :, :]
        x = x_test[i, :, :, :]
        img = generated[i, :, :, :]
        cv2.imshow("img",y)
        cv2.imshow("blur",x)
        cv2.imshow("deblur",img)
        output = np.concatenate((y, x, img), axis=1)
        im = Image.fromarray(output.astype(np.uint8))
        im.save('results{}.png'.format(i))
    cv2.waitKey(100)

@click.command()
@click.option('--batch_size', default=1, help='Number of images to process')
def test_command(batch_size):
    return test(batch_size)


if __name__ == "__main__":
    test_command()

测试:

 

你可能感兴趣的:(gan)