soumik12345 / MIRNet

Tensorflow implementation of MIRNet for Low-light image enhancement
https://huggingface.co/spaces/keras-io/Enhance_Low_Light_Image
Apache License 2.0
113 stars 37 forks source link

mirnet.inference.Inferer gives error #2

Closed hboen closed 3 years ago

hboen commented 3 years ago

I have watch the youtube video https://www.youtube.com/watch?v=b5Uz_c0JLMs from Bhavesh Bhatt and copy the notebook. I only used my own picture (see attachment)

The code

from glob import glob
import tensorflow as tf
import numpy as np
from matplotlib import pyplot as plt
from mirnet.inference import Inferer
from mirnet.utils import download_dataset, plot_result
from PIL import Image

inferer = Inferer()
inferer.download_weights('1sUlRD5MTRKKGxtqyYDpTv7T3jOW6aVAL')
inferer.build_model(
    num_rrg=3, num_mrb=2, channels=64,
    weights_path='low_light_weights_best.h5'
)

#inferer.model.summary()

inferer.model.save('mirnet')

IMAGE_LOC = 'IMG_3598_resize3.jpg'

print("image converteren..")
original_image, output_image = inferer.infer(IMAGE_LOC)
plot_result(original_image, output_image)

But i get an error on the code -> original_image, output_image = inferer.infer(IMAGE_LOC) I used a jpeg file of 22.8 KB with width=600 and height=337 pixels and I get the following error:

InvalidArgumentError Traceback (most recent call last)

in () ----> 1 original_image, output_image = inferer.infer(IMAGE_LOC) 2 plot_result(original_image, output_image) 7 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 58 ctx.ensure_initialized() 59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, ---> 60 inputs, attrs, num_outputs) 61 except core._NotOkStatusException as e: 62 if name is not None: InvalidArgumentError: Incompatible shapes: [1,337,600,64] vs. [1,336,600,64] [[node model_1/add_180/add (defined at /content/MIRNet/mirnet/inference.py:39) ]] [Op:__inference_predict_function_126722] Function call stack: predict_function ![IMG_3598_resize3](https://user-images.githubusercontent.com/77464641/104652896-10299b00-56ba-11eb-8ef8-5f89825b1724.jpg) I have also try with different sizes but I get similar errors. I used google colab Any idea why it is not working.. Thanks sofar. Henk
soumik12345 commented 3 years ago

Hi @hboen , I investigated your issue and it seems like MIRNet has some tensor calculation issues when the image dimensions are not multiples of 4. You can either manually change the shape of the image to width=600 and height=336, or you can use the image_resize_factor parameter in Inferer.infer to resize your image. Hope that helps :)

hboen commented 3 years ago

Hi Soumik,

Thanks for having time for looking at my problem. I just tried and it works! Great algorithm.