class STHSL(nn.Module): def __init__(self): super(STHSL, self).__init__() self.dimConv_in = nn.Conv3d(1, args.latdim, kernel_size=1, padding=0, bias=True) self.dimConv_local = nn.Conv2d(args.latdim, 1, kernel_size=1, padding=0, bias=True) self.dimConv_global = nn.Conv2d(args.latdim, 1, kernel_size=1, padding=0, bias=True) self.spa_cnn_local1 = spa_cnn_local(args.latdim, args.latdim) self.spa_cnn_local2 = spa_cnn_local(args.latdim, args.latdim) self.tem_cnn_local1 = tem_cnn_local(args.latdim, args.latdim) self.tem_cnn_local2 = tem_cnn_local(args.latdim, args.latdim) self.Hypergraph_Infomax = Hypergraph_Infomax() self.tem_cnn_global1 = tem_cnn_global(args.latdim, args.latdim, 9) self.tem_cnn_global2 = tem_cnn_global(args.latdim, args.latdim, 9) self.tem_cnn_global3 = tem_cnn_global(args.latdim, args.latdim, 9) self.tem_cnn_global4 = tem_cnn_global(args.latdim, args.latdim, 6) self.local_tra = Transform_3d() self.global_tra = Transform_3d() def forward(self, embeds_true, neg): embeds_in_global = self.dimConv_in(embeds_true.unsqueeze(1)) DGI_neg = self.dimConv_in(neg.unsqueeze(1)) embeds_in_local = embeds_in_global.permute(0, 3, 1, 2, 4).contiguous().view(-1, args.latdim, args.row, args.col, 4) spa_local1 = self.spa_cnn_local1(embeds_in_local) spa_local2 = self.spa_cnn_local2(spa_local1) spa_local2 = spa_local2.view(-1, args.temporalRange, args.latdim, args.areaNum, args.cateNum).permute(0, 2, 3, 1, 4) tem_local1 = self.tem_cnn_local1(spa_local2) tem_local2 = self.tem_cnn_local2(tem_local1) eb_local = tem_local2.mean(3) eb_tra_local = self.local_tra(tem_local2) out_local = self.dimConv_local(eb_local).squeeze(1) hy_embeds, Infomax_pred = self.Hypergraph_Infomax(embeds_in_global, DGI_neg) tem_global1 = self.tem_cnn_global1(hy_embeds) tem_global2 = self.tem_cnn_global2(tem_global1) tem_global3 = self.tem_cnn_global3(tem_global2) tem_global4 = self.tem_cnn_global4(tem_global3) eb_global = tem_global4.squeeze(3) eb_tra_global = self.global_tra(tem_global4) out_global = self.dimConv_global(eb_global).squeeze(1) return out_local, eb_tra_local, eb_tra_global, Infomax_pred, out_global
时间: 2023-11-30 17:02:16 浏览: 194
pytorch构建网络模型的4种方法
这是一个使用 PyTorch 实现的神经网络模型的定义类。在这个模型中,输入数据包含一个真实的嵌入向量和一个负样本向量。模型将这些数据作为输入,并执行一系列操作来生成输出。具体来说,模型包含了一些卷积和全连接层,以及一些变换和聚合操作。这些操作包括将嵌入向量转换为局部和全局表示,通过超图信息最大化来学习嵌入向量的表示,以及对局部和全局表示进行转换和聚合。最终,模型的输出包括局部和全局表示,超图信息最大化的预测结果,以及对局部和全局表示进行卷积后得到的输出。
阅读全文