pygcn
pygcn copied to clipboard
TypeError: expected torch.FloatTensor (got torch.LongTensor)
Hi tkipf, thank you for sharing the source code.
I ran it on Pytorch 0.4.0 and Python 2.7, but got this type error. However, if I used python 3.5 it can be run. Loading cora dataset...
Traceback (most recent call last):
File "train.py", line 49, in <module>
dropout=args.dropout)
File "build/bdist.linux-x86_64/egg/pygcn/models.py", line 11, in __init__
self.gc2 = GraphConvolution(nhid, nclass)
File "build/bdist.linux-x86_64/egg/pygcn/layers.py", line 43, in __init__
self.bias = Parameter(torch.Tensor(out_features))
TypeError: expected torch.FloatTensor (got torch.LongTensor)
May I ask how to solve this issue? Thank you
PyTorch 0.4.0 is currently not supported (see README). Pytorch 0.2.0 is the officially supported version, however 0.3.0 might work as well.
On line 47 of train.py you need to cast (labels.max()+1) as an int instead on a torch.LongTensor. so switch
model = GCN(nfeat=features.shape[1],
nhid=args.hidden,
nclass=labels.max() + 1,
dropout=args.dropout)
to
model = GCN(nfeat=features.shape[1],
nhid=args.hidden,
nclass=(labels.max() + 1).data.numpy(),
dropout=args.dropout)
Now if you use Pytorch 0.4 with the updated merge (that @nkolot referenced to) this issue is solved
(by having labels.max().item()
).