jasonseu / cnn_graph.pytorch

A PyTorch implementation of paper "Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering"
11 stars 2 forks source link

Dear author, Hello.I am running your code, but there is always an error when running train. Py. The error content is shown below. #1

Open zhuyuan804 opened 4 years ago

zhuyuan804 commented 4 years ago

VALIDATION - loss: 0.0000: 0%| | 0/67 [00:00<?, ?it/s]<class 'int'> Traceback (most recent call last): File "C:/Users/01/Desktop/GNN(图神经网络)/算法实践/GCN/cnn_graph.pytorch-master/train.py", line 159, in trainer.run() File "C:/Users/01/Desktop/GNN(图神经网络)/算法实践/GCN/cnn_graph.pytorch-master/train.py", line 71, in run acc, mloss = self.validation(epoch) File "C:/Users/01/Desktop/GNN(图神经网络)/算法实践/GCN/cnn_graph.pytorch-master/train.py", line 107, in validation loss = self.criterion(logits, labels.cuda()) File "D:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "D:\Anaconda\lib\site-packages\torch\nn\modules\loss.py", line 948, in forward ignore_index=self.ignore_index, reduction=self.reduction) File "D:\Anaconda\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:\Anaconda\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

jasonseu commented 4 years ago

VALIDATION - loss: 0.0000: 0%| | 0/67 [00:00<?, ?it/s]<class 'int'> Traceback (most recent call last): File "C:/Users/01/Desktop/GNN(图神经网络)/算法实践/GCN/cnn_graph.pytorch-master/train.py", line 159, in trainer.run() File "C:/Users/01/Desktop/GNN(图神经网络)/算法实践/GCN/cnn_graph.pytorch-master/train.py", line 71, in run acc, mloss = self.validation(epoch) File "C:/Users/01/Desktop/GNN(图神经网络)/算法实践/GCN/cnn_graph.pytorch-master/train.py", line 107, in validation loss = self.criterion(logits, labels.cuda()) File "D:\Anaconda\lib\site-packages\torch\nn\modules\module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "D:\Anaconda\lib\site-packages\torch\nn\modules\loss.py", line 948, in forward ignore_index=self.ignore_index, reduction=self.reduction) File "D:\Anaconda\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:\Anaconda\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

Hello, thanks for the interest to the codebase. It looks like a variable type related error. I have checked the code and it runs well. The error reported by you is occurred in the line 107, but it's actually the line 105 in my code. So, have you made any changes in the code? By the way, what's your pytorch version?

zhuyuan804 commented 4 years ago

I just make a few minor adjustments, like looking at the function type, and it doesn't affect the whole thing.My Python=3.7,Pytorch=1.6.Is it because of problems with the latest version of Pytorch?Also, I think the problem is at line 69, where the type of epoch is Int and the validation function defined is long, and when I print(epoch), The result is just 0.I wondered if it was possible to try to change the type of epoch to Long, but I tried a variety of methods without success.

jasonseu commented 4 years ago

I just make a few minor adjustments, like looking at the function type, and it doesn't affect the whole thing.My Python=3.7,Pytorch=1.6.Is it because of problems with the latest version of Pytorch?Also, I think the problem is at line 69, where the type of epoch is Int and the validation function defined is long, and when I print(epoch), The result is just 0.I wondered if it was possible to try to change the type of epoch to Long, but I tried a variety of methods without success.

I have tested with pytorch=1.6 and anything is ok. I can't get your means that validation function defined is long, but I believe it is unlikely the problem caused by the type of epoch. According to your reported error, I think it is caused by the type conflict of labels. I suggest that you can try to convert the type of labels to Torch.LongTensor, it maybe works, although everything runs well in my code.

zhuyuan804 commented 4 years ago

There is no casting required to convert an int to a long, which is a relative implicit cast and is done in the background.I guess my computer system can't convert int to long in the background.