Package: escnn
E(n)-equivariant Steerable CNNs (escnn)Documentation|Paper ICLR 22|Paper NeurIPS 19|e2cnnlibrary|e2cnn experiments|Thesisescnnis aPyTorchextension for equivariant deep learning.escnnis the successor of thee2cnnlibrary, which only supported planar isometries.
Instead,escnnsupports steerable CNNs equivariant to both 2D and 3D isometries, as well as equivariant MLPs.If you prefer using Jax, check our this forkescnn_jaxof our library!Equivariant neural networksguarantee a specified transformation behavior of their feature spaces under transformations of their input.
For instance, classical convolutional neural networks (CNNs) are by design equivariant to translations of their input.
This means that a translation of an image leads to a corresponding translation of the network's feature maps.
This package provides implementations of neural network modules which are equivariant under allisometriesE(2) of the image planeand allisometriesE(3) of the 3D space, that is, undertranslations,rotationsandreflections(and can, potentially, be extended to all isometries E(n) of).
In contrast to conventional CNNs, E(n)-equivariant models are guaranteed to generalize over such transformations, and are therefore more data efficient.The feature spaces of E(n)-equivariant Steerable CNNs are defined as spaces offeature fields, being characterized by their transformation law under rotations and reflections.
Typical examples are scalar fields (e.g. gray-scale images or temperature fields) or vector fields (e.g. optical flow or electromagnetic fields).Instead of a number of channels, the user has to specify the fieldtypesand theirmultiplicitiesin order to define a feature space.
Given a specified input- and output feature space, ourR2convandR3convmodules instantiate themost generalconvolutional mapping between them.
Our library provides many other equivariant operations to process feature fields, including nonlinearities, mappings to produce invariant features, batch normalization and dropout.
Feature fields are represented byGeometricTensorobjects, which wrap atorch.Tensorwith the corresponding transformation law.
All equivariant operations perform a dynamic type-checking in order to guarantee a geometrically sound processing of the feature fields.To parameterize steerable kernel spaces, equivariant to an arbitrary compact group G,
in ourpaper, we generalize the Wigner-Eckart theorem inA Wigner-Eckart Theorem for Group Equivariant Convolution Kernelsfrom G-homogeneous spaces to more general spaces X carrying a G-action.
In short, our method leverages a G-steerable basis for unconstrained scalar filters over the whole Euclidean spaceto generate steerable kernel spaces with arbitrary input and output fieldtypes.
For example, the left side of the next image shows two elements of a SO(2)-steerable basis for functions onwhich are used to generate two
basis elements for SO(2)-equivariant steerable kernels on the right.
In particular, the steerable kernels considered map a frequency l=1 vector field (2 channels) to a frequency J=2
vector field (2 channels).E(n)-Equivariant Steerable CNNs unify and generalize a wide range of isometry equivariant CNNs in one single framework.
Examples include:Group Equivariant Convolutional NetworksHarmonic Networks: Deep Translation and Rotation EquivarianceSteerable CNNsRotation equivariant vector field networksLearning Steerable Filters for Rotation Equivariant CNNsHexaConvRoto-Translation Covariant Convolutional Networks for Medical Image Analysis3D Steesable CNNsTensor Field NetworksCormorant: Covariant Molecular Neural Networks3D GCNNs for Pulmonary Nodule DetectionFor more details, we refer to our ICLR 2022 paperA Program to Build E(N)-Equivariant Steerable CNNsand our NeurIPS 2019 paperGeneral E(2)-Equivariant Steerable CNNs.The library is structured into four subpackages with different high-level features:ComponentDescriptionescnn.groupimplements basic concepts ofgroupandrepresentationtheoryescnn.kernelssolves for spaces of equivariant convolution kernelsescnn.gspacesdefines the Euclidean spaces and their symmetriesescnn.nncontains equivariant modules to build deep neural networksWARNING:escnn.kernelsreceived major refactoring in version 1.0.0 and it is not compatible with previous versions of the library. These changes do not affect the interface provided in the rest of the library but, sometimes, the weights of a network trained with a previous version might not load correctly in a newly instantiated model.
We recommend using versionv0.1.9for backward compatibility.DemoSince E(2)-steerable CNNs are equivariant under rotations and reflections, their inference is independent from the choice of image orientation.
The visualization below demonstrates this claim by feeding rotated images into a randomly initialized E(2)-steerable CNN (left).
The middle plot shows the equivariant transformation of a feature space, consisting of one scalar field (color-coded) and one vector field (arrows), after a few layers.
In the right plot we transform the feature space into a comoving reference frame by rotating the response fields back (stabilized view).The invariance of the features in the comoving frame validates the rotational equivariance of E(2)-steerable CNNs empirically.
Note that the fluctuations of responses are discretization artifacts due to the sampling of the image on a pixel grid, which does not allow for exact continuous rotations.For comparison, we show a feature map response of a conventional CNN for different image orientations below.Since conventional CNNs are not equivariant under rotations, the response varies randomly with the image orientation.
This prevents CNNs from automatically generalizing learned patterns between different reference frames.Experimental resultsE(n)-steerable convolutions can be used as a drop in replacement for the conventional convolutions used in CNNs.
While using the same base architecture (with similar memory and computational cost),
this leads to significant performance boosts compared to CNN baselines (values are test accuracies in percent).modelRotated ModelNet10CNN baseline82.5       ± 1.4SO(2)-CNN86.9       ± 1.9Octa-CNN89.7       ± 0.6Ico-CNN90.0       ± 0.6SO(3)-CNN89.5       ± 1.0All models share approximately the same architecture and width.
For more details we refer to ourpaper.This library supports E(2)-steerable CNNs implemented in our previouse2cnnlibrary as a special case;
we include some representative results in the 2D setting from there:modelCIFAR-10CIFAR-100STL-10CNN baseline2.6   ± 0.117.1   ± 0.312.74 ± 0.23E(2)-CNN *2.39       ± 0.1115.55       ± 0.1310.57 ± 0.70E(2)-CNN2.05       ± 0.0314.30       ± 0.099.80 ± 0.40While using the same training setup (no further hyperparameter tuning) used for the CNN baselines, the equivariant models achieve significantly better results (values are test errors in percent).
For a fair comparison, the models without * are designed such that the number of parameters of the baseline is approximately preserved while models with * preserve the number of channels, and hence compute.
For more details we refer to our previouse2cnnpaper.Getting Startedescnnis easy to use since it provides a high level user interface which abstracts most intricacies of group and representation theory away.
The following code snippet shows how to perform an equivariant convolution from an RGB-image to 10regularfeature fields (corresponding to agroup convolution).fromescnnimportgspaces#  1fromescnnimportnn#  2importtorch#  3#  4r2_act=gspaces.rot2dOnR2(N=8)#  5feat_type_in=nn.FieldType(r2_act,3*[r2_act.trivial_repr])#  6feat_type_out=nn.FieldType(r2_act,10*[r2_act.regular_repr])#  7#  8conv=nn.R2Conv(feat_type_in,feat_type_out,kernel_size=5)#  9relu=nn.ReLU(feat_type_out)# 10# 11x=torch.randn(16,3,32,32)# 12x=feat_type_in(x)# 13# 14y=relu(conv(x))# 15Line 5 specifies the symmetry group action on the image planeunder which the network should be equivariant.
We choose thecyclic groupC8, which describes discrete rotations by multiples of 2π/8.
Line 6 specifies the input feature field types.
The three color channels of an RGB image are thereby to be identified as three independent scalar fields, which transform under thetrivial representationof C8(when the input image is rotated, the RGB values do not change; compare the scalar and vector fields in the first image above).
Similarly, the output feature space in line 7 is specified to consist of 10 feature fields which transform under theregular representationof C8.
The C8-equivariant convolution is then instantiated by passing the input and output type as well as the kernel size to the constructor (line 9).
Line 10 instantiates an equivariant ReLU nonlinearity which will operate on the output field and is therefore passed the output field type.Lines 12 and 13 generate a random minibatch of RGB images and wrap them into ann.GeometricTensorto associate them
with their correct field typefeat_type_in.
The equivariant modules process the geometric tensor in line 15.
Each module is thereby checking whether the geometric tensor passed to them satisfies the expected transformation law.Because the parameters do not need to be updated anymore at test time, after training, any equivariant network can be
converted into a pure PyTorch model with no additional computational overhead in comparison to conventional CNNs.
The code currently supports the automatic conversion of a few commonly used modules through the.export()method;
check thedocumentationfor more details.To get started, we provide some examples and tutorials:Theintroductory tutorialintroduces the basic functionality of the library.A secondtutorialgoes through building and training
an equivariant model on the rotated MNIST dataset.Note thatescnnalso supports equivariant MLPs; seethese examples.Check also thetutorialon Steerable CNNs using our library in theDeep Learning 2course at the University of Amsterdam.More complex 2D equivariantWide Resnetmodels are implemented ine2wrn.py.
To try a model which is equivariant under reflections call:cd examples
python e2wrn.pyA version of the same model which is simultaneously equivariant under reflections and rotations of angles multiple of 90 degrees can be run via:python e2wrn.py --rot90You can find more examples in theexamplefolder.
For instance,se3_3Dcnn.pyimplements a 3D CNN equivariant to
rotations and translations in 3D. You can try it withcd examples
python se3_3Dcnn.pyUseful material to learn about Equivariance and Steerable CNNsIf you want to better understand the theory behind equivariant and steerable neural networks, you can check these references:Erik Bekkers'lecturesonGeometric Deep Learningat in the Deep Learning 2 course at the University of AmsterdamThe course material also includes atutorialongroup convolutionandanotherabout Steerable CNNs, usingthis library.Mythesisprovides a brief overview of the essential mathematical ingredients needed to understand Steerable CNNs.DependenciesThe library is based on Python3.7torch>=1.3
numpy
scipy
lie_learn
joblib
py3njOptional:torch-geometric
pymanopt>=1.0.0
autogradWARNING:py3njenables a fast computation of Clebsh Gordan coefficients.
If this package is not installed, our library relies on a numerical method to estimate them.
This numerical method is not guaranteed to return the same coefficients computed bypy3nj(they can differ by a sign).
For this reason, models built with and withoutpy3njmight not be compatible.To successfully installpy3njyou may need a Fortran compiler installed in you environment.InstallationYou can install the latestreleaseaspip install escnnor you can clone this repository and manually install it withpip install git+https://github.com/QUVA-Lab/escnnContributingWould you like to contribute toescnn? That's great!Then, check the instructions inCONTRIBUTING.mdand help us to
improve the library!CiteThe development of this library was part of the work done for our papersA Program to Build E(N)-Equivariant Steerable CNNsandGeneral E(2)-Equivariant Steerable CNNs.
Please cite these works if you use our code:@inproceedings{cesa2022a,
        title={A Program to Build {E(N)}-Equivariant Steerable {CNN}s },
        author={Gabriele Cesa and Leon Lang and Maurice Weiler},
        booktitle={International Conference on Learning Representations},
        year={2022},
        url={https://openreview.net/forum?id=WE4qe9xlnQw}
    }
    
   @inproceedings{e2cnn,
       title={{General E(2)-Equivariant Steerable CNNs}},
       author={Weiler, Maurice and Cesa, Gabriele},
       booktitle={Conference on Neural Information Processing Systems (NeurIPS)},
       year={2019},
   }Feel free tocontact us.Licenseescnnis distributed under BSD Clear license. See LICENSE file.