Skip to content

Full Implementation of the Captum-Optim Module #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 890 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
890 commits
Select commit Hold shift + click to select a range
77c80f0
Add MIT Places 365 GoogleNet model (#935)
ProGamerGov May 10, 2022
c500ab5
Merge branch 'optim-wip-master-1' into captum-master
ProGamerGov May 11, 2022
f365ee1
Merge branch 'master' into 'optim-wip'
ProGamerGov May 11, 2022
1290094
Fix linting, depreciations, & version checks
ProGamerGov May 11, 2022
cf86e1f
Fix test errors
ProGamerGov May 11, 2022
90b5bd5
Fix linting, version checks, and other issues
ProGamerGov May 12, 2022
dc3a07b
Remove old version checks & fix test version checks
ProGamerGov May 12, 2022
167dbc9
Merges updates from master branch
ProGamerGov May 12, 2022
f11f271
Formatting changes for black 22.3.0
May 12, 2022
9bb7d47
Merge updates from master branch
ProGamerGov May 12, 2022
e2ba3df
Merge pull request #939 from ProGamerGov/optim-wip-master-1
aobo-y May 12, 2022
e9598ea
Merge branch 'optim-wip' into optim-wip-clip-vis
ProGamerGov May 13, 2022
599d8e1
Update CLIP model for new testing & linting
ProGamerGov May 13, 2022
cf67101
Optim-wip: Fix the Channel Attr notebook image download & metadata fi…
ProGamerGov May 15, 2022
ba84783
Optim-wip: Miscellaneous Changes & Fixes (#827)
ProGamerGov May 15, 2022
5c92e09
Optim-wip: Add descriptions and argument documentation to losses (#831)
greentfrapp May 15, 2022
5e18711
Optim-wip: Add new StackImage parameterization & JIT support for Shar…
ProGamerGov May 17, 2022
4e5e50c
Optim-wip: Improve ModuleOutputsHook, testing coverage (#834)
ProGamerGov May 17, 2022
d272be7
Optim-wip: Add better colorspace support, image grids, & user agent t…
ProGamerGov May 17, 2022
d27e6c2
Add CLIP loss objectives
ProGamerGov May 17, 2022
77850c7
Fix Mypy error
ProGamerGov May 17, 2022
a4eee84
Fix Mypy errors
ProGamerGov May 17, 2022
452979b
Add Optimization With Transparency tutorial
ProGamerGov May 18, 2022
e2e58da
Improve loss objective docs + batch_index
ProGamerGov May 18, 2022
c905352
Fix NeuronActivation docs
ProGamerGov May 18, 2022
8c28dad
Fix FacetLoss docs
ProGamerGov May 18, 2022
32fc693
Improve VectorLoss docs
ProGamerGov May 18, 2022
7b78aaa
Improve loss objective testing
ProGamerGov May 21, 2022
69a73b2
Fix mypy test errors
ProGamerGov May 21, 2022
caffe7c
Fix mypy tests
ProGamerGov May 21, 2022
973aacc
Update test_loss.py
ProGamerGov May 22, 2022
6e6f4e6
Add more tests
ProGamerGov May 22, 2022
221c72b
Fix weird value mismatch
ProGamerGov May 22, 2022
862ddce
Add batch_index tests to new objectives
ProGamerGov May 22, 2022
c50c50b
Optim-wip: Fix duplicated target bug (#919)
ProGamerGov May 23, 2022
39e6ab1
Change Inception5h model link (#948)
ProGamerGov May 23, 2022
b196bbe
Miscellaneous Fixes
ProGamerGov May 25, 2022
c656658
Add Model Preparation Tutorial
ProGamerGov May 25, 2022
0e7d0f4
Improve vector function
ProGamerGov May 25, 2022
3b67bb0
Improve the `FacetLoss` objective
ProGamerGov May 28, 2022
4c51ef1
Add CLIP objectives to `__all__`
ProGamerGov May 28, 2022
36df47e
Separate some loss tests
ProGamerGov May 28, 2022
31cb2a9
Fix mistake in FacetLoss docs
ProGamerGov May 28, 2022
cfa9d9f
Update CustomModules tutorial for new changes
ProGamerGov May 31, 2022
3c9bd01
Add Linear Probe Facet Training tutorial
ProGamerGov May 31, 2022
91056ab
Remove incorrect normalization step
ProGamerGov Jun 1, 2022
264a8ad
Support non default input sizes in FacetLoss
ProGamerGov Jun 2, 2022
00927a1
Improve loss docs
ProGamerGov Jun 2, 2022
f8d3d52
Add the CLIP Feeling Wheel Atlas tutorial
ProGamerGov Jun 3, 2022
c4dd2de
Add the CLIP Faceted Feature Visualization tutorial
ProGamerGov Jun 3, 2022
16f2177
Add additional tests
ProGamerGov Jun 3, 2022
9d92e6b
Improve LaplacianImage
ProGamerGov Jun 4, 2022
c3953a8
Add the CLIP Text Feature Visualization Tutorial
ProGamerGov Jun 4, 2022
63843b5
Add packaging library to setup.py
ProGamerGov Jun 5, 2022
a8fa243
Improve NaturalImage docs
ProGamerGov Jun 6, 2022
c8f9cc5
Remove old commented out TransformationRobustness version
ProGamerGov Jun 9, 2022
8b82a37
Add alias for ImageTensor.open()
ProGamerGov Jun 16, 2022
44203fa
Fix torch.meshgrid warning
ProGamerGov Jun 18, 2022
9e2f953
self.assertEquals -> self.assertEqual
ProGamerGov Jun 18, 2022
857f26c
Add CompositeLoss to __all__
ProGamerGov Jun 20, 2022
9e9a6be
Add Conv2dSame to __all__
ProGamerGov Jun 21, 2022
0270383
Fix doc formatting for Sphinx
ProGamerGov Jun 21, 2022
f867bf3
Resolve register_backward_hook -> register_full_backward_hook depreci…
ProGamerGov Jun 22, 2022
54b652d
Fix lint errors
ProGamerGov Jun 22, 2022
73eedd1
Fix docs for Sphinx
ProGamerGov Jun 23, 2022
c45f694
Minor fixes
ProGamerGov Jun 23, 2022
650927e
Add missing input_param attribute to InputOptimization info
ProGamerGov Jun 23, 2022
4cf8cfc
Fix test errors
ProGamerGov Jun 23, 2022
90f9592
Fix mypy error
ProGamerGov Jun 23, 2022
5e3a80f
Add docs for loss_fn in sum_loss_list
ProGamerGov Jun 24, 2022
613baa9
Add docs for loss testing helper
ProGamerGov Jun 25, 2022
6f41b20
Remove loss_wrapper requirement for loss objectives
ProGamerGov Jun 25, 2022
5f849aa
Fix Sphinx loss doc duplication bug
ProGamerGov Jun 26, 2022
ca3b5f9
Update _common.py
ProGamerGov Jun 27, 2022
dd58b75
Improve ImageParameterization docs for Sphinx
ProGamerGov Jun 27, 2022
e87c975
Improve ImageTensor, Optimization, & submodule docs for Sphinx
ProGamerGov Jun 27, 2022
3173fd9
Sphinx doc improvements
ProGamerGov Jun 27, 2022
2b665f2
Improve CLIP loss docs for Sphinx
ProGamerGov Jun 27, 2022
5837745
Improve loss docs for Sphinx
ProGamerGov Jun 27, 2022
d3a2cca
Improve vector function docs for Sphinx
ProGamerGov Jun 28, 2022
2a592f0
Adjust spacing in doc variables
ProGamerGov Jun 28, 2022
aafc4f7
Improve GaussianSmoothing
ProGamerGov Jun 28, 2022
5935119
Add underscore to some FFTImage functions
ProGamerGov Jun 28, 2022
fdba4e2
Add function links to atlas docs
ProGamerGov Jun 29, 2022
e80b42e
Fix spacing in docs
ProGamerGov Jun 29, 2022
8ceecaf
Improve dataset docs
ProGamerGov Jun 29, 2022
0491cca
Improve Sphinx docs
ProGamerGov Jun 29, 2022
76836b9
Improve ToRGB docs
ProGamerGov Jun 29, 2022
c1161c5
Improve NaturalImage docs
ProGamerGov Jun 29, 2022
86f24ba
Improve ImageTensor docs
ProGamerGov Jun 29, 2022
bb0984f
Add more doc refs
ProGamerGov Jun 29, 2022
e01478c
Fix lint error
ProGamerGov Jun 29, 2022
ef48587
Improve ToRGB docs
ProGamerGov Jul 1, 2022
975550e
Add 'Feature Visualization' keyword
ProGamerGov Jul 1, 2022
3ab53ae
Improve docs for Sphinx (#550)
ProGamerGov Jul 2, 2022
7530ae5
Improve ImageTensor & Dataset docs (#552)
ProGamerGov Jul 2, 2022
eb6930e
Improve ImageParameterization docs (#551)
ProGamerGov Jul 2, 2022
55cad28
Improve GaussianSmoothing docs
ProGamerGov Jul 5, 2022
57ea951
More doc improvements
ProGamerGov Jul 5, 2022
4a62c0b
Improve docs
ProGamerGov Jul 5, 2022
e63cee8
Improve docs
ProGamerGov Jul 5, 2022
3c6c24d
Improve docs (#554)
ProGamerGov Jul 5, 2022
06db64f
Improve dataset docs
ProGamerGov Jul 5, 2022
10d2379
Add missing Places365 InceptionModule docs
ProGamerGov Jul 6, 2022
07c9e60
Add missing InceptionV1 InceptionModule docs
ProGamerGov Jul 6, 2022
fbaa8eb
Add missing forward docs to PixelImage
ProGamerGov Jul 6, 2022
953780e
Fix TransformationRobustness doc formatting & add missing RedirectedR…
ProGamerGov Jul 6, 2022
5457544
Improve FFTImage float dtype support
ProGamerGov Jul 7, 2022
45c8511
Add dtype tests for ImageParameterizations
ProGamerGov Jul 7, 2022
3dc061d
Fix weird error: RuntimeError: expected scalar type Float but found D…
ProGamerGov Jul 7, 2022
90d9fd1
Fix test failures
ProGamerGov Jul 7, 2022
dd13dc6
NaturalImage dtype test fix + transform dtype tests
ProGamerGov Jul 9, 2022
1ffcad4
Fix dtype tests
ProGamerGov Jul 9, 2022
2a0a898
Remove failing test
ProGamerGov Jul 9, 2022
7c833ad
Simplify some image parameterization tests
ProGamerGov Jul 9, 2022
b376466
Improve Optimization docs
ProGamerGov Jul 9, 2022
5333128
http -> https
ProGamerGov Jul 10, 2022
1821a2d
http -> https
ProGamerGov Jul 10, 2022
adaf367
Improve InputOptimization docs
ProGamerGov Jul 10, 2022
3657784
Move tutorial to clip directory
ProGamerGov Jul 10, 2022
cac1d1c
Move tutorial to clip directory
ProGamerGov Jul 10, 2022
c9bed14
Move tutorial to clip directory
ProGamerGov Jul 10, 2022
a92a462
Move tutorial to clip directory
ProGamerGov Jul 10, 2022
44af560
Improve ChannelReducer docs
ProGamerGov Jul 11, 2022
509accd
Improve loss docs
ProGamerGov Jul 14, 2022
407f769
Improve DeepDream docs
ProGamerGov Jul 15, 2022
6f10b76
Improve doc grammar
ProGamerGov Jul 15, 2022
2d81aec
Fix type hints
ProGamerGov Jul 15, 2022
acebbd8
Fix tensor type hints
ProGamerGov Jul 15, 2022
eb5a961
Fix nn.Module type hints
ProGamerGov Jul 15, 2022
a66e7f5
Fix InputOptimization docs
ProGamerGov Jul 16, 2022
61e18e4
Add missing return docs to get_model_layers
ProGamerGov Jul 16, 2022
f781265
Fix loss doc type formating
ProGamerGov Jul 16, 2022
32c4ba5
Fix parameterization doc type hint formatting
ProGamerGov Jul 16, 2022
4426003
Fix clip objective doc type formatting
ProGamerGov Jul 16, 2022
6dbfc3d
Fix doc parameter type formatting
ProGamerGov Jul 16, 2022
6259b13
Improve doc types
ProGamerGov Jul 16, 2022
936bc84
Update _common.py
ProGamerGov Jul 16, 2022
82ca242
Fix duplicated circuits type hint
ProGamerGov Jul 16, 2022
95ed9f9
Remove unused type hints
ProGamerGov Jul 16, 2022
8e77eb7
Doc fix
ProGamerGov Jul 16, 2022
42b18ca
Add more assert checks
ProGamerGov Jul 17, 2022
d6f0def
Add function aliases to docs
ProGamerGov Jul 17, 2022
96e2f8d
Add aliases to InputOptimization and ImageTensor docs
ProGamerGov Jul 17, 2022
f31b8ca
Improve MaxPool2dRelaxed docs
ProGamerGov Jul 17, 2022
910c38d
Improve docstring type formatting
ProGamerGov Jul 18, 2022
199509e
Improve docstring type formatting
ProGamerGov Jul 18, 2022
2480b69
Fix loss docstring type hint formatting
ProGamerGov Jul 18, 2022
a9eabfd
Fix loss docstring type hint formatting
ProGamerGov Jul 18, 2022
f2f1d5d
Fix bug in skip_layers
ProGamerGov Jul 18, 2022
5335a4e
Improve parameterization docs
ProGamerGov Jul 18, 2022
876d737
:class: -> :func:
ProGamerGov Jul 18, 2022
8cbca6d
Fix accidental indent
ProGamerGov Jul 19, 2022
668aff1
Fix NaturalImage docs issue
ProGamerGov Jul 19, 2022
a61461b
Improve optimization docs
ProGamerGov Jul 20, 2022
0ecff5d
Improve InputOptimization.optimize's docstring
ProGamerGov Jul 20, 2022
4bab7d7
Fix doc type hint
ProGamerGov Jul 20, 2022
485481d
Improve doc types for ActivationFetcher
ProGamerGov Jul 20, 2022
aeb058d
Improve InputOptimization docs
ProGamerGov Jul 21, 2022
0fa87de
Add hyperlink ref to circuits argument
ProGamerGov Jul 21, 2022
1faadcd
Fix doc spacing
ProGamerGov Jul 21, 2022
a7fb6d9
Max line length doesn't apply to urls
ProGamerGov Jul 21, 2022
2cfa21b
Add Optim to run_mypy.sh
ProGamerGov Jul 22, 2022
01c59d2
Improve reducer docs
ProGamerGov Jul 22, 2022
e727712
Simplify reducer tests
ProGamerGov Jul 22, 2022
1c50b87
Fix grammar
ProGamerGov Jul 27, 2022
33f9f66
Fix spelling
ProGamerGov Jul 27, 2022
27b702e
Fix spelling
ProGamerGov Jul 27, 2022
7924b87
Remove Optim from run_mypy.sh for now
ProGamerGov Jul 27, 2022
d456347
Fix spelling
ProGamerGov Jul 27, 2022
3a2194f
Remove loss_wrapper tests
ProGamerGov Jul 27, 2022
819a0a8
Remove `loss_wrapper`
ProGamerGov Jul 27, 2022
61a0be9
Fix lint errors
ProGamerGov Jul 27, 2022
31b5707
Fix lint errors
ProGamerGov Jul 27, 2022
e704243
Fix lint error
ProGamerGov Jul 27, 2022
07c7593
Fix Mypy type hints
ProGamerGov Jul 28, 2022
16dd3cf
Fix formatting
ProGamerGov Jul 28, 2022
f2f7ea5
Fix typehint mistake
ProGamerGov Jul 28, 2022
330f009
Fix docstring types
ProGamerGov Jul 28, 2022
7e2dbf9
callable -> Callable
ProGamerGov Jul 28, 2022
ca84f7b
Docstring Improvements
ProGamerGov Jul 29, 2022
fb6db3b
Fix branch
ProGamerGov Aug 1, 2022
1f0420b
Update transforms.py
ProGamerGov Aug 4, 2022
03cea17
callable -> Callable
ProGamerGov Aug 11, 2022
dd610df
Update setup.py
ProGamerGov Apr 1, 2023
7e3ebae
Merge pull request #635 from ProGamerGov/patch-22
ProGamerGov Mar 30, 2025
040ca9f
Merge pull request #636 from ProGamerGov/optim-wip-clip-vis
ProGamerGov Mar 30, 2025
b98c20e
Merge pull request #637 from ProGamerGov/optim-wip-clip-loss-objectives
ProGamerGov Mar 30, 2025
94b90d6
Merge pull request #638 from ProGamerGov/optim-wip-transparency
ProGamerGov Mar 30, 2025
a1e0633
Merge pull request #639 from ProGamerGov/optim-wip-loss-docs
ProGamerGov Mar 30, 2025
32e4f33
Merge pull request #642 from ProGamerGov/optim-wip-model-tutorial
ProGamerGov Mar 30, 2025
ebf133d
Merge pull request #643 from ProGamerGov/optim-wip-custom-modules
ProGamerGov Mar 30, 2025
613e052
Merge pull request #640 from ProGamerGov/optim-wip-version-check
ProGamerGov Mar 30, 2025
99d5b00
Merge branch 'master-0-new-1' into optim-wip-loss-testing
ProGamerGov Mar 30, 2025
7aec493
Merge pull request #641 from ProGamerGov/optim-wip-loss-testing
ProGamerGov Mar 30, 2025
067ee6c
Update setup.py
ProGamerGov Mar 30, 2025
b26d630
move test helpers
ProGamerGov Mar 30, 2025
4041121
Merge pull request #645 from ProGamerGov/master
ProGamerGov Mar 30, 2025
5c85308
Update basic_models.py
ProGamerGov Mar 30, 2025
45ae31c
Merge pull request #646 from ProGamerGov/optim-wip-linear-probes
ProGamerGov Mar 30, 2025
fa15008
Merge pull request #647 from ProGamerGov/optim-wip-feeling-wheel
ProGamerGov Mar 30, 2025
93d719e
Merge pull request #649 from ProGamerGov/optim-wip-minor-fixes
ProGamerGov Mar 30, 2025
af60e34
Merge pull request #650 from ProGamerGov/optim-wip-text-vis
ProGamerGov Mar 30, 2025
00de34d
Update loss.py
ProGamerGov Mar 30, 2025
845c0dc
Merge branch 'master-0-new-1' into optim-wip-more-sphinx-docs
ProGamerGov Mar 30, 2025
7ea6a82
Merge pull request #651 from ProGamerGov/optim-wip-more-sphinx-docs
ProGamerGov Mar 30, 2025
49c7d4b
Merge pull request #648 from ProGamerGov/optim-wip-facet-vis
ProGamerGov Mar 30, 2025
0ef04f4
Update imports
ProGamerGov Mar 30, 2025
d3d60da
fix
ProGamerGov Mar 30, 2025
ff13c30
Update test_loss.py
ProGamerGov Mar 30, 2025
eb5bd96
Update test_loss.py
ProGamerGov Mar 30, 2025
e1dec17
Update loss.py
ProGamerGov Mar 30, 2025
8802e34
Update numpy_image.py
ProGamerGov Mar 30, 2025
1727a09
Update test_loss.py
ProGamerGov Mar 30, 2025
78fcd44
Update test_loss.py
ProGamerGov Mar 30, 2025
0666d3a
Update test_loss.py
ProGamerGov Mar 30, 2025
93dc335
Merge remote-tracking branch 'origin/optim-wip-neural-style-transfer'…
ProGamerGov Mar 30, 2025
eb9409c
Merge branch 'master-0-new-1' of https://github.com/ProGamerGov/captu…
ProGamerGov Mar 30, 2025
71fa7d6
Linting fixes
ProGamerGov Mar 30, 2025
9fa9b5d
optimvizz -> optimvis
ProGamerGov Mar 30, 2025
caeac1a
Update loss.py
ProGamerGov Mar 30, 2025
74d8771
Update README.md
ProGamerGov Apr 3, 2025
fff026c
Update README.md
ProGamerGov Apr 3, 2025
70bcd39
Update README.md
ProGamerGov Apr 3, 2025
283df8f
Update README.md
ProGamerGov Apr 3, 2025
64d4b04
Merge branch 'pytorch:master' into master-optim
ProGamerGov Apr 3, 2025
314e150
Add files via upload
ProGamerGov Apr 3, 2025
df2e5cd
Add files via upload
ProGamerGov Apr 3, 2025
cad91bf
Add files via upload
ProGamerGov Apr 3, 2025
0450121
Fix github notebook error
ProGamerGov Apr 3, 2025
c97d91c
Create test_file_downloads.py
ProGamerGov Apr 3, 2025
09d20f6
Update test_file_downloads.py
ProGamerGov Apr 3, 2025
acb7c13
Update test_file_downloads.py
ProGamerGov Apr 3, 2025
a206001
Update test_file_downloads.py
ProGamerGov Apr 3, 2025
7f5c5d2
Update README.md
ProGamerGov Apr 3, 2025
efebd08
Update README.md
ProGamerGov Apr 3, 2025
a649dd4
Update README.md
ProGamerGov Apr 3, 2025
d848c2d
Update README.md
ProGamerGov Apr 3, 2025
6c7fb9c
Remove model
ProGamerGov Apr 4, 2025
23ba83c
Merge branch 'pytorch:master' into master-optim
ProGamerGov Apr 10, 2025
cd31944
Create algorithms.md
ProGamerGov Apr 10, 2025
a7c79cb
Create optimvis_overview.md
ProGamerGov Apr 10, 2025
83cadc6
Update optimvis_overview.md
ProGamerGov Apr 10, 2025
a6fe7a6
Update optimvis_overview.md
ProGamerGov Apr 10, 2025
77a4f86
Update optimvis_overview.md
ProGamerGov Apr 10, 2025
e1b4ea3
Update optimvis_overview.md
ProGamerGov Apr 10, 2025
8b140a5
Update optimvis_overview.md
ProGamerGov Apr 10, 2025
a584725
Rename README.md to README_old.md
ProGamerGov Apr 10, 2025
622478b
Rename optimvis_overview.md to README.md
ProGamerGov Apr 10, 2025
49f79ed
Delete README_old.md
ProGamerGov Apr 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions captum/optim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
captum-optim Module Overview
=================

About Optim
-----------------

The Optim module is a set tools for optimization based interpretability for neural networks. It is a continuation of the research work performed by the team behind the [tensorflow/lucid](https://github.com/tensorflow/lucid) library.


The Optim module is designed to be extremely customizable, as to avoid limitations in its research potential.

History
-----------------

The initial concept for the Optim module was devised by Ludwig Shubert, and then developed by Ben Egan and Swee Kiat Lim with help from Chris Olah & Narine Kokhlikyan. This is project began as an attempt to integrate the tensorflow/lucid library into the pytorch/captum library. It implements numerous papers on feature visualization and interpretability.


Optim Structure
-----------------

![](https://user-images.githubusercontent.com/10626398/177629584-33e7ff7c-a504-404e-a7ab-d8d786b7e25a.svg?sanitize=true)

The standard rendering process works like this for the forward pass, with loss objectives being able to target any of the steps:

* ``NaturalImage`` (``ImageParameterization`` ➔ ``ToRGB`` ➔ Squash Function ➔ ``ImageTensor``) ➔ Transforms ➔ Model


Parameterizations
-----------------

The default settings store image parameters in a fully decorrelated format where the spatial information and channel information is decorrelated. By preconditioning our optimizer with decorrelated data, we alter the loss landscape to make optimization significantly easier and decrease the presence of high frequency patterns. Parameterizations like these are also known as a differentiable image parameterizations.

![](https://user-images.githubusercontent.com/10626398/176753493-b90f4e18-0133-4dca-afd4-26e811aa965e.svg?sanitize=true)

* Decorrelated Data ➔ Recorrelate Spatial ➔ Recorrelate Color ➔ Squash Function ➔ Transforms ➔ Model

By default, recorrelation occurs entirely within the ``NaturalImage`` class.


Submodules
-----------------

**Reducer**: The reducer module makes it easy to perform dimensionality reduction with a wide array of algorithms like [t-SNE](https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html), [UMAP](https://umap-learn.readthedocs.io/en/latest/), [PCA](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html), & [NMF](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.NMF.html).

**Circuits**: The circuits module allows for the extraction of meaningful weight interactions from between neurons which aren’t literally adjacent in a neural network.

**Models**: The models module contains the model zoo of pretrained models along with various help functions and classes.

**Dataset**: The dataset module provides functions for calculating color correlation matrices of image datasets.


Docs
-----------------

The docs for the optim module can be found here.


Tutorials
-----------------

We also provide multiple tutorials covering a wide array of research for the optim module [here](https://github.com/ProGamerGov/captum/tree/master-optim/tutorials/optimvis).


FAQ
=================

**How do I know if my model is compatible with the Optim module?**

In general model layers need to be nn.Modules as functional layers don't support hooks and also cannot be replaced.
Please check out the 'Getting Started Model Preparation' tutorial notebook for more information.

**Are only RGB images supported or can I use a different color space?**

By default the rendering modules in Optim are setup for rendering RGB images, but they can easily support other [color spaces](https://en.wikipedia.org/wiki/Color_space) with a simple settings change. In the case of ``ToRGB``, you may have to provide a new 3x3 transform matrix for 3 channel color spaces. For color spaces using less than or greater than 3 channels, you will need to create a custom color recorrelation module to replace ``ToRGB``. New color correlation matrices can be created using the dataset module, or with your own custom algorithms.

**Why are my rendered visualizations poor quality or non-existent in outputs?**

There are a wide array of factors that dictate how well a model performs for rendering visualizations. Aspects like the model architecture, the training data used to train the model, the optimizer being used, and your Optim module settings like parameterizations & transforms all play an important role in creating visualizations.

ReLU layers will block the flow of gradients during the backward pass, if their inputs are less than 0. This can result in no visualizations being produced for the target, even if the model already performs well with other targets. To avoid this issue, you can ensure that all applicable ReLU layers have been replaced with Optim's ``RedirectedReLU`` layer (the ``replace_layers`` function makes this extremely easy to do!).

**Does the Optim module support JIT?**

For the most part, yes. Image parameterizations, transforms, and many of the helper classes & functions support JIT. The provided models also support JIT, but rendering JIT models with ``InputOptimizatization`` is not supported. The ``InputOptimizatization`` class itself does not support JIT either, but it does work with scripted image parameterizations and transforms. The loss objective system also does not support JIT. These limitations are due to the limitations with JIT supporting PyTorch hooks.

**What dtypes does the Optim module support?**

In addition to the default ``torch.float32`` dtype, the Optim module also easily support the other float dtypes.

The ``FFTImage`` parameterization currently doesn't work with ``torch.float16`` or ``torch.bfloat16`` due to issues with PyTorch's support for ``torch.complex32``.


References
-----------------

* Feature Visualization: https://distill.pub/2017/feature-visualization/

* Differentiable Image Parameterizations: https://distill.pub/2018/differentiable-parameterizations/

* The Building Blocks of Interpretability: https://distill.pub/2018/building-blocks/

* Exploring Neural Networks with Activation Atlases: https://distill.pub/2019/activation-atlas/

* Understanding Deep Image Representations by Inverting Them: https://arxiv.org/abs/1412.0035

* Color information for region segmentation: https://www.sciencedirect.com/science/article/pii/0146664X80900477

* Thread: Circuits: https://distill.pub/2020/circuits/

* Visualizing Weights: https://distill.pub/2020/circuits/visualizing-weights/

* Weight Banding: https://distill.pub/2020/circuits/weight-banding/

* Zoom in: https://distill.pub/2020/circuits/zoom-in/

* Curve Detectors: https://distill.pub/2020/circuits/curve-detectors/

* Frequency Edges: https://distill.pub/2020/circuits/frequency-edges/

* Multimodal Neurons in Artificial Neural Networks: https://distill.pub/2021/multimodal-neurons/
37 changes: 37 additions & 0 deletions captum/optim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""optim submodule."""

from captum.optim import models # noqa: F401
from captum.optim._core import loss, optimization # noqa: F401
from captum.optim._core.optimization import InputOptimization # noqa: F401
from captum.optim._param.image import images, transforms # noqa: F401
from captum.optim._param.image.images import ImageTensor # noqa: F401
from captum.optim._utils import circuits, reducer # noqa: F401
from captum.optim._utils.image import atlas, dataset # noqa: F401 # noqa: F401
from captum.optim._utils.image.common import ( # noqa: F401
hue_to_rgb,
make_grid_image,
nchannels_to_rgb,
save_tensor_as_image,
show,
weights_to_heatmap_2d,
)

__all__ = [
"InputOptimization",
"ImageTensor",
"loss",
"optimization",
"images",
"transforms",
"circuits",
"models",
"reducer",
"make_grid_image",
"atlas",
"dataset",
"hue_to_rgb",
"nchannels_to_rgb",
"save_tensor_as_image",
"show",
"weights_to_heatmap_2d",
]
Empty file added captum/optim/_core/__init__.py
Empty file.
Loading