Skip to content

pwlot/contrastflow

Repository files navigation

ContrastFlow

Searchable Intervention Dynamics for GAN Generators

Archival 2019 experiment. Kept for reproducibility and historical context. README refreshed in May 2026 for public release.

ContrastFlow is a winter-2019 AutoGAN extension that adds recurrent local contrast-transport cells to GAN generators so internal feature dynamics can be searched, visualized, ablated, and steered.

ContrastFlow recurrent local flow updates

The visualizer shows a recurrent feature map update, not a final generated image. Each frame is one local contrast-transport step inside the generator.

initial feature state middle recurrent state final recurrent state
state 00 state 03 state 06

The central idea is to make part of the generator explicitly dynamical:

h[t+1] = h[t] + gate(h[t]) * Transport(Contrast(h[t]), local_neighbors)

Instead of interpreting a GAN only after training, ContrastFlow exposes a designed intervention surface during generation.

flowchart LR
    A["feature map h(t)"] --> B["local contrast"]
    B --> C["local transport"]
    C --> D["gated recurrent update"]
    D --> E["intervention handle"]
    E --> F["feature map h(t+1)"]
Loading

In this README, "causal" means explicit ablation and intervention handles inside the generator. It does not mean formal causal discovery.

Novelty in the 2019 Context

By late 2019, AutoGAN had shown GAN architecture search, SAGAN had established self-attention for long-range feature interaction, Dynamic Filter Networks had shown adaptive local filters, GAN Dissection had shown causal unit intervention, and latent-space steering methods were emerging.

ContrastFlow's claim is the combination:

  1. searchable GAN primitive inside the AutoGAN-style search space
  2. recurrent local contrast transport over feature maps
  3. built-in intervention handles for generator dynamics
  4. contrastive prediction over internal recurrent time

The claim is not that ContrastFlow was the first recurrent GAN layer, the first interpretable GAN method, or the first GAN steering method. The contribution is an early combination of GAN NAS, local recurrent feature transport, and designed causal intervention hooks.

Why This Matters Now

ContrastFlow was an early attempt to make neural generation inspectable and steerable from inside the model, not only through prompts, latents, or post-hoc visualization. The useful historical signal is the direction: model internals as systems that can be searched, watched, ablated, and controlled.

Components

  • contrastflow/layer.py - differentiable recurrent local contrast transport
  • contrastflow/interventions.py - strength, mask, freeze, and reverse controls
  • contrastflow/contrastive_loss.py - internal-time contrastive prediction
  • contrastflow/visualizer.py - state maps and flow GIF export
  • models/autogan_contrastflow.py - AutoGAN generator with ContrastFlow cells
  • contrastflow/search_space.py - 2019-style search-space knobs

2019 Tooling

This repository intentionally keeps a 2019-era stack:

  • Python 3.6
  • PyTorch 1.1
  • torchvision 0.3
  • NumPy / SciPy
  • Matplotlib / imageio
  • TensorBoard / tensorboardX

Install:

pip install -r requirements.txt

Train the ContrastFlow AutoGAN variant:

sh exps/contrastflow_cifar10.sh

Run the local layer visualizer:

python demos/visualize_contrastflow.py

Docker reproduction for the 2019 environment:

docker build -f docker/Dockerfile.cuda9 -t contrastflow:2019 .
docker run --rm --gpus all -v "$PWD:/workspace" -w /workspace contrastflow:2019 python demos/visualize_contrastflow.py

Intervention Handles

ContrastFlow exposes feature-dynamics controls:

  • flow_strength
  • contrast_gain
  • region_mask
  • channel_mask
  • freeze_flow
  • reverse_flow

These allow direct tests of which recurrent step, region, or channel group is responsible for local structure.

Ablations

The intended comparisons are:

  1. vanilla AutoGAN
  2. AutoGAN plus ConvLSTM-style recurrence
  3. AutoGAN plus dynamic local filtering
  4. AutoGAN plus self-attention / SAGAN-style block
  5. ContrastFlow without recurrence
  6. ContrastFlow without contrastive prediction loss
  7. ContrastFlow without intervention hooks

See docs/ablation_plan.md.

AutoGAN Base

This repository started from the public AutoGAN implementation:

@InProceedings{Gong_2019_ICCV,
author = {Gong, Xinyu and Chang, Shiyu and Jiang, Yifan and Wang, Zhangyang},
title = {AutoGAN: Neural Architecture Search for Generative Adversarial Networks},
booktitle = {The IEEE International Conference on Computer Vision (ICCV)},
month = {Oct},
year = {2019}
}

ContrastFlow builds on that AutoGAN code path as a 2019-era generator dynamics experiment.

About

AutoGAN extension for searchable, steerable GAN feature dynamics.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors