Skip to main content

Ἀνατομή (Anatome) is a PyTorch library to analyze representation of neural networks

Project description

anatome

Ἀνατομή is a PyTorch library to analyze internal representation of neural networks

This project is under active development and the codebase is subject to change.

Note the name of the pypi package is ultimate-anatome but the python import is done with the original name import anatome. Test via:

python -c "import anatome.my_utils as my_utils;my_utils.hello()"
python -c "import anatome.my_utils as my_utils;my_utils.my_anatome_test()"

Credit to original library: https://github.com/moskomule/anatome

Installation

If you are going to use a gpu the do this first before continuing (or check the offical website: https://pytorch.org/get-started/locally/):

pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

Otherwise, just doing the follwoing should work.

pip install ultimate-anatome

Manual installation [for Development]

To use code first get the code from this repo (e.g. fork it on github):

git clone git@github.com:brando90/ultimate-anatome.git

Then install it in development mode in your python env with python >=3.9. E.g. create your env with conda:

conda create -n ultimate_anatome_env python=3.9
conda activate ultimate_anatome_env

Then install code in edibable mode and all it's depedencies with pip in the currently activated conda environment:

pip install -e ~/ultimate-anatome

Available Tools

Representation Similarity

To measure the similarity of learned representation, anatome.SimilarityHook is a useful tool. Currently, the following methods are implemented.

import torch
from torchvision.models import resnet18
from anatome import DistanceHook
from anatome.my_utils import remove_hook

model = resnet18()
hook1 = DistanceHook(model, "layer3.0.conv1")
hook2 = DistanceHook(model, "layer3.0.conv2")
model.eval()
with torch.no_grad():
    model(torch.randn(128, 3, 224, 224))
# downsampling to (size, size) may be helpful
hook1.distance(hook2, size=8)
hook1.clear()
hook2.clear()
remove_hook(model, hook1)
remove_hook(model, hook2)

or to test do:

from anatome.my_utils import my_anatome_test
my_anatome_test()

Loss Landscape Visualization

from anatome import landscape2d

x, y, z = landscape2d(resnet18(),
                      data,
                      F.cross_entropy,
                      x_range=(-1, 1),
                      y_range=(-1, 1),
                      step_size=0.1)
imshow(z)

Fourier Analysis

  • Yin et al. NeurIPS 2019 etc.,
from anatome import fourier_map

map = fourier_map(resnet18(),
                  data,
                  F.cross_entropy,
                  norm=4)
imshow(map)

Citation

If you use this implementation in your research, please conser citing my version of anatome:

@software{miranda2021ultimate_anatome,
    author={Brando Miranda},
    title={My Anatome, a PyTorch library to analyze internal representation of neural networks},
    url={https://github.com/brando90/my_anatome},
    year={2021}
}

and the original version:

@software{hataya2020anatome,
    author={Ryuichiro Hataya},
    title={anatome, a PyTorch library to analyze internal representation of neural networks},
    url={https://github.com/moskomule/anatome},
    year={2020}
}

Project details


Download files

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

Source Distribution

ultimate-anatome-0.0.6.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

ultimate_anatome-0.0.6-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file ultimate-anatome-0.0.6.tar.gz.

File metadata

  • Download URL: ultimate-anatome-0.0.6.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for ultimate-anatome-0.0.6.tar.gz
Algorithm Hash digest
SHA256 e8b1dd49e1e7abe3e6fc1e26c8f231499353799d52eb6d5218944fc99b8203b7
MD5 d161e63f25c7bd17c0f38a59c651a14f
BLAKE2b-256 d6d0c0b3874aee7d288cf5e6ce6933123b2ffc4fcd87fd97e510ea8615050fa1

See more details on using hashes here.

File details

Details for the file ultimate_anatome-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: ultimate_anatome-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for ultimate_anatome-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 75dca1d59002e9d473a109df00ff07323c5d75f1653525f7975eb4b664de83e5
MD5 552de82dffe7367a8a04af75d268ff19
BLAKE2b-256 419ef12cc76e19343a4727f5c5e131bb43788075248a931dc6b4c0c173fdb63f

See more details on using hashes here.

Supported by

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