DGL代码如何转换成MindSpore代码?
收藏回复举报
DGL代码如何转换成MindSpore代码?
t('forum.solved') 已解决
发表于2024-09-13 11:49:23
0 查看
def load_one_graph(fn, data):
    # Create the graph using the edges and number of nodes
    edges = tuple(data['graph']['edges'])
    num_nodes = data['graph']['num_nodes']
    dgl_graph = dgl.graph(edges, num_nodes=num_nodes)

    # Convert node attributes to PyTorch tensors and add them to the graph
    node_attributes = data['graph_face_attr']
    node_attributes = np.array(node_attributes)
    node_attributes = torch.from_numpy(node_attributes).type(torch.float32)
    dgl_graph.ndata["x"] = node_attributes

    # Convert and add node grid attributes if they are present
    node_grid_attributes = data['graph_face_grid']
    if len(node_grid_attributes) > 0:
        node_grid_attributes = np.array(node_grid_attributes)
        node_grid_attributes = torch.from_numpy(node_grid_attributes).type(torch.float32)
        dgl_graph.ndata["grid"] = node_grid_attributes

    # Convert edge attributes to PyTorch tensors and add them to the graph
    edge_attributes = data['graph_edge_attr']
    edge_attributes = np.array(edge_attributes)
    edge_attributes = torch.from_numpy(edge_attributes).type(torch.float32)
    dgl_graph.edata["x"] = edge_attributes

    # Convert and add edge grid attributes if they are present
    edge_grid_attributes = data['graph_edge_grid']
    if len(edge_grid_attributes) > 0:
        edge_grid_attributes = np.array(edge_grid_attributes)
        edge_grid_attributes = torch.from_numpy(edge_grid_attributes).type(torch.float32)
        dgl_graph.edata["grid"] = edge_grid_attributes
    
    sample = {"graph": dgl_graph, "filename": fn}
    return sample

上述DGL创建图网络的代码需要如何转换成MindSpore的代码?

本帖最后由 匿名用户2024/10/08 14:44:40 编辑

我要发帖子