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.28k stars 482 forks source link

Issues with scipy/pil [Win10] #8

Closed matthewbahr closed 8 years ago

matthewbahr commented 8 years ago

Followed the installation guide to a T on windows and entered the following command:

\Neural-Style-Transfer-master>python inetwork.py "A:\Dev\Deepdream\images\B.jpg" "A:\Dev\Deepdream\images\A.jpg" "A:\Dev\Deepdream\images\C.jpg" --image_size 600 --content_weight 0.025 --style_weight 1 --total_variation_weight 0.0001 --style_scale 1 --num_iter 20 --rescale_image "False" --rescale_method "bilinear" --maintain_aspect_ratio "True" --content_layer "conv5_2" --init_image "content" --pool_type "max" --preserve_color "False" --min_improvement 0

I got back an execution error:

Traceback (most recent call last):
  File "inetwork.py", line 1, in <module>
    from scipy.misc import imread, imresize, imsave, fromimage, toimage
ImportError: cannot import name 'imread'

After doing some research I found out that scipy relies on PIL but doesn't actually come with it in the download recommended. SO I tried >pip install pil but that resulted in a "No distribution found for pil". Frustrated I found out that pillow is a replacement for PIL that should work. So... >pip install pillow. I then executed the same command as before and got 1065 lines of raw code put onto my screen along with the following error message:

Problem occurred during compilation with the command line below:
A:\Dev\TDM-GCC-64\bin\g++.exe -shared -g -march=haswell -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -maes -mno-sha -mpclmul -mpopcnt -mabm -mno-lwp -mfma -mno-fma4 -mno-xop -mbmi -mbmi2 -mno-tbm -mavx -mavx2 -msse4.2 -msse4.1 -mlzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-clwb -mno-pcommit --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=haswell -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -IA:\Dev\Miniconda\lib\site-packages\numpy\core\include -IA:\Dev\Miniconda\include -IA:\Dev\Miniconda\lib\site-packages\theano\gof -o C:\Users\MBahr\AppData\Local\Theano\compiledir_Windows-10-10.0.14393-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.4.5-64\lazylinker_ext\lazylinker_ext.pyd C:\Users\MBahr\AppData\Local\Theano\compiledir_Windows-10-10.0.14393-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.4.5-64\lazylinker_ext\mod.cpp -LA:\Dev\Miniconda\libs -LA:\Dev\Miniconda -lpython34
A:\Dev\Miniconda\libs/python34.lib: error adding symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status

Traceback (most recent call last):
  File "A:\Dev\Miniconda\lib\site-packages\theano\gof\lazylinker_c.py", line 74, in <module>
    raise ImportError()
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "A:\Dev\Miniconda\lib\site-packages\theano\gof\lazylinker_c.py", line 91, in <module>
    raise ImportError()
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "inetwork.py", line 7, in <module>
    from keras.models import Sequential
  File "A:\Dev\Miniconda\lib\site-packages\keras\__init__.py", line 2, in <module>
    from . import backend
  File "A:\Dev\Miniconda\lib\site-packages\keras\backend\__init__.py", line 61, in <module>
    from .theano_backend import *
  File "A:\Dev\Miniconda\lib\site-packages\keras\backend\theano_backend.py", line 1, in <module>
    import theano
  File "A:\Dev\Miniconda\lib\site-packages\theano\__init__.py", line 63, in <module>
    from theano.compile import (
  File "A:\Dev\Miniconda\lib\site-packages\theano\compile\__init__.py", line 9, in <module>
    from theano.compile.function_module import *
  File "A:\Dev\Miniconda\lib\site-packages\theano\compile\function_module.py", line 22, in <module>
    import theano.compile.mode
  File "A:\Dev\Miniconda\lib\site-packages\theano\compile\mode.py", line 12, in <module>
    import theano.gof.vm
  File "A:\Dev\Miniconda\lib\site-packages\theano\gof\vm.py", line 638, in <module>
    from . import lazylinker_c
  File "A:\Dev\Miniconda\lib\site-packages\theano\gof\lazylinker_c.py", line 126, in <module>
    preargs=args)
  File "A:\Dev\Miniconda\lib\site-packages\theano\gof\cmodule.py", line 2204, in compile_str
    (status, compile_stderr.replace('\n', '. ')))
. collect2.exe: error: ld returned 1 exit status A:\Dev\Miniconda\libs/python34.lib: error adding symbols: File in wrong format

No clue what I did here. I'm doing the miniconda forced downgrade to Python 3.4 because Anaconda 2.2 was crashing whenever I tried to do upgrade --all. The python version is Python 3.4.5. Here's what pip list returns:

