最近在学习图神经网络,需要安装pytorch-geometric。
Pytorch-gemetric适配 python3.8-3.11版本
- 首先创建python3.8环境
conda create --name PyG python=3.8
conda activate PyG
- 安装PyTorch
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
- 安装pytorch-geometric
pip install torch-geometric
- 安装测试
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.version.cuda)
from torch_geometric.nn import GCNConv
class GCN(torch.nn.Module):
def __init__(self, hidden_channels):
super().__init__()
torch.manual_seed(1234567)
self.conv1 = GCNConv(1433, hidden_channels)
self.conv2 = GCNConv(hidden_channels, 7)
def forward(self, x, edge_index):
x = self.conv1(x, edge_index)
x = x.relu()
x = F.dropout(x, p=0.5, training=self.training)
x = self.conv2(x, edge_index)
return x
model = GCN(hidden_channels=16)
print(model)
>>
True
8
11.6
GCN(
(conv1): GCNConv(1433, 16)
(conv2): GCNConv(16, 7)
)