Giter Club home page Giter Club logo

stir's Introduction

Similarity Through Inverted Representations (STIR) Paper

Measuring Representational Robustness of Neural Networks Through Shared Invariances, (Long Presentation) 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

pip install -e .

or

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.

stir's People

Contributors

dependabot[bot] avatar nvedant07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.