“DGLGraph.apply_edges”的使用和“DGLGraph.send_and_recv” API(计算消息)作为“DGLGraph.send”的替代和“DGLGraph.recv

发布于 2025-01-20 20:01:00 字数 2079 浏览 1 评论 0 原文

我正在使用DGL(用于图表上深度学习的Python软件包)来定义图,定义图形卷积网络(GCN)和火车。

我遇到了一个问题,我已经处理了两个星期。 我根据下面的链接开发了我的GCN代码:

我在上述代码的这一部分面临错误:

class GCNLayer(nn.Module): def init(self, in_feats, out_feats): super(GCNLayer, self).init() self.linear = nn.Linear(in_feats, out_feats)

def forward(self, g, inputs):
    # g is the graph and the inputs is the input node features
    # first set the node features
    g.ndata['h'] = inputs
    # trigger message passing on all edges
    g.send(g.edges(), gcn_message)
    # trigger aggregation at all nodes
    g.recv(g.nodes(), gcn_reduce)
    # get the result node features
    h = g.ndata.pop('h')
    # perform linear transformation
    return self.linear(h)

我在下面遇到一个错误:

dgl._ffi.base.DGLError: DGLGraph.send is deprecated. As a replacement, use DGLGraph.apply_edges API to compute messages as edge data. Then use DGLGraph.send_and_recv and set the message function as dgl.function.copy_e to conduct message aggregation*

在错误的指导下,我想知道如何使用dglgraph.apply_edges “ dglgraph.send” 命令中的不是dglgraph.send?

,我们有2个参数“ g.edges()” “ gcn_message”

如何将这些参数转换为“ dglgraph.apply_edges” 的参数()根据此

另外,“ dglgraph.send_and_recv”

“ dglgraph.recv”中 的同一问题。 “ gcn_reduce”

。 redy_func,apply_node_func = none,eType = none,intplace = false = false)” (根据此 link )?

如果您能帮助我解决这个巨大的挑战。

谢谢

I'm using DGL (Python package dedicated to deep learning on graphs) for training of defining a graph, defining Graph Convolutional Network (GCN) and train.

I faced a problem which I’m dealing with for two weeks.
I developed my GCN code based on the link below:

enter link description here

I’m facing an error for this part of the above mentioned code:

class GCNLayer(nn.Module): def init(self, in_feats, out_feats): super(GCNLayer, self).init() self.linear = nn.Linear(in_feats, out_feats)

def forward(self, g, inputs):
    # g is the graph and the inputs is the input node features
    # first set the node features
    g.ndata['h'] = inputs
    # trigger message passing on all edges
    g.send(g.edges(), gcn_message)
    # trigger aggregation at all nodes
    g.recv(g.nodes(), gcn_reduce)
    # get the result node features
    h = g.ndata.pop('h')
    # perform linear transformation
    return self.linear(h)

I’m getting an error below:

dgl._ffi.base.DGLError: DGLGraph.send is deprecated. As a replacement, use DGLGraph.apply_edges API to compute messages as edge data. Then use DGLGraph.send_and_recv and set the message function as dgl.function.copy_e to conduct message aggregation*

As it is guided in the error, I wonder to know how can I use DGLGraph.apply_edges instead of DGLGraph.send?

In "DGLGraph.send" command we have 2 arguments "g.edges()" and "gcn_message".

How these arguments can be converted to the arguments required for "DGLGraph.apply_edges" which are (func, edges=‘ALL’, etype=None, inplace=False ) (According to this link?

Also, the same question for "DGLGraph.send_and_recv".

In "DGLGraph.recv" we had 2 arguments "g.nodes()" and "gcn_reduce".

How these arguments can be converted to the arguments required for "DGLGraph.send_and_recv" which are "(edges, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False)" (According to this link)?

I would be very grateful if you can help me with this big challenge.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2025-01-27 20:01:00

DGLGraph.apply_edges(func, Edges='ALL', etype=None, inplace=False) 用于在 'edges' 中的所有边上使用函数 'func' 来更新边特征。

DGLGraph.send_and_recv(edges, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False) 用于传递消息、减少消息并更新 'edges' 中所有边的节点特征。

要使您的转发方法发挥作用,您可以更新您的代码,如下所示

def forward(self, g, inputs):
    g.ndata['h'] = inputs
    g.send_and_recv(g.edges(), fn.copy_src("h", "m"), fn.sum("m", "h"))
    h = g.ndata.pop("h")

    return self.linear(h)

您可以使用您自己的 message_func (消息生成)和 reduce_func (消息聚合)来满足您的目的。

DGLGraph.apply_edges(func, edges='ALL', etype=None, inplace=False) is used to update edge features using the function 'func' on all the edges in 'edges'.

DGLGraph.send_and_recv(edges, message_func, reduce_func, apply_node_func=None, etype=None, inplace=False) is used to pass messages, reduce messages and update the node features for all the edges in 'edges'.

To get your forward method to work you can update your code as below

def forward(self, g, inputs):
    g.ndata['h'] = inputs
    g.send_and_recv(g.edges(), fn.copy_src("h", "m"), fn.sum("m", "h"))
    h = g.ndata.pop("h")

    return self.linear(h)

You can use your own message_func (message generation) and reduce_func (message aggregation) to fit your purpose.

—━☆沉默づ 2025-01-27 20:01:00

尝试下面的代码,它可能会解决您的问题

def forward(self, g, inputs):
    g.ndata['h'] = inputs
    g.send_and_recv(g.edges(), gcn_message, gcn_reduce)
    h = g.ndata.pop('h')
    return self.linear(h)

try code below, it may solve your problem

def forward(self, g, inputs):
    g.ndata['h'] = inputs
    g.send_and_recv(g.edges(), gcn_message, gcn_reduce)
    h = g.ndata.pop('h')
    return self.linear(h)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文