rrmina / fast-neural-style-pytorch

Fast Neural Style Transfer implementation in PyTorch :art: :art: :art:
317 stars 77 forks source link

Fixing the save/load generated images #4

Closed nlothian closed 4 years ago

nlothian commented 5 years ago

Hi,

Thanks for this project.

I don't completely understand why the whitening is happening on the generated image, but I don't think it is anything to do with the VideoCapture.

I don't have a real fix, but I think this is slightly better than writing and reading the file:

# old code
#utils.saveimg(generated_image, str(count+1) + ".png")
#img2 = cv2.imread(str(count+1) + ".png", cv2.IMREAD_UNCHANGED)

# don't really understand why this is required
img2 = cv2.imdecode(cv2.imencode(".png", generated_image)[1], cv2.IMREAD_UNCHANGED)
rrmina commented 5 years ago

Hi @nlothian ,

Thanks for raising this issue. I tested the code and it works! It's definitely more neat than the previous approach. Aside from the old codes you've listed above, line 44 and line 50 may also be removed. With that, can I ask you to submit a PR? :)

rrmina commented 4 years ago

Hi again @nlothian,

Apparently I found the cause of this problem. cv2.imshow() expects numpy arrays of values ranging from 0 to 1. The network outputs raw values of pixel (i.e. [0,255]).

So dividing the generated images by 255 would solve this problem!

nlothian commented 4 years ago

Oh that's great! Thanks for letting me know, too.