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.
Installation
anatome
requires
Python>=3.9.0
PyTorch>=1.9.0
torchvision>=0.10.0
After the installation of PyTorch, install anatome
as follows:
pip install -U git+https://github.com/moskomule/anatome
Available Tools
Representation Similarity
To measure the similarity of learned representation, anatome.SimilarityHook
is a useful tool. Currently, the following methods are implemented.
from anatome import SimilarityHook
model = resnet18()
hook1 = SimilarityHook(model, "layer3.0.conv1")
hook2 = SimilarityHook(model, "layer3.0.conv2")
model.eval()
with torch.no_grad():
model(data[0])
# downsampling to (size, size) may be helpful
hook1.distance(hook2, size=8)
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 cite as:
@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}
}