Skip to main content

A method to generate counterfactuals

Project description

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)

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

latentshift-0.0.5.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

latentshift-0.0.5-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: latentshift-0.0.5.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.0

File hashes

Hashes for latentshift-0.0.5.tar.gz
Algorithm Hash digest
SHA256 66eef8993fdb08e742e0f088dcda227d9f8c776878660490fa7240fe00e047da
MD5 8f37524f2d0cc20ea01794cd90e1012d
BLAKE2b-256 7343a8ff2d081304c511fca51ddc8c29638e193eea49470ec4bef3bda62aaf23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: latentshift-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.0

File hashes

Hashes for latentshift-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 332df53f71822cca35ddb9eb7af95d81cc77caf0071bb0d0a8b1e7763bd455dc
MD5 317b6e39e7a34a6dd40cbc378092559c
BLAKE2b-256 0a055d3b26debbdff6218e192e6c05003ed70ab3a91a94dbce04dbce35084005

See more details on using hashes here.

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