Berlin Tech Meetup: The Future of Relational Foundation Models, Systems, and Real-World Applications

Register now:
PyG/Layer8 min read

SplineConv: Smooth Continuous Filters on Graphs

SplineConv uses B-spline basis functions to create smooth, continuous convolutional filters over edge attributes. Created by Matthias Fey (the creator of PyG), it bridges traditional CNNs and graph neural networks by defining proper spatial convolution on irregular structures.

PyTorch Geometric

TL;DR

  • 1SplineConv defines convolutional kernels using B-spline basis functions evaluated at edge pseudo-coordinates. This creates smooth, continuous filters on irregular graph structures.
  • 2Created by Matthias Fey, the lead developer of PyTorch Geometric. SplineCNN was the foundational work that led to PyG's creation.
  • 3Ideal for mesh processing and geometric deep learning where edge attributes encode spatial relationships (relative position, angles).
  • 4kernel_size controls filter resolution (5-7 typical), degree controls smoothness (1=linear is sufficient for most tasks).

Original Paper

SplineCNN: Fast Geometric Deep Learning with Continuous B-Spline Kernels

Fey et al. (2017). CVPR 2018

Read paper →

What SplineConv does

SplineConv generalizes standard image convolution to irregular graph structures:

  1. Interpret edge attributes as pseudo-coordinates in a continuous d-dimensional space
  2. Evaluate B-spline basis functions at these coordinates to get smooth filter weights
  3. Apply the position-dependent filter to neighbor features and aggregate

On a regular grid (image), SplineConv recovers standard 2D convolution. On irregular meshes, it adapts to the local geometry.

PyG implementation

spline_model.py
import torch
import torch.nn.functional as F
from torch_geometric.nn import SplineConv

class SplineNet(torch.nn.Module):
    def __init__(self, in_channels, hidden_channels, out_channels):
        super().__init__()
        self.conv1 = SplineConv(in_channels, hidden_channels,
                                 dim=2, kernel_size=5, degree=1)
        self.conv2 = SplineConv(hidden_channels, out_channels,
                                 dim=2, kernel_size=5, degree=1)

    def forward(self, x, edge_index, edge_attr):
        # edge_attr: pseudo-coordinates in [0, 1]^dim
        x = F.relu(self.conv1(x, edge_index, edge_attr))
        x = self.conv2(x, edge_index, edge_attr)
        return x

# For mesh data: edge_attr encodes relative positions
# For images: edge_attr encodes pixel offsets (normalized to [0,1])
model = SplineNet(in_channels=3, hidden_channels=64, out_channels=10)

edge_attr must be in [0, 1]^dim. For mesh data, normalize relative positions. dim=2 for surfaces, dim=3 for volumetric data.

When to use SplineConv

  • Mesh processing. 3D mesh classification and segmentation where edge attributes encode geometric relationships (relative positions, normals, angles).
  • Manifold learning. Data on surfaces or low-dimensional manifolds where continuous spatial filters are natural.
  • Image-as-graph tasks. MNIST/CIFAR on superpixel graphs where edge attributes encode spatial offsets between superpixels.

When not to use SplineConv

  • Graphs without spatial edge attributes. SplineConv requires meaningful pseudo-coordinates. Social networks, citation graphs, and knowledge graphs lack these.
  • Discrete edge types. B-splines are designed for continuous coordinates. For categorical edge types, use RGCNConv or GINEConv.

Frequently asked questions

What is SplineConv in PyTorch Geometric?

SplineConv implements SplineCNN from Fey et al. (2017), created by Matthias Fey (the lead developer of PyTorch Geometric). It uses continuous B-spline basis functions to define convolutional kernels over edge attributes (pseudo-coordinates). This creates smooth, continuous filters that generalize standard discrete convolutions to irregular graph structures.

How does SplineConv use edge attributes?

SplineConv interprets edge attributes as pseudo-coordinates in a continuous space. It evaluates B-spline basis functions at these coordinates to generate smooth, position-dependent filter weights. For mesh data, edge attributes encode relative position; for images as graphs, they encode pixel offsets.

What is the connection between SplineConv and PyG?

SplineConv was one of the earliest layers in PyTorch Geometric, created by Matthias Fey who also created PyG itself. The SplineCNN paper was Fey's foundational work that led to developing the broader PyG library.

When should I use SplineConv vs EdgeConv?

Use SplineConv when edge attributes represent continuous spatial coordinates and you want smooth filters (mesh processing, manifold learning). Use EdgeConv when you need dynamic graph construction from point clouds. SplineConv works on fixed graphs with spatial edge attributes; EdgeConv recomputes the graph each layer.

What kernel size and degree should I use?

kernel_size controls the number of B-spline control points per dimension. Typical values: 5-7. Higher means more flexible filters but more parameters. Degree controls the B-spline order (1=linear, 2=quadratic, 3=cubic). Degree 1 is most common and sufficient for most tasks.

Learn more about graph ML

PyTorch Geometric is the open-source foundation for graph neural networks. Explore more layers, concepts, and production patterns.