我试图在图神经网络上实现一个回归。我看到的大多数例子都是这个领域的分类,到目前为止还没有回归的例子。我看到了一个用于分类的方法如下:从torch_geometric.nn导入GCNConv
class GCN(torch.nn.Module):
def __init__(self, hidden_channels):
super(GCN, self).__init__()
torch.manual_seed(12345)
self.conv1 = GCNConv(dataset.num_features, hidden_channels)
self.conv2 = GCNConv(hidden_channels, dataset.num_classes)
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)我试图为我的任务修改它,这基本上包括在一个有30个节点的网络上执行一个回归,每个节点都有3个功能,边缘有一个功能。
如果有人能给我举例子来做同样的事情,那将是非常有帮助的。
发布于 2021-12-09 08:42:50
添加线性层,不要忘记使用回归损失函数
class GCN(torch.nn.Module):
def __init__(self, hidden_channels):
super(GCN, self).__init__()
torch.manual_seed(12345)
self.conv1 = GCNConv(dataset.num_features, hidden_channels)
self.conv2 = GCNConv(hidden_channels, dataset.num_classes)
self.linear1 = torch.nn.Linear(100,1)
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)
x = self.linear1(x)
return xhttps://stackoverflow.com/questions/68202388
复制相似问题