当前位置:网站首页>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.
边栏推荐
- leetcode 47. Permutations II 全排列 II(中等)
- Summary of question brushing in leetcode sliding window
- [wechat applet development] Part 1: development tool installation and program configuration
- 号称下一代监控系统!来看看它有多牛逼
- Binary tree (program)
- 功能标记是什么?一文了解它的作用,以及它的最佳实践
- Getting to know blob objects
- 创新实训(十二)项目总结
- Newton method for solving roots of polynomials
- Embedded system hardware composition - embedded system hardware architecture
猜你喜欢

单向环形链表实现约瑟夫环

2022 ARTS|Week 23

嵌入式系统概述2-嵌入式系统组成和应用

Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo
![[wechat applet development] Part 1: development tool installation and program configuration](/img/a8/f4dcbde295ba7cf738d878464b3af0.png)
[wechat applet development] Part 1: development tool installation and program configuration

嵌入式系统概述3-嵌入式系统的开发流程和学习基础、方法

Overview of embedded system 3- development process, learning basis and methods of embedded system

位图、布隆过滤器和哈希切分

成功定级腾讯T3-2,万字解析

功能标记是什么?一文了解它的作用,以及它的最佳实践
随机推荐
【刷题篇】超级洗衣机
[cloud native | kubernetes] kubernetes networkpolicy
OpenMAX (OMX)框架
在 Debian 10 上独立安装MySQL数据库
一行代码实现shell if else逻辑
B站分布式KV存储混沌工程实践
How to adapt the page size when iframe is embedded in a web page
Geek challenge 2021 Web
创新实训(十一)开发过程中的一些bug汇总
功能标记是什么?一文了解它的作用,以及它的最佳实践
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting bar plot, adding significance level and jitter points
多源BFS问题 模板(附题)
Detect whether the vector has an intersection
Hudi key generation
Image comparison function after registration itk:: checkerboardimagefilter
verilog-mode的简要介绍
ITK multiresolution image itk:: recursivemultiresolutionpyramidimagefilter
It is enough to read this article. Web Chinese development
Array -- fancy traversal technique of two-dimensional array
leetcode 47. Permutations II 全排列 II(中等)