当前位置:网站首页>torch_ About the geometric Mini batch
torch_ About the geometric Mini batch
2022-06-12 13:06:00 【Dongxuan】
Mini-batches
PyG Create a sparse block diagonal connection matrix (defined by edge_index) , Splice the features of nodes and labels at the node level .
So in one_batch in The number of nodes is different . This is different from the previous batch Different , In the past, we used to cut the cake evenly . Each... Entered in this library batch The total number of nodes is different

This special treatment mini batch The way , Use another special class :torch_geometric.loader.DataLoader,
from torch_geometric.datasets import TUDataset
from torch_geometric.loader import DataLoader
dataset = TUDataset(root='/tmp/ENZYMES', name='ENZYMES', use_node_attr=True)
loader = DataLoader(dataset, batch_size=32, shuffle=True)
for batch in loader:
batch
>>> DataBatch(batch=[1082], edge_index=[2, 4066], x=[1082, 21], y=[32])
batch.num_graphs
>>> 32He spliced the graph data , Final 32 Graph data , Spliced together into a owning assembly 1082 Nodes ,21 The characteristics of dimensions ,4066 Graph of edges batch data
torch_geometric.data.Batch Class inheritance torch_geometric.data.Data And contains additional properties Pointer array , Specify the figure number of each node :batch.
batch=[0⋯01⋯n−2n−1⋯n−1]⊤( That is to say 0,...,31)
Calculate the average value of each dimension of the node characteristics of each graph
from torch_scatter import scatter_mean
from torch_geometric.datasets import TUDataset
from torch_geometric.loader import DataLoader
dataset = TUDataset(root='/tmp/ENZYMES', name='ENZYMES', use_node_attr=True)
loader = DataLoader(dataset, batch_size=32, shuffle=True)
for data in loader:
data
>>> DataBatch(batch=[1082], edge_index=[2, 4066], x=[1082, 21], y=[32])
data.num_graphs
>>> 32
x = scatter_mean(data.x, data.batch, dim=0)
x.size()
>>> torch.Size([32, 21])You can learn more about the internal batching procedure of PyG, e.g., how to modify its behaviour, here. For documentation of scatter operations, we refer the interested reader to the torch-scatterdocumentation.
Data Transforms
Data preprocessing method ( Data to enhance , Data transformation ), You can also link multiple preprocessing methods , Analogy and picture operation , First crop, Normalization and so on .
Transforms are a common way in torchvision to transform images and perform augmentation. PyG comes with its own transforms, which expect a Data object as input and return a new transformed Data object. Transforms can be chained together using torch_geometric.transforms.Compose and are applied before saving a processed dataset on disk (pre_transform) or before accessing a graph in a dataset (transform).
transforms on the ShapeNet dataset (containing 17,000 3D shape point clouds and per point labels from 16 shape categories).
The following feeling is extracted Airplane A sample set of
from torch_geometric.datasets import ShapeNet
dataset = ShapeNet(root='/tmp/ShapeNet', categories=['Airplane'])
dataset[0]
>>> Data(pos=[2518, 3], y=[2518])We can convert the point cloud dataset into a graph dataset by generating nearest neighbor graphs from the point clouds via transforms:
import torch_geometric.transforms as T
from torch_geometric.datasets import ShapeNet
dataset = ShapeNet(root='/tmp/ShapeNet', categories=['Airplane'],
pre_transform=T.KNNGraph(k=6))
dataset[0]
>>> Data(edge_index=[2, 15108], pos=[2518, 3], y=[2518])Note
We use the pre_transform to convert the data before saving it to disk (leading to faster loading times). Note that the next time the dataset is initialized it will already contain graph edges, even if you do not pass any transform. If the pre_transform does not match with the one from the already processed dataset, you will be given a warning.
In addition, we can use the transform argument to randomly augment a Data object, e.g., translating each node position by a small number:
import torch_geometric.transforms as T
from torch_geometric.datasets import ShapeNet
dataset = ShapeNet(root='/tmp/ShapeNet', categories=['Airplane'],
pre_transform=T.KNNGraph(k=6),
transform=T.RandomTranslate(0.01))
dataset[0]
>>> Data(edge_index=[2, 15108], pos=[2518, 3], y=[2518])You can find a complete list of all implemented transforms at torch_geometric.transforms.
边栏推荐
- torch_geometric mini batch 的那些事
- Further understanding of the network
- C#DBHelper_FactoryDB_GetConn
- [database] Navicat -- Oracle database creation
- Binary tree (serialization)
- Buu question brushing record - 7
- Array -- fancy traversal technique of two-dimensional array
- 403 you don't have permission to access this resource
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- 【云原生 | Kubernetes篇】Kubernetes 网络策略(NetworkPolicy)
猜你喜欢
随机推荐
Binary tree (construction)
Embedded system hardware composition - embedded system hardware architecture
IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V
VNCTF2022 [WEB]
构建嵌入式系统软件开发环境-建立交叉编译环境
C语言【23道】经典面试题【下】
What is the function tag? Article to understand its role and its best practices
JVM 运行时参数
嵌入式系统硬件构成-嵌入式系统硬件体系结构
【云原生 | Kubernetes篇】Kubernetes 网络策略(NetworkPolicy)
Experience and learning path of introductory deep learning and machine learning
[HXBCTF 2021]easywill
2022 ARTS|Week 23
多源BFS问题 模板(附题)
Volume mount and mirror creation
嵌入式系統硬件構成-基於ARM的嵌入式開發板介紹
深度学习的多个 loss 是如何平衡的?
[wechat applet development] Part 1: development tool installation and program configuration
移动应用出海的“新大陆”
C#DBHelper_FactoryDB_GetConn









