cysmith / neural-style-tf

TensorFlow (Python API) implementation of Neural Style
GNU General Public License v3.0
3.11k stars 828 forks source link

Running neural_style.py under Windows 10 x64 #72

Open AiDataSciencer opened 6 years ago

AiDataSciencer commented 6 years ago

Unfortunately I cannot get the code working on my windows machine, since the program is obviously executed using LINUX bash scripts. I got all dependencies inplace, including CUDA and cudnn, since the machine is equipped with an NVIDEA 1080 GPU.

My intention is to simply run main() of neural_style.py from a parent python script, passing all arguments as python variables to main().

I'd greatly appreciate any advice or pseudo examples, since I really want to dig deeper into that beautiful project and the work which has been already done here.

glennamarshall commented 6 years ago

Hi - I got it working under Windows 10 - I installed everything inside Anaconda - I'll try and help if I can.

AiDataSciencer commented 6 years ago

Thanks for your response and the pleasant news you got it working.

I am currently using a "standard" Python installation with Spyder and I installed all libraries required for getting neural_style to run. Are there any other advantages choosing Anaconda over the standard Python distribution?

How do you call i.e. run the programm? Are you somehow using the bash (.sh) scripts to call the python functions insede neural_style.py or are you calling the functions directly from python? How are you passing arguments to the python functions?

Maybe you could share some code to make a long story much shorter. :)

glennamarshall commented 6 years ago

i'm a bit of a noob - so i'll do my best - I followed the instructions on other style transfer projects on github that help you install anaconda and all the other stuff - then you run the anaconda command prompt - and just type 'python neural_style.py' with all your parameters.. i'll have a look around to see where I got my initial installation help from and get back to you.

glennamarshall commented 6 years ago

this is one link I found which I may have used.. https://sites.google.com/site/ivanhuertacasado/installing-keras-theano-tensorflow-with-gpu-windows

glennamarshall commented 6 years ago

and this http://bennycheung.github.io/deep-learning-on-windows-10

AiDataSciencer commented 6 years ago

Great! Thank you for the links. I will work through it and get back to you afterwards. Maybe I can get it work following the instructions in the links.

ljm2020 commented 6 years ago

Hi, I had problem using .sh script in google colab, so I directly called neural_style.py in my code in colab, maybe you can check and might help you implementing it in Win10.

https://colab.research.google.com/drive/18w-b-ntmA8Y5u7JYLrwPqFAIefj4ZFH5

glennamarshall commented 6 years ago

that looks interesting ljm - for a total noob - what's all the stuff I need to install to run this?

ljm2020 commented 6 years ago

if you run it in colab, you need install nothing, just copy this notebook into your own google drive and run the codes step by step follow the instructions:) but if you want to transfer it to Win10 locally, you will need to make a lot of input/output changes (as my codes are adapted to Colab VM which is linux based) for your windows environment.

glennamarshall commented 6 years ago

thanks very much for that - I'll give it a try..

ljm2020 commented 6 years ago

no problem, let me know when you succeed:)

PS: I didn't do that because I don't have a GPU equipped computer at hand, that's also why I pick colab:)

glennamarshall commented 6 years ago

interesting - never heard of colab before - and it has GPU too! - hopefully it will be faster than my laptop :)

AiDataSciencer commented 6 years ago

Hey Guys. I appreciate the information you were sharing. As said before, I will take a look into the links you shared (now also Jim's) and I'll get back to you asap. My objective is to get this running locally on windows in the first place and do some experiments. I think I have appropriate hardware in place and I want to try this with higher resolution pictures, which I took with my Nikon DSLR. Thus, GPU usage will most likely be mandatory. However, I expect it will take me a couple of days or a week to come up with an update, since I am actually on vacation.

glennamarshall commented 6 years ago

Yes thanks ljm - I'm just trying to get your project working - I have colab setup and copied the notebook across. I hit 'Run all' and then it seemed to install a lot of stuff - and then just hung. Don't really know what I'm doing.

p.s. topper, I recommend you use this process rather than locally - it uses its own super fast GPU for your hi res images that your computer will probably not be able to handle.

glennamarshall commented 6 years ago

well I got as far as uploading my content and style images etc - but when rendering it hangs on iteration 0 with this message

At iterate 0 f= 1.11117D+11 |proj g|= 1.38032D+06 2018-08-13 16:56:45.867982: W tensorflow/core/framework/allocator.cc:108] Allocation of 276480000 exceeds 10% of system memory. 2018-08-13 16:56:46.513273: W tensorflow/core/framework/allocator.cc:108] Allocation of 552960000 exceeds 10% of system memory. 2018-08-13 16:56:54.862442: W tensorflow/core/framework/allocator.cc:108] Allocation of 276480000 exceeds 10% of system memory.

