A Vision Transformer explainability package
Project description
txv (Transformer eXplainability - Vision)
txv is a vision transformers explainability package. It provides CAM like visualization for vision transformers. It is built on the top of transformerinterp and Transformer-Explainability repositories.
Website : Home Page
Documentation : Documentation
Tutorial : Tutorials
Installation
For Users
pip install txv
For Development/latest version
git clone git@github.com:LokeshBadisa/txv.git
cd txv
pip install -e .
Example
from txv.exp import BeyondIntuition
from txv.utils import *
from txv.vit import vit_base_patch16_224
device = torch.device('cuda:0')
model = vit_base_patch16_224().to(device)
image = read_image('./images/zebra-elephant.png').to(device)
output = model(image)
print_top_classes(output)
Output:
Top 10 classes:
340 : zebra value = 12.749 prob = 94.2%
386 : African elephant, Loxodonta africana value = 9.485 prob = 3.6%
101 : tusker value = 7.923 prob = 0.8%
385 : Indian elephant, Elephas maximus value = 7.684 prob = 0.6%
352 : impala, Aepyceros melampus value = 5.946 prob = 0.1%
351 : hartebeest value = 5.460 prob = 0.1%
343 : warthog value = 5.416 prob = 0.1%
9 : ostrich, Struthio camelus value = 5.292 prob = 0.1%
353 : gazelle value = 5.248 prob = 0.1%
293 : cheetah, chetah, Acinonyx jubatus value = 4.881 prob = 0.0%
bi = BeyondIntuition(model)
mask_bih = bi.explain(image,method='head')
mask_bit = bi.explain(image,method='token')
inp1,mask_bih = postprocess(image,mask_bih)
cam1 = show_exp_on_image(inp1[0],mask_bih[0])
inp2,mask_bit = postprocess(image,mask_bit)
cam2 = show_exp_on_image(inp2[0],mask_bit[0])
plt.subplot(1,2,1)
plt.imshow(cam1)
plt.axis('off')
plt.subplot(1,2,2)
plt.imshow(cam2)
plt.axis('off')
plt.show()
|
Beyond Intuition - Head wise |
Beyond Intuition - Token wise |
Note that currently txv supports models only in
txv.vitmodule.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file txv-0.0.2.tar.gz.
File metadata
- Download URL: txv-0.0.2.tar.gz
- Upload date:
- Size: 32.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
533581294b47f32fa40aa54187a852225396bdbfdcdd0fb7b38aaf80462e2e21
|
|
| MD5 |
19b92d505327e91186fced5624bc62e4
|
|
| BLAKE2b-256 |
9f28703918674a7e1ba5bd7a13a6761b261c0f8f7cc599be2196a7f94da9f845
|
File details
Details for the file txv-0.0.2-py3-none-any.whl.
File metadata
- Download URL: txv-0.0.2-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b6d0ae150f1b05dc18de6ac0114e157808bc41b18503e3626861241e05c80ef
|
|
| MD5 |
60c79c26f53f5cad224fbaf9aeef8a83
|
|
| BLAKE2b-256 |
d462dd581ca47b242a923e5d0a5cfb0a8e81c4d2de0cbcc729a8851219e0b5c9
|