from torch_geometric.datasets import Planetoid dataset=Planetoid(root="tmp",name="Cora") #构建GCN import torch import torch.nn.functional as F from torch_geometric.nn import GCNConv, SAGEConv, GATConv 1.GCN class GCN_Net(torch.nn.Module): def __init__(self,features,hidden,classes):#特征。隐藏长度,输出的类别 super(GCN_Net,self).__init__() self.conv1=GCNConv(features,hidden)#第一层GCN self.conv2=GCNConv(hidden,classes)#第二层GCN def forward(self,data): x,edge_index=data.x,data.edge_index#节点属性和边的信息 x=self.conv1(x,edge_index)#第一层,输入x和边的信息 x=F.relu(x) x=F.dropout(x,training=self.training) x=self.conv2(x,edge_index) return F.log_softmax(x,dim=1)#按行做softmax归一化操作 device=torch.device("cuda" if torch.cuda.is_available() else "cpu" ) model=GCN_Net(dataset.num_node_features,16,dataset.num_classe