any ideas?

ljm2020 commented 6 years ago

if you got that far, it means it's working, it's just some warning of system memory, normally it does not kill your process, be patient:)

as long as it does not breaks out with an error message of Resource Exhausted, you will be fine.

glennamarshall commented 6 years ago

yes indeed you were right - I got it working great :)

one final question - whats' the easiest way to quickly create an image with my own parameters - for example, here's the command line I usually run

python neural_style.py --verbose --print_iterations 1 --img_output_dir image_output --content_img_dir image_input --style_imgs_dir styles --content_img "C:\Users\ga_ma\Desktop\giftest\gifframesjpg\g_0343-2db-1 (dragged).jpg" --style_imgs "C:\Users\ga_ma\Desktop\buddhaart\style\909.png" --max_size 720 --max_iterations 500 --style_weight 1000 --content_weight 0 --init_img_type content --seed 0 --img_name giftest1

this would be useful to know - so that I could create batches of several images I wanted processed together - rather than one at a time.. many thanks..

ljm2020 commented 6 years ago

what I can think is you can define your code above as a function with content image, style image, mask...(even all the arguments) as variants and out put image as return value and run that function in a loop (put image file paths in a matrix) :)

glennamarshall commented 6 years ago

i'll try that thanks...

glennamarshall commented 6 years ago

Hi again, I'm getting everything working the way I want using your great implementation - but there's something I'm worried about.. Sometimes I'm asked to re-authorise and also a new virtual machine is set up. I thought this was a once only procedure.
For short periods of time this doesn't happen and I can easily log out and in and continue from where I left off. However this morning I had to re authorise and start a new VM, losing all the files I had uploaded previously.

Is this normal?

ljm2020 commented 6 years ago

sadly, that's the limitation of colab, it's free, but limited... that's why I write that sync function to copy all the data generated in VM to google drive (work directly on google drive is very slow and often meet with input/output error...)

glennamarshall commented 6 years ago

I see, thanks. Yes I suppose it's better than nothing.. I think I read somewhere you get 12 hours for a session, which is pretty good.

ljm2020 commented 6 years ago

I never get longer than 4 hours I think, and it require me constantly doing something/anything in the colab environment, it shuts you down automatically if you have no action for a time...

better than nothing :-p

glennamarshall commented 6 years ago

dammit - was hoping to do overnight batch rendering of sequences of images..

ljm2020 commented 6 years ago

google does not want anybody using colab for mining purpose, so guess you have to do on your local environment:)

glennamarshall commented 6 years ago

grrrr

glennamarshall commented 6 years ago

Hi ljm I've just noticed this morning that the authorisation is failing to work - it has been working fine all week until now - just wondering does something need updated in your code. Here's the error.

  1. That’s an error.

Error: invalid_client

The OAuth client was not found.

Thanks..

lcb931023 commented 6 years ago

Ditto on the authorization issue, although it doesn't seem to completely make the colab notebook unusable. The stylize_image.sh script still works when called directly.

lcb931023 commented 6 years ago

Hey @topperwithharley , I got this repo running on Windows 10 x64 just now. Will share my setup and quirks below, hope it'll help!


Dependencies

Install notes

The python environment is installed via Anaconda. tensorflow and tensorflow-gpu is installed using pip inside Anaconda.

Different versions of TensorFlow on windows defaults to different version of CUDA / cuDNN. Hence why I'm pairing tensorflow 1.4.0 with CUDA 8 and cuDNN 6. The latest usually keeps up with the latest. But check release note on Github. Old cuDNN releases can be downloaded at https://developer.nvidia.com/rdp/cudnn-archive

