如何解决图网络如何将 MNIST 数据转化为概率向量?
我正在分析 pytorch-geometric 库中的示例,我真的很想了解它,而且我有一个非常精确的问题。 图网络如何将MNIST数据转化为pytorch几何中的概率向量? 具体什么时候做? 以下是归纳训练中使用的示例代码:
def normalized_cut_2d(edge_index,pos):
row,col = edge_index
edge_attr = torch.norm(pos[row] - pos[col],p=2,dim=1)
return normalized_cut(edge_index,edge_attr,num_nodes=pos.size(0))
class GCN1(torch.nn.Module):
def __init__(self,d):
print(d.num_features)
super(GCN1,self).__init__()
self.conv1 = SplineConv(d.num_features,32,dim=2,kernel_size=5)
self.conv2 = SplineConv(32,64,kernel_size=5)
self.fc1 = torch.nn.Linear(64,128)
self.fc2 = torch.nn.Linear(128,d.num_classes)
def forward(self,data):
data.x = F.elu(self.conv1(data.x,data.edge_index,data.edge_attr))
weight = normalized_cut_2d(data.edge_index,data.pos)
cluster = graclus(data.edge_index,weight,data.x.size(0))
data.edge_attr = None
data = max_pool(cluster,data,transform=transform)
data.x = F.elu(self.conv2(data.x,data.x.size(0))
x,batch = max_pool_x(cluster,data.x,data.batch)
x = global_mean_pool(x,batch)
x = F.elu(self.fc1(x))
x = F.dropout(x,training=self.training)
return F.log_softmax(self.fc2(x),dim=1)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。