abhiskk / fast-neural-style

pytorch implementation of fast-neural-style
MIT License
425 stars 83 forks source link

How to set output_image_size when Eval #14

Closed dovanchan closed 7 years ago

dovanchan commented 7 years ago

Hi 1、Can you explain what's different of the image_size of "content and style" when Train and Eval? 2、How to set output_image_size when Eval? (if your default setting is 1080,can you show me where you set in your code?) 3、Really thanks for your work

abhiskk commented 7 years ago
  1. The --image-size --style-size determine the image sizes of content image and style image. They will resize the input images to the value in --image-size and --style-size parameters.
  2. The output image size will be same as the input image size by default, if you are feeding in a really large image then I have added a command line parameter here , using which you can reduce the size of the output styled image, for eg setting --content-scale will produce an output image which is half the size of the input image.
  3. 😃
dovanchan commented 7 years ago

If I wanna use it to make a ios app like prisma in production enviroment,Can you give me some advices for reducing memory usage.I found pytorch's implement is better than tensorflow in fast-neural-style

abhiskk commented 7 years ago

I would suggest looking into using Caffe2 for that. You should be able to load the pytorch model in Caffe2 directly, you will have to convert weights to numpy and then load it in Caffe2. Then I think you can follow this tutorial to build an app for that.

dovanchan commented 7 years ago

When I try eval,I get a error(python2.7)

Dovan-Rmbp:fast-neural-style DOVAN$ time python neural_style/neural_style.py eval --content-image /Users/DOVAN/Desktop/WX20170621-141545@2x.png --model /Users/DOVAN/deeprely/fast-neural-style/saved-models/udnie.pth --output-image /Users/DOVAN/Desktop/ --cuda 0 Traceback (most recent call last): File "neural_style/neural_style.py", line 210, in main() File "neural_style/neural_style.py", line 206, in main stylize(args) File "neural_style/neural_style.py", line 135, in stylize content_image = Variable(utils.preprocess_batch(content_image), volatile=True) File "/Users/DOVAN/deeprely/fast-neural-style/neural_style/utils.py", line 59, in preprocess_batch (r, g, b) = torch.chunk(batch, 3) ValueError: need more than 2 values to unpack

Can you tell me how to fix it

abhiskk commented 7 years ago

I just tested the implementation again on python 2.7 and it works. Can you try and install pytorch again in a clean environment using conda following the instructions from the pytorch site.

abhiskk commented 7 years ago

Actually I think it's an issue with loading .png images, I think it will work well for .jpg images. Similar issue was reported on the pytorch/examples version of this repo. ref: https://github.com/pytorch/examples/issues/171

dovanchan commented 7 years ago

@abhiskk Hi,I have tried the jpg. But I still get this error:

Dovan-Rmbp:fast-neural-style DOVAN$ time python neural_style/neural_style.py eval --content-image /Users/DOVAN/Desktop/WX20170621-141545@2x.jpg --model /Users/DOVAN/deeprely/fast-neural-style/saved-models/udnie.pth --output-image /Users/DOVAN/Desktop/ --cuda 0 Traceback (most recent call last): File "neural_style/neural_style.py", line 210, in main() File "neural_style/neural_style.py", line 206, in main stylize(args) File "neural_style/neural_style.py", line 135, in stylize content_image = Variable(utils.preprocess_batch(content_image), volatile=True) File "/Users/DOVAN/deeprely/fast-neural-style/neural_style/utils.py", line 59, in preprocess_batch (r, g, b) = torch.chunk(batch, 3) ValueError: need more than 2 values to unpack

I think this may be come from the Function parameters' error

abhiskk commented 7 years ago

@dovanchan what environment are you running this on, I just tested this implementation on python 2.7, on OSX and everything works well.

dovanchan commented 7 years ago

python2.7 on OSX 0.12.5 The same as you~

dovanchan commented 7 years ago

I am also used conda install pytorch ~

abhiskk commented 7 years ago

Are you sure you didn't edit anything, can you try re-cloning the repository and running it again, it should be working. Another option is to try it in python 3, if it fails in that also then something weird is happening. Also are you using --cuda 1 while running the stylizing code, pytorch's GPU version on OSX can misbehave. Try running with --cuda 0.

dovanchan commented 7 years ago

image

This is my enviroment,I dont have change any setting,the same as you(python2.7 --cuda 0 ) I think may be because I am using the latest pytorch version?

abhiskk commented 7 years ago

yes that could be an issue, don't use the master version of pytorch right now, it's unstable I think because they are implementing numpy type indexing. Are you using this command to install pytorch: conda install pytorch torchvision -c soumith ?

dovanchan commented 7 years ago

Yes,I am using conda install pytorch torchvision -c soumith ~

abhiskk commented 7 years ago

Please follow the following steps accurately, use the default image in the repository for stylizing. I just followed the steps listed below one by one and was able to run it successfully.

dovanchan commented 7 years ago

I found the real problem now, When I run the step that you offer,It will be successful; But when I try a new content image,I got the error:

(fnstest) Dovan-Rmbp:fast-neural-style DOVAN$ time python neural_style/neural_style.py eval --content-image images/content-images/image1.jpg --model saved-models/mosaic.pth --output-image stylized_amber.jpg --cuda 0
Traceback (most recent call last):
  File "neural_style/neural_style.py", line 210, in <module>
    main()
  File "neural_style/neural_style.py", line 206, in main
    stylize(args)
  File "neural_style/neural_style.py", line 135, in stylize
    content_image = Variable(utils.preprocess_batch(content_image), volatile=True)
  File "/Users/DOVAN/fast-neural-style/neural_style/utils.py", line 59, in preprocess_batch
    (r, g, b) = torch.chunk(batch, 3)
ValueError: need more than 2 values to unpack

Here is the image I used: image1

abhiskk commented 7 years ago

The image that you shared is not in RGB format, you can convert it to RGB format using the following commands:

from PIL import Image
content_image = Image.open('/path/to/image')
content_rgb_image = content_image.convert('RGB')
content_rgb_image.save('/path/to/output/image')

Then you can run the neural style on the new image. I have also attached the udnie styled version of the image.

Apologies for the late reply. issue_14_udnie

abhiskk commented 7 years ago

Closing the issue, please comment if similar problems resurface.