Pytorch GlobalAttention forward() 缺少 2 个必需的位置参数:“edge_index”和“batch”

问题描述

测试 GlobalAttention 类并获取 forward() 缺少 2 个必需的位置参数:'edge_index' 和 'batch' 错误

class GLOGCN(nn.Module):
    def __init__(self,gcn,hidden_channels):
        super(GLOGCN,self).__init__()
        self.gatt= GlobalAttention(gcn)
        self.lin = Linear(hidden_channels,dataset.num_classes)

    def forward(self,x,batch):
        w=self.gatt(x,batch)
        x=torch.mm(w,x)
        x = self.lin(x)
        return x

class GCN(torch.nn.Module):
    ...

model=GCN(..)
g_model = GLOGCN(model,hidden_channels=1000)

x = model(data.x,data.edge_index,data.batch)  
g_out=g_model(x,data.batch)

注意 GlobalAttention 需要两个参数(x,batch)基于文档https://pytorch-geometric.readthedocs.io/en/latest/modules/nn.html#torch_geometric.nn.glob.GlobalAttention

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)