ne7ermore / torch-light

Deep-learning by using Pytorch. Basic nns like Logistic, CNN, RNN, LSTM and some examples are implemented by complex model.
MIT License
535 stars 201 forks source link

run train.py error #1

Closed arixlin closed 6 years ago

arixlin commented 6 years ago

When I run train.py, show type error:

Traceback (most recent call last): File "D:/github/torch_light/Image-Cap/train.py", line 235, in loss = pre_train_actor() File "D:/github/torch_light/Image-Cap/train.py", line 120, in pre_trainactor target, = actor(hidden, labels) File "D:\Anaconda3\envs\python36\lib\site-packages\torch\nn\modules\module.py", line 357, in call result = self.forward(*input, *kwargs) File "D:\github\torch_light\Image-Cap\model.py", line 91, in forward emb_enc = self.lookup_table(labels[:, i]) File "D:\Anaconda3\envs\python36\lib\site-packages\torch\nn\modules\module.py", line 357, in call result = self.forward(input, **kwargs) File "D:\Anaconda3\envs\python36\lib\site-packages\torch\nn\modules\sparse.py", line 103, in forward self.scale_grad_by_freq, self.sparse File "D:\Anaconda3\envs\python36\lib\site-packages\torch\nn_functions\thnn\sparse.py", line 57, in forward output = torch.index_select(weight, 0, indices) TypeError: torch.index_select received an invalid combination of arguments - got (torch.cuda.FloatTensor, int, !torch.cuda.IntTensor!), but expected (torch.cuda.FloatTensor source, int dim, torch.cuda.LongTensor index)

ne7ermore commented 6 years ago

make sure the labels` data type is torch.cuda.LongTensor i saw your log that something wrong in the labels' datatype (torch.cuda.IntTensor)

File "D:/github/torch_light/Image-Cap/train.py", line 235, in
target, _ = actor(hidden, labels)
arixlin commented 6 years ago

@ne7ermore hi, I don't modify Image-Cap/train.py, i saw return labels is int list.
thx!

ne7ermore commented 6 years ago

what did you get from the data_loader. Data_loader try to get the labels` datatype form this line below i show

https://github.com/ne7ermore/torch_light/blob/master/Image-Cap/data_loader.py#L41

or you can try this simple test code: https://github.com/ne7ermore/torch_light/blob/master/Image-Cap/data_loader.py#L58

img, labels = next(training_data) from https://github.com/ne7ermore/torch_light/blob/master/Image-Cap/data_loader.py#L66
print(labels)
arixlin commented 6 years ago

@ne7ermore Hi, when I run Image-Cap/data_loader.py, labels is [torch.cuda.IntTensor of size 2x16 (GPU 0)], Image-Cap/train.py#115 labels is [torch.cuda.IntTensor of size 32x17 (GPU 0)] thx!

ne7ermore commented 6 years ago

I guess sth change between pytorch`s versions my version is 0.3.1 and i have added long() function to change the datatype of labels

https://github.com/ne7ermore/torch_light/blob/master/Image-Cap/data_loader.py#L46

please try again :)

if found error again, show the pytorch's version which you used

arixlin commented 6 years ago

@ne7ermore Thank you so much, it works out! train.py has been running!