conda (4.1.12)
conda-env (2.5.0a0)
Keras (1.0.8)
menuinst (1.4.1)
numpy (1.11.1+mkl)
Pillow (3.3.1)
pip (8.1.2)
pycosat (0.6.1)
pycrypto (2.6.1)
PyYAML (3.11)
requests (2.11.1)
ruamel-yaml (-VERSION)
scipy (0.18.0)
setuptools (26.1.1)
six (1.10.0)
statsmodels (0.6.1)
Theano (0.8.2)
wheel (0.29.0)

It looks like I have the packages you'd listed installed but I'm getting nowhere with my bumbling about. Any suggestions?

Anotherun commented 8 years ago

Hi Mathew,

Unfortunately I'm not very knowledgeable about most of the installation process, however, I did successfully install the project following the guide on my windows 10 machine. I saw the PIL dependency listed for scipy, but as it was not mentioned in the guide at all I chose to not install it, believing it must not be needed for the project.

I did have a hiccup in my install with Anaconda, so I forced a downgrade to 3.4.4 and then updated all packages as outlined in the guide. This is all I needed to do after following the guide through once, and while I don't think it directly addresses your problem, it does show that the instructions will work with windows 10.

Looking at my pip list, the only difference I see in my packages is in the statsmodels: I have statsmodels (0.8.0rc1). I'll list my full pip list at the end, I've only used pip and Anaconda for this project and I have a lot more packages installed, perhaps a step was missed.

Here is another project for style transfer: https://github.com/jcjohnson/neural-style/blob/master/README.md

It is older, but I believe relatively simple to install and use. I used to dual boot into linux for style transfer, but I was happy to find that the project works perfectly on windows 10 through bash on windows. The one down side is that the gpu acceleration is not supported by bash on windows, but it should give you an alternative if you become too frustrated with trying to install this project. The up side is that the cpu mode allows for higher resolution style transfers for when you want a high quality output and don't mind the compute time.

I regret that I don't know enough to help further, but I hope seeing at least one response quickly will hearten you and that my pip list might help you get the project up and running.

Here is my pip list:

alabaster (0.7.8)
anaconda-client (1.5.1)
argcomplete (1.0.0)
astropy (1.2.1)
Babel (2.3.3)
backports-abc (0.4)
bcolz (1.0.0)
beautifulsoup4 (4.3.2)
bitarray (0.8.1)
blaze (0.9.0)
bokeh (0.12.2)
boto (2.42.0)
certifi (2016.2.28)
cffi (1.7.0)
click (6.6)
clyent (1.2.2)
colorama (0.3.7)
comtypes (1.1.2)
conda (4.1.12)
conda-build (2.0.1)
conda-env (2.5.0a0)
configobj (5.0.6)
cryptography (1.5)
cycler (0.10.0)
Cython (0.24.1)
cytoolz (0.8.0)
datashape (0.5.2)
decorator (4.0.10)
docutils (0.12)
et-xmlfile (1.0.1)
fastcache (1.0.2)
filelock (2.0.6)
Flask (0.11.1)
greenlet (0.4.10)
h5py (2.6.0)
idna (2.1)
imagesize (0.7.1)
ipykernel (4.5.0)
ipython (5.1.0)
ipython-genutils (0.1.0)
itsdangerous (0.24)
jdcal (1.2)
jedi (0.9.0)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter-client (4.4.0)
jupyter-core (4.1.1)
Keras (1.0.8)
llvmlite (0.13.0)
lxml (3.6.4)
MarkupSafe (0.23)
matplotlib (1.5.1)
menuinst (1.4.1)
mistune (0.7.2)
mock (2.0.0)
mpmath (0.19)
multipledispatch (0.4.8)
nbconvert (4.2.0)
nbformat (4.1.0)
networkx (1.11)
nltk (3.2.1)
nose (1.3.7)
notebook (4.2.2)
numba (0.28.1)
numexpr (2.6.1)
numpy (1.11.1+mkl)
odo (0.5.0)
openpyxl (2.3.2)
pandas (0.18.1)
path.py (0.0.0)
patsy (0.4.1)
pbr (1.10.0)
pep8 (1.7.0)
pickleshare (0.7.3)
Pillow (3.3.1)
pip (8.1.2)
ply (3.9)
prompt-toolkit (1.0.3)
psutil (4.3.1)
py (1.4.31)
pyasn1 (0.1.9)
pycosat (0.6.1)
pycparser (2.14)
pycrypto (2.6.1)
pyflakes (1.3.0)
Pygments (2.1.3)
pyOpenSSL (16.0.0)
pyparsing (2.1.4)
pyreadline (2.1)
pytest (2.9.2)
python-dateutil (2.5.3)
pytz (2016.6.1)
pywin32 (220)
PyYAML (3.11)
pyzmq (15.4.0)
qtconsole (4.2.1)
requests (2.11.1)
rope-py3k (0.9.4.post1)
ruamel-yaml (-VERSION)
runipy (0.1.3)
scikit-image (0.12.3)
scikit-learn (0.17.1)
scipy (0.18.0)
setuptools (26.1.1)
simplegeneric (0.8.1)
six (1.10.0)
snowballstemmer (1.2.1)
sockjs-tornado (1.0.3)
sphinx (1.4.1)
sphinx-rtd-theme (0.1.9)
spyder (2.3.8)
SQLAlchemy (1.0.13)
statsmodels (0.8.0rc1)
sympy (1.0)
tables (3.2.2)
Theano (0.8.2)
toolz (0.8.0)
tornado (4.4.1)
traitlets (4.2.2)
ujson (1.35)
wcwidth (0.1.7)
Werkzeug (0.11.11)
wheel (0.29.0)
win-unicode-console (0.5)
xlrd (1.0.0)
XlsxWriter (0.9.2)
xlwings (0.9.2)
titu1994 commented 8 years ago

