Code Monkey home page Code Monkey logo

Comments (10)

titu1994 avatar titu1994 commented on July 28, 2024

@bmaltais Are you using Theano or Tensorflow? Either case, upon launching the script it will show "Using X Backend" followed by "Using gpu device: GPU card name (CNMEM is Enabled...)"

It also depends on which of the two scripts you are using : The Network.py script is slightly faster than INetwork.py script (INetwork.py script uses all layers of VGG for style inference, which requires large amounts of time).

In addition, are you using cuDNN? I highly recommend it for both scripts, especially cuDNN 5.1 since it has bettter performance for VGG 16 and 19 networks by 2.7x

Lastly, are you comparing neural-style in Lua/Torch7, written by jcjohnson? Lua doesn't have a start up time (Theano on GPU has huge startup time, Tensorflow not so much). Does it produce the same results as this script in 50 epochs ? I haven't been able to use it since I'm working on Windows.

from neural-style-transfer.

bmaltais avatar bmaltais commented on July 28, 2024

@titu1994

Running

python Network.py ../in/art2/dst.jpg ../in/art4/src.jpg ./res

I get

Using Theano backend.
Model loaded.
('Start of iteration', 1)
('Current loss value:', array(1649196800.0, dtype=float32), ' Improvement : nan', '%')
Rescaling Image to (910, 681)
('Image saved as', './res_at_iteration_1.png')
Iteration 1 completed in 196s
('Start of iteration', 2)
('Current loss value:', array(371394208.0, dtype=float32), ' Improvement : 77.480', '%')
Rescaling Image to (910, 681)
('Image saved as', './res_at_iteration_2.png')
Iteration 2 completed in 210s
('Start of iteration', 3)
('Current loss value:', array(186508848.0, dtype=float32), ' Improvement : 49.781', '%')
Rescaling Image to (910, 681)
('Image saved as', './res_at_iteration_3.png')
Iteration 3 completed in 268s
('Start of iteration', 4)
('Current loss value:', array(124295216.0, dtype=float32), ' Improvement : 33.357', '%')
Rescaling Image to (910, 681)
('Image saved as', './res_at_iteration_4.png')
Iteration 4 completed in 281s
('Start of iteration', 5)

No indication of CPU vs GPU.

I have both cudn and cuDNN (cudnn-7.5-linux-x64-v5.1.tgz) installed and working with neural-style so I like to think they should be compatible with keras.

How long does it take on your system to run 1000 neural-style (in Lua/Torch7, written by jcjohnson) iteration vs 50 epoch in Neural0Style-Transfer? This info should provide a good estimation of the expected time factor needed when compared to 1000 neural-style iterations. Like twice as fast, same, 1.5 times slower, etc.

I have installed things under linux... but I don't expect this to make a huge diff... but perhaps it does. The funny thing is that I tried to install under Windows 1st but the NVIDIA cuda requirements for visual studio made me mad. I triel to install Visual Studio Express 2015 but found out that it is not supported under 7.5... And now my Windows system is full of junk related to Visual Studio that does not ger de-installed when uninstalling VS 2015.

So I installed Ubuntu on a USB attached SSD because I knwe that would work with cuda.

What version of VS did you install on windows to install CUDA?

from neural-style-transfer.

bmaltais avatar bmaltais commented on July 28, 2024

OK. Did more digging. I think the issue might stem from some missing path. Running:

THEANO_FLAGS='floatX=float32,device=gpu,lib.cnmem=0.8' python Network.py ../in/art2/dst.jpg ../in/art4/src.jpg ./res

resulted in

Using Theano backend.
ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.
Model loaded.

So now I need to figure out what path I need to add to fix this ;-)

from neural-style-transfer.

titu1994 avatar titu1994 commented on July 28, 2024

@bmaltais That means that Theano is not using the GPU. Have you set up your .theanorc file in your home directory?

The minimal .theanorc file in Linux or .theanorc.txt file in Windows to invoke GPU is :

[global]
floatX = float32
device = gpu

[lib]
cnmem = 0.75 # If you have cuDNN installed, and highly recommended 

Theano uses this file to decide runtime configurations, and device = gpu sets it to use gpu if cuda and cudnn are available.

I am using Windows so I am not able to run jcjohnson's neural-style code (No Lua or Torch7 on Windows), but I myself run both the Network.py and INetwork.py script using a 980 M mobile GPU, and here are my time requirements.

