Skip to content

RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward #68

@SunforYou0

Description

@SunforYou0

Error information:
Using backend: pytorch
Namespace(backup=False, batch_size=128, dataset='YAGO', dropout=0.5, gpu=0, grad_norm=1.0, lr=0.001, max_epochs=20, maxpool=1, model=0, n_hidden=200, num_k=1000, raw=False, rnn_layers=1, seq_len=10, valid=False, valid_every=1)
start training...
D:\MyProjects\PycharmProjects\RE-Net-master\RE-Net-master\utils.py:214: UserWarning: This overload of nonzero is deprecated:
nonzero(Tensor input, *, Tensor out)
Consider using one of the following signatures instead:
nonzero(Tensor input, *, bool as_tuple) (Triggered internally at ..\torch\csrc\utils\python_arg_parser.cpp:766.)
num_non_zero = len(torch.nonzero(s_len))
Epoch 0001 | Loss 8.2041 | time 1205.2197
Epoch 0002 | Loss 3.9099 | time 1204.5098
Epoch 0003 | Loss 3.3134 | time 1195.3128
Epoch 0004 | Loss 3.0940 | time 1160.4676
Epoch 0005 | Loss 2.9595 | time 1142.0331
Epoch 0006 | Loss 2.8683 | time 1171.5391
Epoch 0007 | Loss 2.8052 | time 1289.8578
Epoch 0008 | Loss 2.7475 | time 1266.8438
Epoch 0009 | Loss 2.7018 | time 1227.6809
Epoch 0010 | Loss 2.6605 | time 1246.5386
Traceback (most recent call last):
File "D:\AnacondaEnv\renet\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "", line 1, in
File "D:\ProgramFiles\PyCharm 2020.3.4\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\ProgramFiles\PyCharm 2020.3.4\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/MyProjects/PycharmProjects/RE-Net-master/RE-Net-master/train.py", line 241, in
train(args)
File "D:/MyProjects/PycharmProjects/RE-Net-master/RE-Net-master/train.py", line 172, in train
ranks, loss = model.evaluate_filter(batch_data, (s_hist, s_hist_t), (o_hist, o_hist_t), global_model, total_data)
File "D:\MyProjects\PycharmProjects\RE-Net-master\RE-Net-master\model.py", line 388, in evaluate_filter
loss, sub_pred, ob_pred = self.predict(triplet, s_hist, o_hist, global_model)
File "D:\MyProjects\PycharmProjects\RE-Net-master\RE-Net-master\model.py", line 358, in predict
loss_sub = self.criterion(ob_pred.view(1, -1), o.view(-1))
File "D:\AnacondaEnv\renet\lib\site-packages\torch\nn\modules\module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\AnacondaEnv\renet\lib\site-packages\torch\nn\modules\loss.py", line 948, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File "D:\AnacondaEnv\renet\lib\site-packages\torch\nn\functional.py", line 2422, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "D:\AnacondaEnv\renet\lib\site-packages\torch\nn\functional.py", line 2218, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions