anishathalye / neural-style

Neural style in TensorFlow! 🎨
https://anishathalye.com/an-ai-that-can-mimic-any-artist/
GNU General Public License v3.0
5.54k stars 1.52k forks source link

Why I got strange results? #155

Closed david658 closed 4 years ago

david658 commented 4 years ago

Dear friends,

Recently I have tested the program on my notebook but got strange results. The output file contains just random distributed dots, neither content nor style appear as in the input files. After installing Pillow, Scipy 1.1.0 and tensorflow 1.14.0 (not tensorflow-gpu), and checking

import PIL PIL.version '6.2.0' import scipy scipy.version '1.1.0' import numpy numpy.version '1.16.5' import tensorflow as tf tf.version '1.14.0'

Then I ran the following command in anaconda prompt: python neuralstyle.py --content ./content/1-content.jpg --styles ./style/1-style.jpg --output ./output/output.jpg --checkpoint-output ./output/test%d.jpg --checkpoint-iterations 100 --overwrite. The program goes through with no fatal errors, but the output image seems to be not right. test_1000

Could anyone please kindly tell me what is wrong with my practice?

Many thanks,

David

anishathalye commented 4 years ago

It's hard to debug this sort of thing.

Could you try running the following, which uses the example inputs:

python neural_style.py --content examples/1-content.jpg --styles examples/1-style.jpg --output new.png --iterations 1000 --overwrite
david658 commented 4 years ago

Thank you for your prompt reply. I 'm trying your command and will upload the new results after 6 hour running on my laptop. By the way, I have no GPU installed on my laptop, so I install tensorflow 1.14.0, rather than tensorflow-gpu 1.14.0. Can this cause problem?

anishathalye commented 4 years ago

No that shouldn’t cause problems

On Oct 10, 2019, at 5:42 PM, david658 notifications@github.com wrote:

Thank you for your prompt reply. I 'm trying your command and will upload the new results after 6 hour running on my laptop. By the way, I have no GPU installed on my laptop, so I install tensorflow 1.14.0, rather than tensorflow-gpu 1.14.0. Can this cause problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

david658 commented 4 years ago

I have run with your command, and got some error

content loss: 2.15407e+06 style loss: 5.86155e+07 tv loss: nan total loss: nan C:\CV\NST_MIT\stylize.py:202: RuntimeWarning: invalid value encountered in less if this_loss < best_loss: Traceback (most recent call last): File "neural_style.py", line 289, in main() File "neural_style.py", line 236, in main checkpoint_iterations=options.checkpoint_iterations, File "C:\CV\NST_MIT\stylize.py", line 206, in stylize img_out = vgg.unprocess(best.reshape(shape[1:]), vgg_mean_pixel) AttributeError: 'NoneType' object has no attribute 'reshape'

The output new.png is empty new

My system is Anaconda 3 (Python3.7.3) on Windows 8.1.

anishathalye commented 4 years ago

The nan losses look suspicious. I'm not sure why you're getting those. Are you using the latest version of the code?

I get the following output:

content loss: 760838
  style loss: 257111
     tv loss: 54628.2
  total loss: 1.07258e+06

And it produces the following:

new

david658 commented 4 years ago

Yes, I downloaded your programs two weeks ago, so they should be the latest version. The MD5 number of the vgg I used is 8ee3263992981a1d26e73b3ca028a123. Is this version ok to run your program?

anishathalye commented 4 years ago

Oh maybe that's the issue? I don't remember which old versions work, but the current recommended version has MD5 hash 106118b7cf60435e6d8e04f6a6dc3657 (see https://github.com/anishathalye/neural-style#data-files).

david658 commented 4 years ago

Thank you for your help and advice. I have updated VGG 19, but still can not get right results. Then I downgraded Python from 3.7 to 3.5, and Tensorflow from 1.14 to 1.9. It finally worked! Now the output image looks new Thanks again for your kind help.

anishathalye commented 4 years ago

Oh that's interesting… Glad you got it working!

I will leave this issue open till I can test with those specific TF versions to see if there's an incompatibility. Thanks for the detailed error reports.

anishathalye commented 4 years ago

I tried it on my own machine with TensorFlow 1.14, and it seems to work. Not sure why it didn't on your machine.