【PyG】windows下安装PyTorch Geometric

安装:

torch-geometric== 1.2.1
(最新版为1.4.3,注意各依赖包版本适配)

配置:

win10, cpu, python3.6.8, 无conda
torch≥1.1.0

遇到问题:

1.from torch_sparse import coalesce
ImportError: No module named ‘torch_sparse’

2.cannot install scatter, sparse, cluster packages

3.error: command ‘D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe’ failed with exit status 2

4.信息: 用提供的模式无法找到文件

5.error: option --cpu not recognized

试过但没有解决问题的方法

pip install --verbose --no-cache-dir torch-scatter
pip install --verbose --no-cache-dir torch-sparse
pip install --verbose --no-cache-dir torch-cluster
pip install --verbose --no-cache-dir torch-spline-conv
pip install torch-geometric

最后方法:选择合适版本

pip安装:
pip install torch-cluster == 1.2.4
pip install torch-geometric == 1.2.1
pip install torch-scatter == 1.1.2
pip install torch-sparse == 0.4.0
pip install torch-spline-conv == 1.0.6

(torch-sparse>0.4.0时安装出错)

应用

卷积层搭建:

from torch_geometric.nn import MessagePassing
	class MyConv(MessagePassing):

网络定义:

from torch_geometric.nn import MyConv
    class Net(torch.nn.Module):
    	def __init__(self):
        	super(Net, self).__init__()
        	self.conv1 = MyConv(in_channels, out_channels)

上手参考: 图神经网络库PyTorch geometric零基础上手教程 - 知乎.

你可能感兴趣的:(Python)