hughperkins / neural-style

Torch implementation of neural style algorithm
MIT License
1 stars 0 forks source link

Is "opencl" version ready to use? #2

Open vi opened 8 years ago

vi commented 8 years ago

If yes, where are installation instructions? What -gpu shall I specify?

Naive attempt (just checkout opencl and start th neural_style.lua):

# th neural_style.lua -gpu -1
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:505] Reading dangerously large protocol message.  If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 574671192
Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel
/root/torch/install/bin/luajit: models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:2: bad argument #1 to 'insert' (table expected, got nil)
stack traceback:
    [C]: in function 'insert'
    models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:2: in main chunk
    [C]: in function 'dofile'
    ./loadcaffe_wrapper.lua:48: in function 'load'
    neural_style.lua:66: in function 'main'
    neural_style.lua:484: in main chunk
    [C]: in function 'dofile'
    /root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00406670

Second attempt:

/root/torch/install/bin/luarocks install clnn
...
# th neural_style.lua -gpu 0 -backend clnn
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:505] Reading dangerously large protocol message.  If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 574671192
Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel
/root/torch/install/bin/luajit: models/VGG_ILSVRC_19_layers_deploy.prototxt.opencl.lua:3: bad argument #1 to 'insert' (table expected, got nil)
stack traceback:
    [C]: in function 'insert'
    models/VGG_ILSVRC_19_layers_deploy.prototxt.opencl.lua:3: in main chunk
    [C]: in function 'dofile'
    ./loadcaffe_wrapper.lua:77: in function 'load'
    neural_style.lua:66: in function 'main'
    neural_style.lua:484: in main chunk
    [C]: in function 'dofile'
    /root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00406670

Third attempt:

diff --git a/loadcaffe_wrapper.lua b/loadcaffe_wrapper.lua
index ca3ef8c..93f4b1b 100644
--- a/loadcaffe_wrapper.lua
+++ b/loadcaffe_wrapper.lua
@@ -69,6 +69,7 @@ local function loadcaffe_load(prototxt_name, binary_name, backend)
         elseif line_num == 1 then
           fout:write("require 'nn'", '\n')
           fout:write("require 'clnn'", '\n')
+          fout:write("local model = {}", '\n')
         end
         line_num = line_num + 1
       end
# th neural_style.lua -gpu 0 -backend clnn
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:505] Reading dangerously large protocol message.  If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 574671192
Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel
conv1_1: 64 3 3 3
conv1_2: 64 64 3 3
conv2_1: 128 64 3 3
conv2_2: 128 128 3 3
conv3_1: 256 128 3 3
conv3_2: 256 256 3 3
conv3_3: 256 256 3 3
conv3_4: 256 256 3 3
conv4_1: 512 256 3 3
conv4_2: 512 512 3 3
conv4_3: 512 512 3 3
conv4_4: 512 512 3 3
conv5_1: 512 512 3 3
conv5_2: 512 512 3 3
conv5_3: 512 512 3 3
conv5_4: 512 512 3 3
fc6: 1 1 25088 4096
fc7: 1 1 4096 4096
fc8: 1 1 4096 1000
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Using Intel , OpenCL platform: Intel Gen OCL Driver
Using OpenCL device: Intel(R) HD Graphics IvyBridge M GT2
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Setting up content layer    22  :   relu4_2 
/root/torch/install/bin/luajit: /root/torch/install/share/lua/5.1/nn/Linear.lua:39: size mismatch at /tmp/luarocks_cltorch-scm-1-9902/cltorch/cltorch/src/lib/THClTensorMathBlas.cpp:50
stack traceback:
    [C]: in function 'addmv'
    /root/torch/install/share/lua/5.1/nn/Linear.lua:39: in function 'updateOutput'
    /root/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    neural_style.lua:250: in function 'main'
    neural_style.lua:484: in main chunk
    [C]: in function 'dofile'
    /root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00406670

Fourth attempt:

# time th neural_style.lua -style_image examples/inputs/picasso_selfport1907.jpg -content_image examples/inputs/brad_pitt.jpg -gpu 0 -output_image profile.png -image_size 300 -model_file models/vgg_normalised.caffemodel -backend clnn -num_iterations 20 -save_iter 20 -normalize_gradients -content_weight 50000 -style_weight 90000 -print_iter 1
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Successfully loaded models/vgg_normalised.caffemodel
conv1_1: 64 3 3 3
conv1_2: 64 64 3 3
conv2_1: 128 64 3 3
conv2_2: 128 128 3 3
conv3_1: 256 128 3 3
conv3_2: 256 256 3 3
conv3_3: 256 256 3 3
conv3_4: 256 256 3 3
conv4_1: 512 256 3 3
conv4_2: 512 512 3 3
conv4_3: 512 512 3 3
conv4_4: 512 512 3 3
conv5_1: 512 512 3 3
conv5_2: 512 512 3 3
conv5_3: 512 512 3 3
conv5_4: 512 512 3 3
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Using Intel , OpenCL platform: Intel Gen OCL Driver
Using OpenCL device: Intel(R) HD Graphics IvyBridge M GT2
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Failed to release test userptr object! (9) i915 kernel driver may not be sane!
Setting up content layer    22  :   relu4_2 
Running optimization with L-BFGS    
Apply_3t_0s_0pt_-2_-2_-2_*out = 3.4265350877193e-06 * (*in1 - *in2) build log: 
/tmp/wJn5sO.cl:37:12: warning: double precision constant requires cl_khr_fp64, casting to single precision

Iteration 1 / 20    
  Content 1 loss: 1155038.891173    
  Total loss: 1155038.891173    
<optim.lbfgs>   creating recyclable direction/step/history buffers  
Iteration 2 / 20    
  Content 1 loss: 1155037.606223    
  Total loss: 1155037.606223    
Iteration 3 / 20    
  Content 1 loss: 1151180.698328    
  Total loss: 1151180.698328    
...
Iteration 20 / 20   
  Content 1 loss: 315240.542763 
  Total loss: 315240.542763 
<optim.lbfgs>   reached max number of iterations    

real    8m15.786s
user    0m5.430s
sys 0m1.690s

Running CPU version with the same parameters (except of -gpu 0 and -backend) takes 0m57.309s...

susloparovdenis commented 8 years ago

Looks like the author abandoned this project, I managed to run it on stock version of torch and clnn with after modification of loadcaffe_wrapper. It's removing needed lines from VGG_ILSVRC_19_layers_deploy.prototxt.opencl.lua. I am going to sort this out in my repository and pull request into main repo in a few days. My results was not so good on Radeon 280x, max image size is reult was 350. If I set bigger, errors or egmentation falts happen or even the whole system freezes forever.