Skip to main content

Latent Shift - A Simple Autoencoder Approach to Counterfactual Generation

Open In Colab

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: latentshift.gif

Animations/GIFs

Smiling Arched Eyebrows
Mouth Slightly Open Young

Generating a transition sequence

For a predicting of smiling

gen_sequence.png

Multiple different targets

Comparison to traditional methods

For a predicting of pointy_nose

comparison.png

Getting Started

$pip install latentshift
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)

Metadata

Release files for latentshift 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for latentshift 0.0.6
File Size Uploaded
latentshift-0.0.6.tar.gz 19.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for latentshift 0.0.6
File Interpreter ABI Platform
latentshift-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 41.5 kB

Release files / latentshift-0.0.6.tar.gz

Download URL latentshift-0.0.6.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dec6b76952c664619e63d1ab2d03d9c20db6defd64d5db191262cca96bbdde85
BLAKE2b-256 checksum
How to use checksums
9336eff50a708b95d33f0f2085efa2cc4041bbef3b9b0d1b297e653d51b5a12f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.1

Release files / latentshift-0.0.6-py3-none-any.whl

Download URL latentshift-0.0.6-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc01ff6d8f376c592bf0b294d82e8884611d66d60d7f231d4a3ee8d68c407bff
BLAKE2b-256 checksum
How to use checksums
d4241c1cf43d20708aa2d202d3ee0a99504f2b6891c5aeed145f6fcd39016454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page