https://github.com/ieee8023/latentshift
A method to generate counterfactuals
https://github.com/ieee8023/latentshift
Last synced: 5 months ago
JSON representation
A method to generate counterfactuals
- Host: GitHub
- URL: https://github.com/ieee8023/latentshift
- Owner: ieee8023
- Created: 2022-09-05T23:46:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T06:30:48.000Z (12 months ago)
- Last Synced: 2024-11-07T03:08:00.903Z (6 months ago)
- Language: Jupyter Notebook
- Homepage:
- Size: 14.9 MB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Citation: CITATION
Awesome Lists containing this project
README
# Latent Shift - A Simple Autoencoder Approach to Counterfactual Generation
[](https://colab.research.google.com/github/ieee8023/latentshift/blob/main/example.ipynb)
# The idea
Read the paper about Latent Shift: https://arxiv.org/abs/2102.09475
Watch a video: https://www.youtube.com/watch?v=1fxSDP8DheI
Read the paper about Counterfactual Alignment: https://arxiv.org/abs/2312.02186
The main diagram:
## Animations/GIFs
| Smiling
| Arched Eyebrows
|
| ----------- | ----------- |
||
|
|Mouth Slightly Open
| Young
|
| ----------- | ----------- |
||
|
# Generating a transition sequence
For a predicting of `smiling`

# Multiple different targets
# Comparison to traditional methodsFor a predicting of `pointy_nose`

# Getting Started
```bash
$pip install latentshift
```````python3
import latentshift
# Load classifier and autoencoder
model = latentshift.classifiers.FaceAttribute(download=True)
ae = latentshift.autoencoders.VQGAN(weights="faceshq", download=True)# Load image
input = torch.randn(1, 3, 1024, 1024)# Defining Latent Shift module
attr = captum.attr.LatentShift(model, ae)# Computes counterfactual for class 3.
output = attr.attribute(input, target=3)
```