当前位置:网站首页>import torch_ Data view of geometric
import torch_ Data view of geometric
2022-06-12 13:05:00 【Dongxuan】
Welcome to the column torch_geometric

Data Handling of Graphs
A processing library torch_geometric. I also found this class when watching others share code , It is out of place with the usual class .
torch_geometric.data.Data, It can simply represent a graph data . It contains the following properties
data.x: Node characteristics [ Number of nodes , Node feature dimension ][num_nodes, num_node_features]data.edge_index: It has to be this shape[2, num_edges]and typetorch.long. Must be serial number . First of all, yours. data.x It determines the order of each node index . Then specify the edges according to this sequence number , The first row of the edge is the source node , The second node is the target node .data.edge_attr: Feature representation of edges[num_edges, num_edge_features]data.y: A label for graph data , It can be a node classification task[num_nodes, *], It can also be a graph classification task[1, *]data.pos: The coordinates of point , For example, the point is in the three-dimensional coordinate system ,num_dimensions Namely 3[num_nodes, num_dimensions]
We can expand Data List of properties , For example data.face To express 3d In the clouds face The concept of . Use the sequence number of points to specify which three points form a face . [3, num_faces] and type torch.long.
A bunch of runnable examples
Example ①
import torch
from torch_geometric.data import Data
edge_index = torch.tensor([[0, 1, 1, 2],
[1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index)
>>> Data(edge_index=[2, 4], x=[3, 1])perhaps edge_index The second way to write
Example ②
import torch
from torch_geometric.data import Data
edge_index = torch.tensor([[0, 1],
[1, 0],
[1, 2],
[2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index.t().contiguous())
>>> Data(edge_index=[2, 4], x=[3, 1])Let's output the built graph data information .
print(data.keys)
>>> ['x', 'edge_index']
print(data['x'])
>>> tensor([[-1.0],
[0.0],
[1.0]])
for key, item in data:
print(f'{key} found in data')
>>> x found in data
>>> edge_index found in data
'edge_attr' in data
>>> False
data.num_nodes
>>> 3
data.num_edges
>>> 4
data.num_node_features
>>> 1
data.has_isolated_nodes()
>>> False
data.has_self_loops()
>>> False
data.is_directed()
>>> False
# Transfer data object to GPU.
device = torch.device('cuda')
data = data.to(device)边栏推荐
- Five ways to quickly download large files from Google cloud disk
- 5V升压到12.6V的锂电池充电IC芯片方案FS4062B
- Getting to know blob objects
- Known as the next generation monitoring system! See how awesome it is
- 创新实训(十)高级界面美化
- Further understanding of the network
- Microsoft Word tutorial, how to insert a header or footer in word?
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- 【微信小程序开发】第1篇:开发工具安装及程序配置
- LeetCode滑动窗口刷题总结
猜你喜欢

LeetCode滑动窗口刷题总结

Stm32f1 and stm32cubeide programming examples - device driver -eeprom-at24c256 driver

Array -- seven array topics with double pointer technique

The goods are full. You must take this knowledge

从基础到源码统统帮你搞定,技术详细介绍

关于派文的问题

Known as the next generation monitoring system! See how awesome it is

镜像扫描工具预研

Pytoch official fast r-cnn source code analysis (I) -- feature extraction

import torch_geometric 的Data 查看
随机推荐
Microsoft Word 教程,如何在 Word 中插入页眉或页脚?
嵌入式系统概述2-嵌入式系统组成和应用
VNCTF2022 [WEB]
Robot Jacobian solution
用PyTorch进行语义分割
Getting to know blob objects
Help you with everything from the basics to the source code. Introduce the technology in detail
【VIM】. Vimrc configuration, vundle and youcompleteme have been installed
Detect whether the vector has an intersection
Software construction 03 regular expression
leetcode 47. Permutations II 全排列 II(中等)
STM32F1与STM32CubeIDE编程实例-设备驱动-DHT11温度温度传感器驱动
Redis消息队列重复消费问题
"New continent" of mobile application going to sea
Openmax (OMX) framework
Five ways to quickly download large files from Google cloud disk
[cloud native | kubernetes] kubernetes networkpolicy
Constant time delete / find any element in array
深度学习的多个 loss 是如何平衡的?
Binary tree (program)