dongheehand / DeblurGAN-tf

Tensorflow implementation of DeblurGAN(Blind Motion Deblurring Using Conditional Adversarial Networks)
80 stars 24 forks source link

[SOLVED] De-blur Image using Pre-Trained Model #15

Closed david-littlefield closed 4 years ago

david-littlefield commented 4 years ago

It wasn't clear to me what to do to deblur an image using the provided pre-trained model. I'm still fairly new to coding and computer vision. Here's what I had to do to make it work.

  1. Update the Tensorflow code for version one compatibility. That meant changing the code in all of the python files in the DeblurGAN-tf folder.

I updated whichever tf modules were stated as missing in the error messages.

From:

tf.placeholder

To:

tf.compat.v1.placeholder

I also added the following code in whichever file used tf.placeholder. I placed it at the top after the imports section. Apparently, the placeholder doesn't work with eager execution.

tf.compat.v1.disable_eager_execution()
  1. I added an empty result and model folder in the DeblurGAN-tf directory. The default settings are stated in the "main.py" file from line 20 to 28.

    • You can add folders named after the ones stated in the default settings.
    • You can change the default folder names in the "main.py" file.
    • You can include the path arguments in your command-line interface command. --train_Sharp_path, --train_Blur_path, --test_Sharp_path, --test_Blur_path, --vgg_path, --patch_size, --result_path, --model_path
  2. I extracted the pre-trained model files into the model folder. The command in the docs to extract the tar file didn't work. It ended up creating a new tar file. Instead, I double-clicked on the tar file to manually extract it. The And, I referenced the model file path in the command-line interface as ./model/DeblurrGAN_last without the extension.

  3. Mac OS: Stop the .DS_Store file from being loaded in the image folder. Add the following code to the image_loader function in theutil.py file in the DeblurGAN-tf folder.

FROM:

def image_loader(image_path, load_x, load_y, is_train = True):

    imgs = sorted(os.listdir(image_path))

    img_list = []
    for ele in imgs:
        img = Image.open(os.path.join(image_path, ele))
        if is_train:
            img = img.resize((load_x, load_y), Image.BICUBIC)
        img_list.append(np.array(img))

    return img_list

ADD:

for name in imgs:
    if name.endswith("DS_Store"):
        imgs.remove(name)

TO:

def image_loader(image_path, load_x, load_y, is_train = True):

    imgs = sorted(os.listdir(image_path))

    for name in imgs:
        print(name)
        if name.endswith("DS_Store"):
            imgs.remove(name)

    img_list = []
    for ele in imgs:
        img = Image.open(os.path.join(image_path, ele))
        if is_train:
            img = img.resize((load_x, load_y), Image.BICUBIC)
        img_list.append(np.array(img))

    return img_list