Package: e2cnn
General E(2)-Equivariant Steerable CNNsDocumentation|Experiments|Paper|Thesis|newescnnlibraryCheck outour newescnnlibrarywhich extendse2cnnto a wider class of equivariance groups.While we will still provide some support for this older version,
this library isdeprecatedand we plan to slowly abandon it in favour of the newer versionescnn.
Note thatescnnalready includes all features ofe2cnnand many more.
You can find a short summary of the main differences in the new versionhere.e2cnnis aPyTorchextension for equivariant deep learning.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 plane, that is, undertranslations,rotationsandreflections.
In contrast to conventional CNNs, E(2)-equivariant models are guaranteed to generalize over such transformations, and are therefore more data efficient.The feature spaces of E(2)-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, ourR2convmodule instantiates 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.E(2)-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 AnalysisFor more details we refer to our NeurIPS 2019 paperGeneral E(2)-Equivariant Steerable CNNs.The library also supports equivariant Steerable partial differential operators as described inSteerable Partial Differential Operators for Equivariant Neural Networks.The library is structured into four subpackages with different high-level features:ComponentDescriptione2cnn.groupimplements basic concepts ofgroupandrepresentationtheorye2cnn.kernelssolves for spaces of equivariant convolution kernelse2cnn.diffopssolves for spaces of equivariant differential operatorse2cnn.gspacesdefines the image plane and its symmetriese2cnn.nncontains equivariant modules to build deep neural networksDemoSince 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(2)-steerable convolutions can be used as a drop in replacement for the conventional convolutions used in CNNs.
Keeping the same training setup andwithout performing hyperparameter tuning, this leads to significant performance boosts compared to CNN baselines (values are test errors in percent):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.40The models without * are for a fair comparison 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 ourpaper.Getting Startede2cnnis 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).frome2cnnimportgspaces#  1frome2cnnimportnn#  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=nn.GeometricTensor(x,feat_type_in)# 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.
Similarly, the output feature space is in line 7 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 type.
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.A hands-on tutorial, introducing the basic functionality ofe2cnn, is provided inintroduction.ipynb.
Code for training and evaluating a simple model on therotated MNISTdataset is given inmodel.ipynb.More complex 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 --rot90DependenciesThe library is based on Python3.7torch>=1.1
numpy
scipyOptional:pymanopt
autogradThe following packagessympy
rbfare required to use the steerable differential operators.Check the branchlegacy_py3.6for a Python 3.6 compatible version of the library.InstallationYou can install the latestreleaseaspip install e2cnnor you can clone this repository and manually install it withpip install git+https://github.com/QUVA-Lab/e2cnnNOTE: therbfdependency (necessary to use differential operators) can not
be installed automatically since PyPI does not support direct dependencies
(seehere).
You can installrbfmanually by followingtheseinstructions.CiteThe development of this library was part of the work done for our paperGeneral E(2)-Equivariant Steerable CNNs.
Please cite this work if you use our code:@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},
}The implementation of steerable PDOs are part of the work done in the paperSteerable Partial Differential Operators for Equivariant Neural Networks.
Please, cite it if you use this code in your own work:@inproceedings{jenner2022steerable,
    title={Steerable Partial Differential Operators for Equivariant Neural Networks},
    author={Erik Jenner and Maurice Weiler},
    booktitle={International Conference on Learning Representations},
    year={2022},
    url={https://openreview.net/forum?id=N9W24a4zU}
}Feel free tocontact us.Licensee2cnnis distributed under BSD Clear license. See LICENSE file.