This repository contains the code necessary to obtain the experimental results published in the article Measuring (in)variances to transformations in Neural Networks (link and bib entry coming soon).
Invariances in neural networks are useful and necessary for many tasks. Currently, there are various proposals on how to achieve invariance, based on both specialized model design and data augmentation. However, the actual representation of the invariance, especially for models trained with data augmentation, has received little attention. We define efficient and interpretable measures to quantify the invariance of neural networks in terms of their internal representation. The measures can be applied to any neural network model, but can also be specialized for specific modules such as convolutional layers. Through various experiments, we validate the measures and their properties in the domain of affine transformations and the CIFAR10 and MNIST datasets, including their stability, their relation to sample and transformation size, and interpretability.
You can train a model on the datasets:
You can choose a set of transformations as data augmentation. Currently supported:
- Affine Transformations
- Rotation
- Translation
- Scaling
- ... and combinations
Afterwards, you can also calculate various measures of invariance/equivariance for those models, and produce several plots/visualizations.
The available models are:
These instructions have been tested on a modern ubuntu-based (22.04) distro with python version>=3.10. All experiments are based on models defined and trained with PyTorch.
- Clone the repository and cd to it:
git clone https://github.com/facundoq/transformational_measures_experiments.git
cd transformational_measures_experiments
- Create a virtual environment and activate it (requires python3 with the venv module and pip):
python3 -m venv .env
source .env/bin/activate
- Update
pip
,wheel
andsetuptools
to the latest versions:- pip install --upgrade pip wheel setuptools
- Install libraries
pip install -r requirements.txt
- Also install a distribution of Pytorch (requirements-torch.txt is the one we used for cuda 10 but you should the appropriate version for your hardware/drivers/cuda).
- (optional) Install the Computer Modern fonts if you want to recreate the figures as in the paper.
sudo apt install cm-super
in ubuntu
- Run the experiments:
./invariance_run.py
Executes invariance experiments (see folderexperiments/invariance/
for their individual description)./same_equivariance_run.py
Executes same-equivariance experiments (see folderexperiments/same_equivariance/
for their individual description)