awentzonline / image-analogies

Generate image analogies using neural matching and blending.
MIT License
3.52k stars 282 forks source link

couple of issues to support opencl #21

Open rayset opened 8 years ago

rayset commented 8 years ago

as you know theano works on opencl, but it's in beta.

first issue: this program forces cpu mode if not on cuda.

python make_image_analogy.py images/arch-A.jpg images/arch-Ap.jpg images/arch-B.jpg /nothing Using Theano backend. Mapped name None to device opencl0:0: Tahiti /home/deep/.local/lib/python2.7/site-packages/theano/tensor/signal/downsample.py:5: UserWarning: downsample module has been moved to the pool module. warnings.warn("downsample module has been moved to the pool module.") Theano CPU mode detected. Forcing a-scale-mode to "match" Using PatchMatch model

I think this is because of the _on_gpu() method of keras/backend/theano_backend.py that seems to assume opencl (and gpuarray) support don't exist.

second problem: this is the error I get running the code

Precomputing static features... ERROR (theano.gof.opt): Optimization failure due to: local_error_convop ERROR (theano.gof.opt): node: ConvOp{('imshp', (256, 16, 12)),('kshp', (3, 3)),('nkern', 512),('bsize', None),('dx', 1),('dy', 1),('out_mode', 'valid'),('unroll_batch', None),('unroll_kern', None),('unroll_patch', True),('imshp_logical', (256, 16, 12)),('kshp_logical', (3, 3)),('kshp_logical_top_aligned', True)}(IncSubtensor{Set;::, ::, int64:int64:, int64:int64:}.0, HostFromGpu(gpuarray).0) ERROR (theano.gof.opt): TRACEBACK: ERROR (theano.gof.opt): Traceback (most recent call last): File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 1772, in process_node replacements = lopt.transform(node) File "/home/deep/.local/lib/python2.7/site-packages/theano/sandbox/gpuarray/opt.py", line 141, in local_opt new_op = maker(node, context_name) File "/home/deep/.local/lib/python2.7/site-packages/theano/sandbox/gpuarray/opt.py", line 839, in local_error_convop """ AssertionError: ConvOp does not work with the gpuarray backend.

Use the new convolution interface to have GPU convolution working: theano.tensor.nnet.conv2d()

Traceback (most recent call last): File "make_image_analogy.py", line 27, in image_analogy.main.main(args, model_class) File "/home/deep/.local/lib/python2.7/site-packages/image_analogy/main.py", line 69, in main model.build(a_image, ap_image, b_image, (1, img_num_channels, img_height, img_width)) File "/home/deep/.local/lib/python2.7/site-packages/image_analogy/models/nnf.py", line 16, in build loss = self.build_loss(a_image, ap_image, b_image) File "/home/deep/.local/lib/python2.7/site-packages/image_analogy/models/nnf.py", line 54, in build_loss all_a_features, all_ap_image_features, all_b_features = self.precompute_static_features(a_image, ap_image, b_image) File "/home/deep/.local/lib/python2.7/site-packages/image_analogy/models/base.py", line 51, in precompute_static_features all_a_features = self.get_features(a_image, a_layers) File "/home/deep/.local/lib/python2.7/site-packages/image_analogy/models/base.py", line 59, in get_features f = K.function([self.net_input], [self.get_layer_output(layer_name) for layer_name in layers]) File "/home/deep/.local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 388, in function return Function(inputs, outputs, updates=updates) File "/home/deep/.local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 380, in init allow_input_downcast=True, _kwargs) File "/home/deep/.local/lib/python2.7/site-packages/theano/compile/function.py", line 320, in function output_keys=output_keys) File "/home/deep/.local/lib/python2.7/site-packages/theano/compile/pfunc.py", line 479, in pfunc output_keys=output_keys) File "/home/deep/.local/lib/python2.7/site-packages/theano/compile/function_module.py", line 1776, in orig_function output_keys=output_keys).create( File "/home/deep/.local/lib/python2.7/site-packages/theano/compile/function_module.py", line 1456, in init optimizer_profile = optimizer(fgraph) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 101, in call return self.optimize(fgraph) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 89, in optimize ret = self.apply(fgraph, args, _kwargs) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 230, in apply sub_prof = optimizer.optimize(fgraph) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 89, in optimize ret = self.apply(fgraph, _args, _kwargs) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 230, in apply sub_prof = optimizer.optimize(fgraph) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 89, in optimize ret = self.apply(fgraph, _args, *_kwargs) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 2196, in apply lopt_change = self.process_node(fgraph, node, lopt) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 1777, in process_node lopt, node) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 1673, in warn_inplace return NavigatorOptimizer.warn(exc, nav, repl_pairs, local_opt, node) File "/home/deep/.local/lib/python2.7/site-packages/theano/gof/opt.py", line 1659, in warn raise exc AssertionError: ConvOp does not work with the gpuarray backend.

Use the new convolution interface to have GPU convolution working: theano.tensor.nnet.conv2d()

I think using conv2d instead of ConvOp could fix it, but I really have no idea of how much of a work is it. if you'll ever decide to make it work on opencl I will happly make a readme here or on reddit on how to set it up. for now I'll try to figure out how to run with tensorflow!

awentzonline commented 8 years ago

Thanks for giving it a shot with opencl! I think both of those issues need to be solved in keras. I'll have a look at what it would take.

rayset commented 8 years ago

if you'll ever need some opencl testing feel free contact me, sadly I'm not able to help you more than that.

I read that the developers of neural doodle are looking into opencl too (they also have a theano backend),I'm myself going to test it too tomorrow, if I read something interesting over there I will link it here.