super(GCNConv, self).__init__(aggr='add') # "Add" aggregation. # super(GCNConv, self).__init__(aggr='max') # "Max" aggregation. self.weight = torch.nn.Parameter(torch.Tensor(in_channels, out_channels)) if bias: self.bias = torch.nn.Parameter(torch.Tensor(out_channels)) else:...
将上面例子中的torch.nn.Linear替换成torch_geometric.nn.GCNConv,我们就可以得到一个GCN图神经网络,如下方代码所示: from torch_geometric.nn import GCNConv class GCN(torch.nn.Module): def __init__(self, hidden_channels): super(GCN, self).__init__() torch.manual_seed(12345) self.conv1 = GCN...
from torch_geometric.nn import GCNConvimport torch.nn.functional as Fclass GCN(torch.nn.Module): def __init__(self): super().__init__() self.conv1 = GCNConv(dataset.num_node_features, 16) self.conv2 = GCNConv(16, dataset.num_classes) def forward(self, data): ...
我应用了 GCN 进行图二元分类,我想使用 GNNexplainer 来解释预测。但我不知道如何在我的模型上应用 GNNexplainer。这是我的 GCN 模型代码: class GCNModel(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim): super(GCNModel, self).__init__() self.conv1 = GCNConv(input_dim, ...
importtorchimporttorch.nn.functionalasFfromtorch_geometric.nnimportGCNConvclassGNN(torch.nn.Module):def__init__(self,in_channels,out_channels):super().__init__()self.conv1=GCNConv(in_channels,64)self.conv2=GCNConv(64,out_channels)defforward(self,x,edge_index):x=self.conv1(x,edge_index...
Have a question about this project?Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Sign up for GitHub By clicking “Sign up for GitHub”, you agree to ourterms of serviceandprivacy statement. We’ll occasionally send you account related ema...
from torch_geometric.nn import GATConv, GraphConv, TopKPooling class CustomeModel(torch.nn.Module): def __init__(self): super(CustomeModel, self).__init__() self.gcn_layer = GraphConv(512, 256) def forward(self, x1, x2): x, edge_index = x1, x2 x = self.gcn_layer(x, edge...
Source File: seal_link_pred.py From pytorch_geometric with MIT License 6 votes def forward(self, x, edge_index, batch): xs = [x] for conv in self.convs: xs += [torch.tanh(conv(xs[-1], edge_index))] x = torch.cat(xs[1:], dim=-1) # Global pooling. x = global_sort_...
Source File: test_gcn_conv.py From pytorch_geometric with MIT License 5 votes def test_gcn_conv_with_sparse_input_feature(): x = torch.sparse_coo_tensor(indices=torch.tensor([[0, 0], [0, 1]]), values=torch.tensor([1., 1.]), size=torch.Size([4, 16])) edge_index = torch...
data.edge_attr, torch.Tensor([[1,1,0], [1,1,0.5]]), atol=1e-04) 开发者ID:rusty1s,项目名称:pytorch_geometric,代码行数:24,代码来源:test_polar.py 示例6: test_permuted_global_pool ▲点赞 6▼ # 需要导入模块: import torch [as 别名]# 或者: from torch importallclose[as 别名]deftest...