OpenCV on Windows is only supported by non-official binary. Use special magical command in Anaconda conda install -c https://conda.binstar.org/menpo opencv

Don't forget to download the imagenet vgg model weight.

Running the style transfer

For now I've only tried single image transfer. Video will require some extra dependencies that's difficult on Windows.

Simply run the python script and pass in arguments to specify content, style, and gpu option. e.g.:

python neural_style.py --content_img "lion.jpg" --content_img_dir "image_input" --style_imgs "kandinsky.jpg" --style_imgs_dir "styles" --img_name "lion-kandinsky-output" --device "/gpu:0"
mote0230 commented 6 years ago

Here's my even easier step by step guide for win10:

Download & install:

Install dependencies:

Test

xiangshidai commented 5 years ago

Hi, I had problem using .sh script in google colab, so I directly called neural_style.py in my code in colab, maybe you can check and might help you implementing it in Win10.

https://colab.research.google.com/drive/18w-b-ntmA8Y5u7JYLrwPqFAIefj4ZFH5

This is amazing!!!!

Hanbub commented 5 years ago

@mote0230 Which version of tensorflow, python, scipy, opencv-python you used?

racinmat commented 4 years ago

Hi, I am running this successfully on Windows 10 machine with GTX 1080Ti, python installed through anaconda. This is my conda environment which I'm using for it, works perfectly fine. Probably there are some other libraries that are not needed, but it works.

name: tensorflow_1_14
channels:
  - defaults
