Code Monkey home page Code Monkey logo

latentclr's Introduction

LatentCLR: A Contrastive Learning Approach for Unsupervised Discovery of Interpretable Directions

Installation

Install the dependencies in env.yml

$ conda env create -f env.yml
$ conda activate latentclr-env

and download the wordnet as follows:

import nltk
nltk.download('wordnet')

Quickstart

For a quick demo, see DEMO.

Hydra Usage

The repository uses Hydra framework to manage experiments. We provide three main experiments:

train.py: Trains a model from scratch. eval.py: Evaluates a pre-trained model. gen.py: Generates samples with the given model.

Use --help to list all experiment parameters and help on Hydra usage:

python train.py --help

Hydra will output experiment results under outputs folder. Outputs of train and eval tasks will be under runfolder while results of generation experiments will be scaffolded first by date and then time of the day.

Examples

Train 32 nonlinear directions with BigGAN and class bulbul by targeting feature layer generator.layers.4.

python train.py k=32 generator=biggan generator.feature_layer=generator.layers.4 generator.class_name=bulbul model=nonlinear hparams.batch_size=16 model.alpha='[-3.0,+3.0]'

Train 100 nonlinear directions with StyleGAN2 and class ffhq by targeting feature layer conv1.

python train.py k=100 generator=stylegan2 generator.feature_layer=conv1 hparams.batch_size=8 generator.class_name=ffhq model=nonlinear model.alpha=1

Generate 5 images from the first 4 directions of a pre-trained model located at $PATH

python gen.py \
        --config-path="$PATH/.hydra"
        --config-name=config \
        checkpoint="$PATH/best_model.pt"
        +n_samples=5 \
        +alphas="[-15,-10,-5,5,10,15]" \
        +iterative=False \
        +image_size=256 \
        +n_dirs=[0,1,2,3] \

You can also use feed_layers (takes a list of layer indices) option to only activate changes in certain layers of the generator (both in training and generation).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.