With size 400x400, each iteration takes 11 seconds
With size 512x512, each iteration takes 17-18 seconds.

Extrapolating from that, 50 iterations completes using 400x400 completes in approximately 9 minutes and a few seconds (550 seconds). This is a tad bit faster than jcjohnson's implementation (50 epochs in 15 minutes, according to you), with a speedup of 1.62 times as fast as jcjohnson's script.

Now as to using this on Windows, I agree it is a sublime p-i-t-a. Theano requires MS VS 2013 to be installed for CUDA 7.5.

EDIT:
I found another user saying that on the new 1060 GPU, the more time consuming INetwork.py script requires just 7 seconds per epoch. That would extrapolate to 50 iterations in 5 minutes and 46 seconds ~ approximately, roughly 2.6 times faster with better results than the older Network.py script.

from neural-style-transfer.

titu1994 avatar titu1994 commented on July 28, 2024

@bmaltais Are you running this on Windows now? Add the path to the MS VS 2013 compiler.

To make matters easier, I'll post my .theanorc.txt here:

[global]
device=gpu 
floatX=float32
optimizer=fast_run
optimizer_including=cudnn
base_compiledir=D:\Users\Yue\Theano Make # Not needed, I prefer the output on my HDD rather than SDD
allow_gc=True

[cuda]
root = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5 # Path to CUDA 7.5

[nvcc]
fastmath = True
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin # Path to NVCC compiler (Needs MS VS 2013) 

[lib]
cnmem=0.8

from neural-style-transfer.

bmaltais avatar bmaltais commented on July 28, 2024

OK. I added /usr/local/cuda/bin to the $PATH environment variable. Now running

THEANO_FLAGS='floatX=float32,device=gpu,lib.cnmem=0.7' python Network.py ../in/art2/dst.jpg ../in/art4/src.jpg ./res

Is looking good:

Using Theano backend.
Using gpu device 0: GeForce GTX 780M (CNMeM is enabled with initial size: 80.0% of memory, cuDNN 5103)
/home/bernard/anaconda2/lib/python2.7/site-packages/theano/sandbox/cuda/__init__.py:600: UserWarning: Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.
  warnings.warn(warn)
Model loaded.
('Start of iteration', 1)
('Current loss value:', array(1618764032.0, dtype=float32), ' Improvement : nan', '%')
Rescaling Image to (910, 681)
('Image saved as', './res_at_iteration_1.png')
Iteration 1 completed in 21s
('Start of iteration', 2)
('Current loss value:', array(353565184.0, dtype=float32), ' Improvement : 78.158', '%')
Rescaling Image to (910, 681)
('Image saved as', './res_at_iteration_2.png')
Iteration 2 completed in 21s
('Start of iteration', 3)

Loading the model took something like 3 minutes but after each epoch take 21 second on my old GPU. Much better ;-)

from neural-style-transfer.

titu1994 avatar titu1994 commented on July 28, 2024

@bmaltais Thats great. I think I will add a step by step guide to installing Theano w/ GPU for Windows.

The info I found on the net were scattered along various kaggle contests and across various sites. It's best to set have a centralized source of info for an important thing like this.

from neural-style-transfer.

bmaltais avatar bmaltais commented on July 28, 2024

@titu1994 That would be great. If you want to share the config for linux .theanorc here is what I came up with that work fine for me:

[global]
device=gpu
floatX=float32
optimizer=fast_run
optimizer_including=cudnn

[lib]
cnmem=0.8

Essentially on Ubuntu 14.04 I installed anaconda2, installed cuda 7.5 and cudann 5.1 for cuda 7.5 and did a pip install keras. Last you need to create a ~/.theanorc file with the content above.

from neural-style-transfer.

titu1994 avatar titu1994 commented on July 28, 2024

@bmaltais Thanks for the linux version of theanorc.

I'm crying a little bit on the inside because of how simple it is to install Theano with GPU support on Ubuntu as compared to installing gigantic MS VS 2013 and other unrelated stuff for Windows + Theano (although I do program a lot of C# in VS 2015 :P).

from neural-style-transfer.

titu1994 avatar titu1994 commented on July 28, 2024

@bmaltais The guide.md now contains whole sections on how to install Theano on Windows and Linux.

from neural-style-transfer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.