Skip to main content

STIR -- shared invariance measure

Project description

Similarity Throught Inverted Representations (STIR) Paper

Measuring Representational Robustness of Neural Networks Through Shared Invariances, ICML 2022. Vedant Nanda, Till Speicher, Camila Kolling, John P. Dickerson, Krishna P. Gummadi, Adrian Weller

Installation

pip install stir-invariance

Or you can install it from source. First clone this repo and then run

python setup.py install

Quick Start

import stir
import stir.model.tools.helpers as helpers
import stir.helper as hp

test_dataloader = ... ## (instance of torch.utils.data.DataLoader, 
                      ## should return (images, labels) in each iter)
                      ## images should *not* be normalized since 
                      ## normalization is performed in model's forward pass

model1 = ... ## instance of torch.nn.Module
model1_dataset = 'cifar10'
normalizer1 = helpers.InputNormalize(*hp.DATASET_TO_MEAN_STD[model1_dataset]) 
## or any instance of torch.nn.Module that performs input normalization
model2 = ... ## instance of torch.nn.Module
model2_dataset = 'cifar10'
normalizer2 = helpers.InputNormalize(*hp.DATASET_TO_MEAN_STD[model2_dataset])
## or any instance of torch.nn.Module that performs input normalization

total_images = 1000 # number of images to use for computing STIR

# computes STIR between penultimate layer of model1 and model2
stir_score = stir.STIR(model1, model2, 
                       normalizer1, normalizer2, 
                       (test_dataloader, total_images))

stir_score.m1m2 ## STIR(m1|m2)
stir_score.m2m1 ## STIR(m2|m1)
stir_score.rsm ## Underlying similarity measure (default: Linear CKA)

Citation

If you find our work useful, please cite it:

@inproceedings{nanda2022measuring,
    title={Measuring Representational Robustness of Neural Networks Through Shared Invariances},
    author={Nanda, Vedant and Speicher, Till and Kolling, Camilla and Dickerson, John P. and Gummadi, Krishna P. and Weller, Adrian},
    booktitle={ICML},
    year={2022}
}

Acknowledgements

This repo borrows code from the robustness library to invert representations (and train models). The minibatch CKA implementation is inspired by PyTorch-Model-Compare and full batch from @yuanli2333's CKA implementation. Models for TRADES and MART were trained using the repos made public by authors of the respective papers.

Project details


Release history Release notifications | RSS feed

This version

0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stir-invariance-0.0.tar.gz (64.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stir_invariance-0.0-py3-none-any.whl (73.0 kB view details)

Uploaded Python 3

File details

Details for the file stir-invariance-0.0.tar.gz.

File metadata

  • Download URL: stir-invariance-0.0.tar.gz
  • Upload date:
  • Size: 64.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for stir-invariance-0.0.tar.gz
Algorithm Hash digest
SHA256 94ed9cf0ce4a9645253f43702d0e958f39b1d125abad5d72119c5b0c78351b37
MD5 bb7dd92d5844b2a38dda3b4964664429
BLAKE2b-256 6478cd2631f4423b4c95b19cdf8d60b5a0af4d7fd6ff46ed6981c81f2cf1825e

See more details on using hashes here.

File details

Details for the file stir_invariance-0.0-py3-none-any.whl.

File metadata

  • Download URL: stir_invariance-0.0-py3-none-any.whl
  • Upload date:
  • Size: 73.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for stir_invariance-0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 687912c6a1a705162d9d434948656ad76f4a953f40bdf1bd706b389b21ede96a
MD5 7436d25759f9ea9b69f3276d6bd40316
BLAKE2b-256 83ebee2f6b4c21c74c61b1295abe0892eb20d022c3bcc8661465daf10b97206d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page