torch_geometric.transforms
Transforms are a general way to modify and customize Data
or HeteroData
objects, either by implicitly passing them as an argument to a Dataset
, or by applying them explicitly to individual Data
or HeteroData
objects:
import torch_geometric.transforms as T
from torch_geometric.datasets import TUDataset
transform = T.Compose([T.ToUndirected(), T.AddSelfLoops()])
dataset = TUDataset(path, name='MUTAG', transform=transform)
data = dataset[0] # Implicitly transform data on every access.
data = TUDataset(path, name='MUTAG')[0]
data = transform(data) # Explicitly transform data.
General Transforms
An abstract base class for writing transforms. 

Composes several transforms together. 

Composes several filters together. 

Performs tensor device conversion, either for all attributes of the 

Converts the 

Appends a constant value to each node feature 

Rownormalizes the attributes given in 

Dimensionality reduction of node features via Singular Value Decomposition (SVD) (functional name: 

Removes classes from the nodelevel training set as given by 

Performs a nodelevel random split by adding 

Performs an edgelevel random split into training, validation and test sets of a 

Creates a nodelevel split with distributional shift based on a given node property, as proposed in the "Evaluating Robustness and Uncertainty of Graph Models Under Structural Distributional Shifts" paper (functional name: 

Converts indices to a mask representation (functional name: 

Converts a mask to an index representation (functional name: 

Applies padding to enforce consistent tensor shapes (functional name: 
Graph Transforms
Converts a homogeneous or heterogeneous graph to an undirected graph such that \((j,i) \in \mathcal{E}\) for every edge \((i,j) \in \mathcal{E}\) (functional name: 

Adds the node degree as one hot encodings to the node features (functional name: 

Saves the globally normalized degree of target nodes (functional name: 

Appends the Local Degree Profile (LDP) from the "A Simple yet Effective Baseline for Nonattribute Graph Classification" paper (functional name: 

Adds selfloops to the given homogeneous or heterogeneous graph (functional name: 

Adds remaining selfloops to the given homogeneous or heterogeneous graph (functional name: 

Removes all selfloops in the given homogeneous or heterogeneous graph (functional name: 

Removes isolated nodes from the graph (functional name: 

Removes duplicated edges from a given homogeneous or heterogeneous graph. 

Creates a kNN graph based on node positions 

Creates edges based on node positions 

Converts a sparse adjacency matrix to a dense adjacency matrix with shape 

Adds the two hop edges to the edge indices (functional name: 

Converts a graph to its corresponding linegraph (functional name: 

Computes the highest eigenvalue of the graph Laplacian given by 

Processes the graph via Graph Diffusion Convolution (GDC) from the "Diffusion Improves Graph Learning" paper (functional name: 

The Scalable Inception Graph Neural Network module (SIGN) from the "SIGN: Scalable Inception Graph Neural Networks" paper (functional name: 

Applies the GCN normalization from the "Semisupervised Classification with Graph Convolutional Networks" paper (functional name: 

Adds additional edge types to a 

Adds additional edge types similar to 

Collects rooted \(k\)hop EgoNets for each node in the graph, as described in the "From Stars to Subgraphs: Uplifting Any GNN with Local Structure Awareness" paper. 

Collects rooted randomwalk based subgraphs for each node in the graph, as described in the "From Stars to Subgraphs: Uplifting Any GNN with Local Structure Awareness" paper. 

Selects the subgraph that corresponds to the largest connected components in the graph (functional name: 

Appends a virtual node to the given homogeneous graph that is connected to all other nodes, as described in the "Neural Message Passing for Quantum Chemistry" paper (functional name: 

Adds the Laplacian eigenvector positional encoding from the "Benchmarking Graph Neural Networks" paper to the given graph (functional name: 

Adds the random walk positional encoding from the "Graph Neural Networks with Learnable Structural and Positional Representations" paper to the given graph (functional name: 

The feature propagation operator from the "On the Unreasonable Effectiveness of Feature propagation in Learning on Graphs with Missing Node Features" paper (functional name: 

The graph upsampling augmentation from the "HalfHop: A Graph Upsampling Approach for Slowing Down Message Passing" paper. 
Vision Transforms
Saves the Euclidean distance of linked nodes in its edge attributes (functional name: 

Saves the relative Cartesian coordinates of linked nodes in its edge attributes (functional name: 

Saves the relative Cartesian coordinates of linked nodes in its edge attributes (functional name: 

Saves the polar coordinates of linked nodes in its edge attributes (functional name: 

Saves the spherical coordinates of linked nodes in its edge attributes (functional name: 

Computes the rotationinvariant Point Pair Features (functional name: 

Centers node positions 

Rotates all points according to the eigenvectors of the point cloud (functional name: 

Centers and normalizes node positions to the interval \((1, 1)\) (functional name: 

Translates node positions by randomly sampled translation values within a given interval (functional name: 

Flips node positions along a given axis randomly with a given probability (functional name: 

Transforms node positions 

Scales node positions by a randomly sampled factor \(s\) within a given interval, e.g., resulting in the transformation matrix (functional name: 

Rotates node positions around a specific axis by a randomly sampled factor within a given interval (functional name: 

Shears node positions by randomly sampled factors \(s\) within a given interval, e.g., resulting in the transformation matrix (functional name: 

Converts mesh faces 

Uniformly samples a fixed number of points on the mesh faces according to their face area (functional name: 

Samples a fixed number of points and features from a point cloud (functional name: 

Generate normal vectors for each mesh node based on neighboring faces (functional name: 

Computes the delaunay triangulation of a set of points (functional name: 

Converts an image to a superpixel representation using the 

Clusters points into fixedsized voxels (functional name: 