@matthewbahr Did you perform this step? : conda install mingw libpython I have seen this error once in awhile when this step is missed (especially the thousands of lines of raw code).

Just installing TDM-GCC is not usually sufficient for getting the compiler to work correctly.

@Anotherun I agree that setting up this project on Windows is akin to shooting oneself in the foot, repeatedly. On another note, this project can also be setup using bash on windows (and I argue that it's simpler than the jcjohnson project, since GPU support isn't needed therefore everything comes with anaconda itself and a single pip install of Keras)

This however is simply not recommended. It takes huge amounts of time to run either these scripts or jcjohnson's scripts on CPU. The main culprit is the forward and backward passes through the huge VGG network to get the best quality results.

The best way to get high resolution examples if by first creating small scale results, and then upscaling them using a super resolution algorithm. See below (2732 x 2048). bryona gwidion uprgb noise_scale level3 x4 000000

The upscaled result is exactly the same as the smaller version computed by the script. (683 x 512) bryona gwidion_at_iteration_100

Upscaling was done through the caffe super resolution program which I linked to at the end of the readme.me (https://github.com/lltcggie/waifu2x-caffe/releases). With CUDA already set up for Theano, this can process a 2732 x 2048 image in less than 1 second from a given image of size 683 x 512.

Edit: Thanks for the tip about pil not being a direct dependency of scipy. Iv'e added pip install pillow after the conda install mingw libpython to address this.

matthewbahr commented 8 years ago

I was specifically looking for high quality large images to be done via CUDA accelerated GPU, which is why I went through the process of slowly gnawing off my own fingers also known as installing theano.

After getting this fixed (great call on the mingw @titu1994) I had to get h5py as well which then automatically installed numpy. Pip didn't work on the h5py but conda install h5py worked great. Now I've got a great system all set up. The ultimate goal for this is to work at it until I can make high scale prints for myself of photos I've taken in the styles of the great painters. Really cool program here man. I'm looking at the upscaling repo and it's all in Japanese?

titu1994 commented 8 years ago

@matthewbahr With a GPU, you are limited to the amount of RAM your GPU has. With my 980M (4 GB), I can go 764 x 764 if I provide --img_size as 764. But this takes exorbitant amounts of time even on GPU. It is better to just choose a smaller size (say 400, or 512) and then upscale this result.

As to the upscaling repo, it was and is still mainly used to upscale low resolution anime art (hence the name "waifu2x-caffe"). Therefore the repo is in Japanese. However, there is no need to read that. You can simply scroll down a little to come across a 109~ MB download. It's a zip file with a program (which is in English) which gives you a nice GUI to work with this upscaling algorithm. I use this daily so I can assure you it's safe.

The above image I posted is also upscaled using this program. There are a few options that are important. Depending on the kind of art that you produce, you may want to use one of two different modes of the upscaling algorithm. However I just use the "2-D illust (UpRGB Model)" model.

Also, since you have setup this script on Windows, you might as well use the Windows Helper program. It provides a nice GUI to quickly select images and alter the parameters of the script. The first time you execute the script, it will as for the location of python.exe from your Anaconda / miniconda installation. I use it directly since I kinda dislike going in the windows command prompt repeatedly for executing this script :P

Also, I've added the note about h5py as well (ideally it is auto installed when installing Keras). These instructions are from my own experience of installing Theano on 14 windows laptops. So I think these instructions are "battle tested" against the beast known as Theano. Still, the first time is a true test of patience.