titu1994 / Neural-Style-Transfer

Keras Implementation of Neural Style Transfer from the paper "A Neural Algorithm of Artistic Style" (http://arxiv.org/abs/1508.06576) in Keras 2.0+
Apache License 2.0
2.26k stars 481 forks source link

usage of maintain aspect ratio #23

Closed 7yl4r closed 7 years ago

7yl4r commented 7 years ago

I may be doing something wrong here, but I also see the latest commit mentions a change to maintain_aspect_ratio. Using the latest build all images are coming out square. I've tried passing --maintain_aspect_ratio 1 as well, but no luck.

If someone can confirm it isn't just me being dumb, this line in the last commit may be the culprit.

titu1994 commented 7 years ago

@7yl4r The last commit did change the behaviour of the maintain_aspect_ratio parameter, but I made it so that the image that is generated at the end of the script will always maintain the aspect ratio of the original content image. The parameter now acts as a flag to load a 400x640 image (if set to 1) or else a 400x400 image as the content and style image (assuming that image_size = 400)

The replacement of if maintain_aspect_ratio and (not rescale_image) with if not rescale_image basically means that if you aren't going to upscale the image to the original dimensions (say 1080p using bicubic upsampling), then at least maintain the aspect ratio (say 400x640)

Simply put, as long as you aren't providing a square image and aren't upscaling to full size of the original image, it should maintain the aspect ratio in the generated image. Can you provide me with some sample content images on which I can test this?

7yl4r commented 7 years ago

Here is what I get from the first iteration of

python INetwork.py --image_size 200 ./images/inputs/content/tubingen.jpg ./images/inputs/style/starry_night.jpg ./test

test_at_iteration_1

titu1994 commented 7 years ago

Can you see if there is a line such as "Rescaling Image to (400, 640)" after each iteration ?

titu1994 commented 7 years ago

Try with the argument : --rescale_image "False"

7yl4r commented 7 years ago

It says rescaling to 200x200

On Wed, Nov 30, 2016, 9:12 PM Somshubra Majumdar notifications@github.com wrote:

Try with the argument : --rescale_image "False"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/titu1994/Neural-Style-Transfer/issues/23#issuecomment-264058699, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAK_r75EHuoZWvHRl8iN-EooP_CSr8Xks5rDi0IgaJpZM4LA5eU .

titu1994 commented 7 years ago

Can you copy paste the Network.py and INetwork.py code from the repo into your local copies and run it again? Because this is the results I am getting :

"D:/Users/Yue/PycharmProjects/Neural Style Transfer/INetwork.py" D:\Yue\Pictures\hoovertowernight.jpg D:\Yue\Pictures\Art\starry_night.jpg "D:\Yue\Desktop\Neural Art\test" --image_size 200

Model loaded.
Starting iteration 1 of 10
Current loss value: 135229216.0  Improvement : 0.000 %
Rescaling Image to (200, 380)
Image saved as D:\Yue\Desktop\Neural Art\test_at_iteration_1.png

test_at_iteration_1

7yl4r commented 7 years ago

I have cloned the repo through git, and git status shows no changes from master. Adding --rescale_image "False" didn't have an effect.

titu1994 commented 7 years ago

Well that is weird. The same code having different results ? What is your python version? 2.7 ?

There shouldn't be any difference in calculating the aspect ratio between python 3 and 2 though

7yl4r commented 7 years ago

Python version 2.7.12. I'm going to add some print statements and see if I can find what is going on and I'll get back to you.

titu1994 commented 7 years ago

Yes thanks for that. Also, try adding the original line if maintain_aspect_ratio and (not rescale_image) to see if it makes any difference.

7yl4r commented 7 years ago

I believe I've identified the issue and suggested a fix. aspect_ratio was being calculated using integer math, so I've suggested a cast to force floating point computation. I'm guessing the difference has to do with how command line vars are evaluated on windows vs linux.

titu1994 commented 7 years ago

Oh ! Nice catch. If you wish to be credited for the fix, could you create a pull request ?

titu1994 commented 7 years ago

Thanks for the fix !