华为计算微信公众号
昇腾AI开发者公众号
华为计算微博
华为计算今日头条
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 编辑
我要发帖子
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的代码?