examples icon indicating copy to clipboard operation
examples copied to clipboard

fast_neural_style using cuda

Open spencerbull opened this issue 8 years ago • 2 comments

0.4.0 Cuda 9.0 cudnn 7.1 python3.5

I am trying to train a new model using cuda.

I am getting a RuntimeError


Traceback (most recent call last):
  File "neural_style/neural_style.py", line 239, in <module>
    main()
  File "neural_style/neural_style.py", line 233, in main
    train(args)
  File "neural_style/neural_style.py", line 78, in train
    features_x = vgg(x)
  File "/home/dell/sbull/onnx/env/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/dell/sbull/onnx/examples/fast_neural_style/neural_style/vgg.py", line 28, in forward
    h = self.slice1(X)
  File "/home/dell/sbull/onnx/env/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/dell/sbull/onnx/env/lib/python3.5/site-packages/torch/nn/modules/container.py", line 91, in forward
    input = module(input)
  File "/home/dell/sbull/onnx/env/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/dell/sbull/onnx/env/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 301, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight'

I have spent some time trying to figure it out what to fix, but without luck.

It seems like vgg16 for x needs to be set to run using cuda, like y, but I cannot figure out how to get that to work.

spencerbull avatar May 03 '18 19:05 spencerbull

HI! i get same problem with you ,and i solve the problem by modify the "neural_style.py" :

replace line 72: y = transformer(x.to(device)) as: x = x.to(device) y = transformer(x)

zuotengxu avatar May 13 '18 08:05 zuotengxu

Awesome thanks!

spencerbull avatar May 15 '18 20:05 spencerbull