dependencies:
  - _tflow_select=2.1.0=gpu
  - absl-py=0.9.0=py36_0
  - asn1crypto=1.3.0=py36_0
  - astor=0.8.0=py36_0
  - attrs=19.3.0=py_0
  - backcall=0.1.0=py36_0
  - blas=1.0=mkl
  - bleach=3.1.0=py36_0
  - ca-certificates=2020.1.1=0
  - certifi=2019.11.28=py36_0
  - cffi=1.14.0=py36h7a1dbc1_0
  - chardet=3.0.4=py36_1003
  - colorama=0.4.3=py_0
  - cryptography=2.8=py36h7a1dbc1_0
  - cudatoolkit=10.0.130=0
  - cudnn=7.6.5=cuda10.0_0
  - cycler=0.10.0=py36h009560c_0
  - decorator=4.4.1=py_0
  - defusedxml=0.6.0=py_0
  - entrypoints=0.3=py36_0
  - freetype=2.9.1=ha9979f8_1
  - gast=0.3.3=py_0
  - grpcio=1.16.1=py36h351948d_1
  - h5py=2.10.0=py36h5e291fa_0
  - hdf5=1.10.4=h7ebc959_0
  - icc_rt=2019.0.0=h0cc432a_1
  - icu=58.2=ha66f8fd_1
  - idna=2.8=py36_0
  - importlib_metadata=1.5.0=py36_0
  - intel-openmp=2020.0=166
  - ipykernel=5.1.4=py36h39e3cac_0
  - ipython=7.12.0=py36h5ca1d4c_0
  - ipython_genutils=0.2.0=py36_0
  - ipywidgets=7.5.1=py_0
  - jedi=0.16.0=py36_0
  - jinja2=2.11.1=py_0
  - joblib=0.14.1=py_0
  - jpeg=9b=hb83a4c4_2
  - jsonschema=3.2.0=py36_0
  - jupyter=1.0.0=py36_7
  - jupyter_client=5.3.4=py36_0
  - jupyter_console=6.1.0=py_0
  - jupyter_core=4.6.1=py36_0
  - keras-applications=1.0.8=py_0
  - keras-preprocessing=1.1.0=py_1
  - kiwisolver=1.1.0=py36ha925a31_0
  - libpng=1.6.37=h2a8f88b_0
  - libprotobuf=3.11.3=h7bd577a_0
  - libsodium=1.0.16=h9d3ae62_0
  - libtiff=4.1.0=h56a325e_0
  - m2w64-gcc-libgfortran=5.3.0=6
  - m2w64-gcc-libs=5.3.0=7
  - m2w64-gcc-libs-core=5.3.0=7
  - m2w64-gmp=6.1.0=2
  - m2w64-libwinpthread-git=5.0.0.4634.697f757=2
  - markdown=3.1.1=py36_0
  - markupsafe=1.1.1=py36he774522_0
  - matplotlib=3.1.3=py36_0
  - matplotlib-base=3.1.3=py36h64f37c6_0
  - mistune=0.8.4=py36he774522_0
  - mkl=2020.0=166
  - mkl-service=2.3.0=py36hb782905_0
  - mkl_fft=1.0.15=py36h14836fe_0
  - mkl_random=1.1.0=py36h675688f_0
  - msys2-conda-epoch=20160418=1
  - nbconvert=5.6.1=py36_0
  - nbformat=5.0.4=py_0
  - notebook=6.0.3=py36_0
  - numpy=1.16.6=py36h5510c5b_0
  - numpy-base=1.16.6=py36hc3f5095_0
  - olefile=0.46=py36_0
  - openssl=1.1.1d=he774522_4
  - pandas=1.0.1=py36h47e9c7a_0
  - pandoc=2.2.3.2=0
  - pandocfilters=1.4.2=py36_1
  - parso=0.6.1=py_0
  - pickleshare=0.7.5=py36_0
  - pillow=7.0.0=py36hcc1f983_0
  - pip=20.0.2=py36_1
  - prometheus_client=0.7.1=py_0
  - prompt_toolkit=3.0.3=py_0
  - protobuf=3.11.3=py36h33f27b4_0
  - pycparser=2.19=py36_0
  - pygments=2.5.2=py_0
  - pyopenssl=19.1.0=py36_0
  - pyparsing=2.4.6=py_0
  - pyqt=5.9.2=py36h6538335_2
  - pyreadline=2.1=py36_1
  - pyrsistent=0.15.7=py36he774522_0
  - pysocks=1.7.1=py36_0
  - python=3.6.10=h9f7ef89_0
  - python-dateutil=2.8.1=py_0
  - pytz=2019.3=py_0
  - pywin32=227=py36he774522_1
  - pywinpty=0.5.7=py36_0
  - pyzmq=18.1.1=py36ha925a31_0
  - qt=5.9.7=vc14h73c81de_0
  - qtconsole=4.6.0=py_1
  - requests=2.22.0=py36_1
  - scikit-learn=0.22.1=py36h6288b17_0
  - scipy=1.4.1=py36h9439919_0
  - send2trash=1.5.0=py36_0
  - setuptools=45.2.0=py36_0
  - sip=4.19.8=py36h6538335_0
  - six=1.14.0=py36_0
  - sqlite=3.31.1=he774522_0
  - tensorboard=1.14.0=py36he3c9ec2_0
  - tensorflow=1.14.0=gpu_py36h305fd99_0
  - tensorflow-base=1.14.0=gpu_py36h55fc52a_0
  - tensorflow-estimator=1.14.0=py_0
  - tensorflow-gpu=1.14.0=h0d30ee6_0
  - termcolor=1.1.0=py36_1
  - terminado=0.8.3=py36_0
  - testpath=0.4.4=py_0
  - tk=8.6.8=hfa6e2cd_0
  - tornado=6.0.3=py36he774522_3
  - traitlets=4.3.3=py36_0
  - urllib3=1.25.8=py36_0
  - vc=14.1=h0510ff6_4
  - vs2015_runtime=14.16.27012=hf0eaf9b_1
  - wcwidth=0.1.8=py_0
  - webencodings=0.5.1=py36_1
  - werkzeug=1.0.0=py_0
  - wheel=0.34.2=py36_0
  - widgetsnbextension=3.5.1=py36_0
  - win_inet_pton=1.1.0=py36_0
  - wincertstore=0.2=py36h7fe50ca_0
  - winpty=0.4.3=4
  - wrapt=1.11.2=py36he774522_0
  - xz=5.2.4=h2fa13f4_4
  - zeromq=4.3.1=h33f27b4_3
  - zipp=2.2.0=py_0
  - zlib=1.2.11=h62dcd97_3
  - zstd=1.3.7=h508b16e_0
  - pip:
    - click==7.1.2
    - dlib==19.19.0
    - imageio==2.6.1
    - imageio-ffmpeg==0.3.0
    - imutils==0.5.3
    - moviepy==1.0.1
    - opencv-contrib-python==4.2.0.32
    - proglog==0.1.9
    - progressbar2==3.51.0
    - python-utils==2.4.0
    - tqdm==4.24.0

