T2F icon indicating copy to clipboard operation
T2F copied to clipboard

RuntimeError: Expected object of backend CUDA but got backend CPU for argument #3 'index'

Open KaffeineCode opened this issue 5 years ago • 2 comments

I am getting this error and don't know how to solve it, can you help please?

Starting the training process ... Traceback (most recent call last): File "train_network.py", line 426, in main(parse_arguments()) File "train_network.py", line 420, in main use_matching_aware_dis=config.use_matching_aware_discriminator File "train_network.py", line 138, in train_networks fixed_embeddings = encoder(fixed_captions) File "C:\Users\Giacobbe\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 493, in call result = self.forward(*input, **kwargs) File "D:\Download\T2F-master\T2F-master\implementation\networks\TextEncoder.py", line 42, in forward output, (_, _) = self.network(x) File "C:\Users\Giacobbe\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 493, in call result = self.forward(*input, **kwargs) File "C:\Users\Giacobbe\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\container.py", line 92, in forward input = module(input) File "C:\Users\Giacobbe\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 493, in call result = self.forward(*input, **kwargs) File "C:\Users\Giacobbe\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\sparse.py", line 117, in forward self.norm_type, self.scale_grad_by_freq, self.sparse) File "C:\Users\Giacobbe\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\functional.py", line 1506, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: Expected object of backend CUDA but got backend CPU for argument #3 'index'

KaffeineCode avatar Jun 15 '19 14:06 KaffeineCode

I fixed this by changing fixed_embeddings = encoder(fixed_captions) line to fixed_embeddings = encoder(fixed_captions.to(device))

But im not sure if this is a good way to solve this error since I get some other errors after this. But you may try.

ulucsahin avatar Oct 27 '19 14:10 ulucsahin

I fixed this by changing fixed_embeddings = encoder(fixed_captions) line to fixed_embeddings = encoder(fixed_captions.to(device))

But im not sure if this is a good way to solve this error since I get some other errors after this. But you may try.

It's useful. Thanks a lot.

jenfung avatar Nov 03 '20 08:11 jenfung