Skip to main content

WassersteinGAN_GP-PyTorch

Update (Feb 21, 2020)

The mnist and fmnist models are now available. Their usage is identical to the other models:

from wgangp_pytorch import Generator
model = Generator.from_pretrained('g-mnist') 

Overview

This repository contains an op-for-op PyTorch reimplementation of Improved Training of Wasserstein GANs.

The goal of this implementation is to be simple, highly extensible, and easy to integrate into your own projects. This implementation is a work in progress -- new features are currently being implemented.

At the moment, you can easily:

  • Load pretrained Generate models
  • Use Generate models for extended dataset

Upcoming features: In the next few days, you will be able to:

  • Quickly finetune an Generate on your own dataset
  • Export Generate models for production

Table of contents

  1. About Wasserstein GAN GP
  2. Model Description
  3. Installation
  4. Usage
  5. Contributing

About Wasserstein GAN GP

If you're new to Wasserstein GAN GP, here's an abstract straight from the paper:

Generative Adversarial Networks (GANs) are powerful generative models, but suffer from training instability. The recently proposed Wasserstein GAN (WGAN) makes progress toward stable training of GANs, but sometimes can still generate only low-quality samples or fail to converge. We find that these problems are often due to the use of weight clipping in WGAN to enforce a Lipschitz constraint on the critic, which can lead to undesired behavior. We propose an alternative to clipping weights: penalize the norm of gradient of the critic with respect to its input. Our proposed method performs better than standard WGAN and enables stable training of a wide variety of GAN architectures with almost no hyperparameter tuning, including 101-layer ResNets and language models over discrete data. We also achieve high quality generations on CIFAR-10 and LSUN bedrooms.

Model Description

We have two networks, G (Generator) and D (Discriminator).The Generator is a network for generating images. It receives a random noise z and generates images from this noise, which is called G(z).Discriminator is a discriminant network that discriminates whether an image is real. The input is x, x is a picture, and the output is D of x is the probability that x is a real picture, and if it's 1, it's 100% real, and if it's 0, it's not real.

Installation

Install from pypi:

pip install wgangp_pytorch

Install from source:

git clone https://github.com/Lornatang/WassersteinGAN_GP-PyTorch.git
cd WassersteinGAN_gp-PyTorch
pip install -e .

Usage

Loading pretrained models

Load an Wasserstein GAN GP:

from wgangp_pytorch import Generator
model = Generator.from_name("g-mnist")

Load a pretrained Wasserstein GAN GP:

from wgangp_pytorch import Generator
model = Generator.from_pretrained("g-mnist")

Example: Extended dataset

As mentioned in the example, if you load the pre-trained weights of the MNIST dataset, it will create a new imgs directory and generate 64 random images in the imgs directory.

import os
import torch
import torchvision.utils as vutils
from wgangp_pytorch import Generator

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

model = Generator.from_pretrained("g-mnist")
model.to(device)
# switch to evaluate mode
model.eval()

try:
    os.makedirs("./imgs")
except OSError:
    pass

with torch.no_grad():
    for i in range(64):
        noise = torch.randn(64, 100, device=device)
        fake = model(noise)
        vutils.save_image(fake.detach(), f"./imgs/fake_{i:04d}.png", normalize=True)
    print("The fake image has been generated!")

Example: Visual

cd $REPO$/framework
sh start.sh

Then open the browser and type in the browser address http://127.0.0.1:10003/. Enjoy it.

Contributing

If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues.

I look forward to seeing what the community does with these models!

Metadata

Release files for wgangp-pytorch 0.1.4

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

Source distribution (sdist)

Source distribution for wgangp-pytorch 0.1.4
File Size Uploaded Provenance Actions
wgangp_pytorch-0.1.4.tar.gz 7.3 kB Without provenance Details for wgangp_pytorch-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wgangp-pytorch 0.1.4
File Interpreter ABI Platform Actions
wgangp_pytorch-0.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details for wgangp_pytorch-0.1.4-py2.py3-none-any.whl

Total release size: 19.0 kB

Release files / wgangp_pytorch-0.1.4.tar.gz

Download URL wgangp_pytorch-0.1.4.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fbdd840129357f95e6213bdb285417c66374d696ca2a9a7673527e27c652e976
BLAKE2b-256 checksum
How to use checksums
ae94551f1b103d6bb7670622429a483e69dddba2ca7109f208e81b3bd2c00a87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / wgangp_pytorch-0.1.4-py2.py3-none-any.whl

Download URL wgangp_pytorch-0.1.4-py2.py3-none-any.whl
Size 11.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
db83e37091fb4999118c855c960fa1f11b246023c4d707986c50b46d4a7acb44
BLAKE2b-256 checksum
How to use checksums
e8eb2983ad3acd279945608ed2485cb5ce9ce6976695d534c23c1a9658b0514f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Security for wgangp-pytorch 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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