Since I'm on windows, I can't run sh scripts too, so I'm preparing arguments in py wrapper python scripts and then execute render_single_image function, although I made some changes which can be seen here: https://github.com/racinmat/neural-style-tf

dokluch commented 3 years ago

Hi, I am running this successfully on Windows 10 machine with GTX 1080Ti, python installed through anaconda. This is my conda environment which I'm using for it, works perfectly fine. Probably there are some other libraries that are not needed, but it works.

name: tensorflow_1_14
channels:
  - defaults
dependencies:
  - _tflow_select=2.1.0=gpu
  - absl-py=0.9.0=py36_0
  - asn1crypto=1.3.0=py36_0
  - astor=0.8.0=py36_0
  - attrs=19.3.0=py_0
  - backcall=0.1.0=py36_0
  - blas=1.0=mkl
  - bleach=3.1.0=py36_0
  - ca-certificates=2020.1.1=0
  - certifi=2019.11.28=py36_0
  - cffi=1.14.0=py36h7a1dbc1_0
  - chardet=3.0.4=py36_1003
  - colorama=0.4.3=py_0
  - cryptography=2.8=py36h7a1dbc1_0
  - cudatoolkit=10.0.130=0
  - cudnn=7.6.5=cuda10.0_0
  - cycler=0.10.0=py36h009560c_0
  - decorator=4.4.1=py_0
  - defusedxml=0.6.0=py_0
  - entrypoints=0.3=py36_0
  - freetype=2.9.1=ha9979f8_1
  - gast=0.3.3=py_0
  - grpcio=1.16.1=py36h351948d_1
  - h5py=2.10.0=py36h5e291fa_0
  - hdf5=1.10.4=h7ebc959_0
  - icc_rt=2019.0.0=h0cc432a_1
  - icu=58.2=ha66f8fd_1
  - idna=2.8=py36_0
  - importlib_metadata=1.5.0=py36_0
  - intel-openmp=2020.0=166
  - ipykernel=5.1.4=py36h39e3cac_0
  - ipython=7.12.0=py36h5ca1d4c_0
  - ipython_genutils=0.2.0=py36_0
  - ipywidgets=7.5.1=py_0
  - jedi=0.16.0=py36_0
  - jinja2=2.11.1=py_0
  - joblib=0.14.1=py_0
  - jpeg=9b=hb83a4c4_2
  - jsonschema=3.2.0=py36_0
  - jupyter=1.0.0=py36_7
  - jupyter_client=5.3.4=py36_0
  - jupyter_console=6.1.0=py_0
  - jupyter_core=4.6.1=py36_0
  - keras-applications=1.0.8=py_0
  - keras-preprocessing=1.1.0=py_1
  - kiwisolver=1.1.0=py36ha925a31_0
  - libpng=1.6.37=h2a8f88b_0
  - libprotobuf=3.11.3=h7bd577a_0
  - libsodium=1.0.16=h9d3ae62_0
  - libtiff=4.1.0=h56a325e_0
  - m2w64-gcc-libgfortran=5.3.0=6
  - m2w64-gcc-libs=5.3.0=7
  - m2w64-gcc-libs-core=5.3.0=7
  - m2w64-gmp=6.1.0=2
  - m2w64-libwinpthread-git=5.0.0.4634.697f757=2
  - markdown=3.1.1=py36_0
  - markupsafe=1.1.1=py36he774522_0
  - matplotlib=3.1.3=py36_0
  - matplotlib-base=3.1.3=py36h64f37c6_0
  - mistune=0.8.4=py36he774522_0
  - mkl=2020.0=166
  - mkl-service=2.3.0=py36hb782905_0
  - mkl_fft=1.0.15=py36h14836fe_0
  - mkl_random=1.1.0=py36h675688f_0
  - msys2-conda-epoch=20160418=1
  - nbconvert=5.6.1=py36_0
  - nbformat=5.0.4=py_0
  - notebook=6.0.3=py36_0
  - numpy=1.16.6=py36h5510c5b_0
  - numpy-base=1.16.6=py36hc3f5095_0
  - olefile=0.46=py36_0
  - openssl=1.1.1d=he774522_4
  - pandas=1.0.1=py36h47e9c7a_0
  - pandoc=2.2.3.2=0
  - pandocfilters=1.4.2=py36_1
  - parso=0.6.1=py_0
  - pickleshare=0.7.5=py36_0
  - pillow=7.0.0=py36hcc1f983_0
  - pip=20.0.2=py36_1
  - prometheus_client=0.7.1=py_0
  - prompt_toolkit=3.0.3=py_0
  - protobuf=3.11.3=py36h33f27b4_0
  - pycparser=2.19=py36_0
  - pygments=2.5.2=py_0
  - pyopenssl=19.1.0=py36_0
  - pyparsing=2.4.6=py_0
  - pyqt=5.9.2=py36h6538335_2
  - pyreadline=2.1=py36_1
  - pyrsistent=0.15.7=py36he774522_0
  - pysocks=1.7.1=py36_0
  - python=3.6.10=h9f7ef89_0
  - python-dateutil=2.8.1=py_0
  - pytz=2019.3=py_0
  - pywin32=227=py36he774522_1
  - pywinpty=0.5.7=py36_0
  - pyzmq=18.1.1=py36ha925a31_0
  - qt=5.9.7=vc14h73c81de_0
  - qtconsole=4.6.0=py_1
  - requests=2.22.0=py36_1
  - scikit-learn=0.22.1=py36h6288b17_0
  - scipy=1.4.1=py36h9439919_0
  - send2trash=1.5.0=py36_0
  - setuptools=45.2.0=py36_0
  - sip=4.19.8=py36h6538335_0
  - six=1.14.0=py36_0
  - sqlite=3.31.1=he774522_0
  - tensorboard=1.14.0=py36he3c9ec2_0
  - tensorflow=1.14.0=gpu_py36h305fd99_0
  - tensorflow-base=1.14.0=gpu_py36h55fc52a_0
  - tensorflow-estimator=1.14.0=py_0
  - tensorflow-gpu=1.14.0=h0d30ee6_0
  - termcolor=1.1.0=py36_1
  - terminado=0.8.3=py36_0
  - testpath=0.4.4=py_0
  - tk=8.6.8=hfa6e2cd_0
  - tornado=6.0.3=py36he774522_3
  - traitlets=4.3.3=py36_0
  - urllib3=1.25.8=py36_0
  - vc=14.1=h0510ff6_4
  - vs2015_runtime=14.16.27012=hf0eaf9b_1
  - wcwidth=0.1.8=py_0
  - webencodings=0.5.1=py36_1
  - werkzeug=1.0.0=py_0
  - wheel=0.34.2=py36_0
  - widgetsnbextension=3.5.1=py36_0
  - win_inet_pton=1.1.0=py36_0
  - wincertstore=0.2=py36h7fe50ca_0
  - winpty=0.4.3=4
  - wrapt=1.11.2=py36he774522_0
  - xz=5.2.4=h2fa13f4_4
  - zeromq=4.3.1=h33f27b4_3
  - zipp=2.2.0=py_0
  - zlib=1.2.11=h62dcd97_3
  - zstd=1.3.7=h508b16e_0
  - pip:
    - click==7.1.2
    - dlib==19.19.0
    - imageio==2.6.1
    - imageio-ffmpeg==0.3.0
    - imutils==0.5.3
    - moviepy==1.0.1
    - opencv-contrib-python==4.2.0.32
    - proglog==0.1.9
    - progressbar2==3.51.0
    - python-utils==2.4.0
    - tqdm==4.24.0

Since I'm on windows, I can't run sh scripts too, so I'm preparing arguments in py wrapper python scripts and then execute render_single_image function, although I made some changes which can be seen here: https://github.com/racinmat/neural-style-tf

Thank you for the env list. I've recreated it locally to no luck unfortunately. I'm trying to render a single image and getting about 30 minutes of delay followed by a barrage of errors.