Skip to main content

Personal toolbox for experimenting with Feature Visualization

Project description

Horama logo

Horama is a compact library designed for Feature Visualization experiments, initially providing the implementation code for the research paper Maco.

This repository also introduces various feature visualization methods, including a reimagined approach to the remarkable work by the Clarity team and an implementation of Feature Accentuation by Hamblin et al. For an official reproduction of Distill's work, complete with comprehensive notebooks, we highly recommend Lucent. However, Horama emphasizes experimentation and is not an official reproduction of any other paper aside from Maco within PyTorch.

  • Starter Notebook: Open in Google Colab

🚀 Getting Started with Horama

Horama requires Python 3.6 or newer and several dependencies, including Numpy. It supports both Tensorflow and Torch. Installation is straightforward with Pypi:

pip install horama

With Horama installed, you can dive into feature visualization. The API is designed to be intuitive across both Tensorflow and Pytorch frameworks, requiring only a few hyperparameters to get started.

Example usage:

import torch
import timm
from horama import maco, fourier, plot_maco

%config InlineBackend.figure_format = 'retina'

model = timm.create_model('resnet18', pretrained=True).cuda().eval()

objective = lambda images: torch.mean(model(images)[:, 1])

image1, alpha1 = maco(objective)
plot_maco(image1, alpha1)
plt.show()

image2, alpha2 = fourier(objective)
plot_maco(image2, alpha2)
plt.show()

Notebooks

  • Starter Notebook: Open in Google Colab
  • Feature Inversion: Coming soon
  • Feature Accentuation: Coming soon

Complete API

Complete API Guide Horama's API includes the following primary functions:

maco(objective_function,
     total_steps=1000,
     learning_rate=1.0,
     image_size=1000,
     model_input_size=224,
     noise=0.1,
     values_range=(-2.5, 2.5),
     crops_per_iteration=6,
     box_size=(0.20, 0.25),
     device='cuda')

fourier(objective_function,
        decay_power=1.5,
        total_steps=1000,
        learning_rate=1.0,
        image_size=1000,
        model_input_size=224,
        noise=0.1,
        values_range=(-2.5, 2.5),
        crops_per_iteration=6,
        box_size=(0.20, 0.25),
        device='cuda')

When optimizing, it's crucial to fine-tune the hyperparameters. Parameters like the decay spectrum in the Fourier method significantly impact the visual output, controlling the energy distribution across frequencies. Additionally, adjust the values_range to match your model's preprocessing requirements, and ensure model_input_size matches the expected input size of your model.

Citation

@article{fel2023maco,
      title={Unlocking Feature Visualization for Deeper Networks with MAgnitude Constrained Optimization},
      author={Thomas, Fel and Thibaut, Boissin and Victor, Boutin and Agustin, Picard and Paul, Novello and Julien, Colin and Drew, Linsley and Tom, Rousseau and Rémi, Cadène and Laurent, Gardes and Thomas, Serre},
      journal={Advances in Neural Information Processing Systems (NeurIPS)},
      year={2023},
}

Additional Resources

For a simpler and maintained implementation of the code for TensorFlow and the other feature visualization methods used in the paper, refer to the Xplique toolbox. Additionally, we have created a website called the LENS Project, which features the 1000 classes of ImageNet.

For code faithful to the original work of the Clarity team, we highly recommend Lucent.

Authors

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

horama-0.0.5.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

Horama-0.0.5-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file horama-0.0.5.tar.gz.

File metadata

  • Download URL: horama-0.0.5.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for horama-0.0.5.tar.gz
Algorithm Hash digest
SHA256 8f419beab6c2b5f05de39b433dc0d4750aa593d73b949b36472c6663e81b325f
MD5 48245ecf96ec12c21bba9011fe33c27b
BLAKE2b-256 df81a28078d0933b8768fb442ff897b1a8f4321d5b8b25692b055976b8108f61

See more details on using hashes here.

Provenance

File details

Details for the file Horama-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: Horama-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for Horama-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 17853b80a093e062fd828158d604508193e3136d63bbaa9236da846555b4bc4d
MD5 e110748c79a0a94dca8f9ad5e00007cf
BLAKE2b-256 c0bad91955d69d31562bbef6d5210880e9ec70e849209bdc09a4659d040fcc31

See more details on using hashes here.

Provenance

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