All Projects → EugenHotaj → Pytorch Generative

EugenHotaj / Pytorch Generative

Licence: mit
Easy generative modeling in PyTorch.

Projects that are alternatives of or similar to Pytorch Generative

Multi Viewpoint Image Generation
Given an image and a target viewpoint, generate synthetic image in the target viewpoint
Stars: ✭ 23 (-79.46%)
Mutual labels:  jupyter-notebook, image-generation
Hidt
Official repository for the paper "High-Resolution Daytime Translation Without Domain Labels" (CVPR2020, Oral)
Stars: ✭ 513 (+358.04%)
Mutual labels:  jupyter-notebook, image-generation
Swapnet
Virtual Clothing Try-on with Deep Learning. PyTorch reproduction of SwapNet by Raj et al. 2018. Now with Docker support!
Stars: ✭ 202 (+80.36%)
Mutual labels:  jupyter-notebook, image-generation
Ganspace
Discovering Interpretable GAN Controls [NeurIPS 2020]
Stars: ✭ 1,224 (+992.86%)
Mutual labels:  jupyter-notebook, image-generation
Python Bigdata
Data science and Big Data with Python
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
An Introduction To Statistical Learning
This repository contains the exercises and its solution contained in the book "An Introduction to Statistical Learning" in python.
Stars: ✭ 1,843 (+1545.54%)
Mutual labels:  jupyter-notebook
Stock Market Analysis And Prediction
Stock Market Analysis and Prediction is the project on technical analysis, visualization and prediction using data provided by Google Finance.
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Pydata Book
利用Python进行数据分析(https://read.douban.com/reader/ebook/15249337/)源代码整理版
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Developerworks
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Data Scientists Guide Apache Spark
Best practices of using Spark for practicing data scientists in the context of a data scientist’s standard workflow.
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Carnd Tensorflow Lab
TensorFlow Lab for Self-Driving Car ND
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Hello World
Add any Program in any language you like or add a hello world Program ❣️ if you like give us ⭐
Stars: ✭ 1,464 (+1207.14%)
Mutual labels:  jupyter-notebook
Krisk
Statistical Interactive Visualization with pandas+Jupyter integration on top of Echarts.
Stars: ✭ 111 (-0.89%)
Mutual labels:  jupyter-notebook
Deepfashion2
DeepFashion2 Dataset https://arxiv.org/pdf/1901.07973.pdf
Stars: ✭ 1,628 (+1353.57%)
Mutual labels:  jupyter-notebook
Numerical Python Book Code
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Ctc Executioner
Master Thesis: Limit order placement with Reinforcement Learning
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Ml Study
ML Learning Sabbatical Study Materials
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Nips2015 Action Conditional Video Prediction
Implementation of "Action-Conditional Video Prediction using Deep Networks in Atari Games"
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Mlf Mlt
📚 机器学习基石和机器学习技法作业
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook
Sigver wiwd
Learned representation for Offline Handwritten Signature Verification. Models and code to extract features from signature images.
Stars: ✭ 112 (+0%)
Mutual labels:  jupyter-notebook

pytorch-generative

pytorch-generative is a Python library which makes generative modeling in PyTorch easier by providing:

  • high quality reference implementations of SOTA generative models
  • useful abstractions of common building blocks found in the literature
  • utilities for training, debugging, and working with Google Colab
  • integration with TensorBoard for easy metrics visualization

To get started, click on one of the links below.

Installation

To install pytorch-generative, clone the repository and install the requirements:

git clone https://www.github.com/EugenHota/pytorch-generative
cd pytorch-generative
pip install -r requirements.txt

After installation, run the tests to sanity check that everything works:

python -m unittest discover

Reproducing Results

All our supported algorithms section. This makes it very easy to reproduce any results using our training script, for example:

python train.py --model image_gpt --logdir /tmp/run --use-cuda

Training metrics will periodically be logged to TensorBoard for easy visualization. To view these metrics, launch a local TensorBoard server:

tensorboard --logdir /tmp/run

To run the model on a different dataset, with different hyperparameters, etc, simply modify its reproduce function and rerun the commands above.

Google Colab

To use pytorch-generative in Google Colab, clone the repository and move it into the top-level directory:

!git clone https://www.github.com/EugenHotaj/pytorch-generative
!mv pytorch-generative/pytorch_generative pytorch-generative

You can then import pytorch-generative like any other library:

import pytorch_generative as pg_nn
from pytorch_generative import models
...

Example - ImageGPT

Supported models are implemented as PyTorch Modules and are easy to use:

from pytorch_generative import models

... # Data loading code.

model = models.ImageGPT(in_channels=1, out_channels=1, in_size=28)
model(batch)

Alternatively, lower level building blocks in pytorch_generative.nn can be used to write models from scratch. We show how to implement a convolutional ImageGPT model below:

from torch import nn

from pytorch_generative import nn as pg_nn


class TransformerBlock(nn.Module):
  """An ImageGPT Transformer block."""

  def __init__(self, 
               n_channels, 
               n_attention_heads):
    """Initializes a new TransformerBlock instance.
    
    Args:
      n_channels: The number of input and output channels.
      n_attention_heads: The number of attention heads to use.
    """
    super().__init__()
    self._ln1 = pg_nn.NCHWLayerNorm(n_channels)
    self._ln2 = pg_nn.NCHWLayerNorm(n_channels)
    self._attn = pg_nn.CausalAttention(
        in_channels=n_channels,
        embed_channels=n_channels,
        out_channels=n_channels,
        n_heads=n_attention_heads,
        mask_center=False)
    self._out = nn.Sequential(
        nn.Conv2d(
            in_channels=n_channels, 
            out_channels=4*n_channels, 
            kernel_size=1),
        nn.GELU(),
        nn.Conv2d(
            in_channels=4*n_channels, 
            out_channels=n_channels, 
            kernel_size=1))

  def forward(self, x):
    x = x + self._attn(self._ln1(x))
    return x + self._out(self._ln2(x))


class ImageGPT(nn.Module):
  """The ImageGPT Model."""
  
  def __init__(self,       
               in_channels,
               out_channels,
               in_size,
               n_transformer_blocks=8,
               n_attention_heads=4,
               n_embedding_channels=16):
    """Initializes a new ImageGPT instance.
    
    Args:
      in_channels: The number of input channels.
      out_channels: The number of output channels.
      in_size: Size of the input images. Used to create positional encodings.
      n_transformer_blocks: Number of TransformerBlocks to use.
      n_attention_heads: Number of attention heads to use.
      n_embedding_channels: Number of attention embedding channels to use.
    """
    super().__init__()
    self._pos = nn.Parameter(torch.zeros(1, in_channels, in_size, in_size))
    self._input = pg_nn.CausalConv2d(
        mask_center=True,
        in_channels=in_channels,
        out_channels=n_embedding_channels,
        kernel_size=3,
        padding=1)
    self._transformer = nn.Sequential(
        *[TransformerBlock(n_channels=n_embedding_channels,
                         n_attention_heads=n_attention_heads)
          for _ in range(n_transformer_blocks)])
    self._ln = pg_nn.NCHWLayerNorm(n_embedding_channels)
    self._out = nn.Conv2d(in_channels=n_embedding_channels,
                          out_channels=out_channels,
                          kernel_size=1)

  def forward(self, x):
    x = self._input(x + self._pos)
    x = self._transformer(x)
    x = self._ln(x)
    return self._out(x)

Supported Algorithms

pytorch-generative supports the following algorithms.

We train likelihood based models on dynamically Binarized MNIST and report the log likelihood in the tables below.

Autoregressive Models

Algorithm Binarized MNIST (nats) Links
PixelSNAIL 78.61 Code, Paper
ImageGPT 79.17 Code, Paper
Gated PixelCNN 81.50 Code, Paper
PixelCNN 81.45 Code, Paper
MADE 84.87 Code, Paper
NADE 85.65 Code, Paper

Variational Autoencoders

NOTE: The results below are the (variational) upper bound on the negative log likelihod (or equivalently, the lower bound on the log likelihod).

Algorithm Binarized MNIST (nats) Links
VD-VAE <= 80.72 Code, Paper
VAE <= 86.77 Code, Paper
BetaVAE N/A Code, Paper
VQ-VAE N/A Code, Paper
VQ-VAE-2 N/A Code, Paper

Neural Style Transfer

Blog: https://towardsdatascience.com/how-to-get-beautiful-results-with-neural-style-transfer-75d0c05d6489
Notebook: https://github.com/EugenHotaj/pytorch-generative/blob/master/notebooks/style_transfer.ipynb
Paper: https://arxiv.org/abs/1508.06576

Compositional Pattern Producing Networks

Notebook: https://github.com/EugenHotaj/pytorch-generative/blob/master/notebooks/cppn.ipynb
Background: https://en.wikipedia.org/wiki/Compositional_pattern-producing_network

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].