GithubHelp home page GithubHelp logo

sushmanthreddy / ganetic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kingjuno/ganetic

0.0 0.0 0.0 33.76 MB

A collection of highly customizable GANs implemented in PyTorch.

License: MIT License

Python 100.00%

ganetic's Introduction

GANetic

A collection of highly customizable GANs implemented in PyTorch.

Table of Contents

Installation

Stable version:

pip install ganetic

Latest version:

pip install git+https://github.com/kingjuno/ganetic.git

Usage

DCGAN

import torch

from ganetic.dcgan import Discriminator, Generator

netG = Generator(
    nz=100,  # length of latent vector
    nc=3,    # number of channels in the training images.
    ngf=64,  # size of feature maps in generator
)
netD = Discriminator(
    nc=3,    # number of channels in the training images.
    ndf=64,  # size of feature maps in discriminator
)

noise = torch.randn(1, 100)
fake_img = netG(noise)
prediction = netD(fake_img)

SRGAN

import torch

from ganetic.srgan import Generator, Discriminator

img = torch.randn(1, 3, 64, 64)
gen = Generator(
    scale_factor=4, # scale factor for super resolution
    nci=3,          # number of channels in input image
    nco=3,          # number of channels in output image
    ngf=64,         # number of filters in the generator
    no_of_residual_blocks=5
)
disc = Discriminator(
    input_shape=(3, 256, 256),
    ndf=64,              # number of filters in the discriminator
    negative_slope=0.2,  # negative slope of leaky relu
)

HR_img = gen(img)
pred = disc(HR_img)

Pix2Pix

import torch

from ganetic.pix2pix import Discriminator, Generator

img = torch.randn(1, 3, 256, 256)
gen = Generator(
    nci=3,  # number of channels in input image
    nco=3,  # number of channels in output image
    ngf=64  # number of filters in the generator
)

disc = Discriminator(
    nci=3,  # number of channels in input image
    ndf=64  # number of filters in the discriminator
)

fake = gen(img)
pred = disc(img, fake)

Conditional GANs

import torch

from ganetic.cgan import Discriminator, Generator

gen = Generator(
    n_classes=10,
    nz=100,
    nc=3,
    ngf=64,
    out_size=64,
    activation='relu',
    last_activation='tanh'
)
disc = Discriminator(
    n_classes=10,
    nc=3,
    ndf=64,
    in_size=64,
    activation='LeakyReLU',
    last_activation='sigmoid'
)

z = torch.randn(64, 100)
label = torch.LongTensor(64).random_(0, 10)

print(gen(z, label).shape)
print(disc(gen(z, label), label).shape)

CycleGAN

import torch

from ganetic.cyclegan import Discriminator, Generator

img = torch.randn(1, 3, 128, 128)

gen = Generator(
    nci=3,
    nco=3,
    ngf=64,
    no_of_residual_blocks=9,
    activation=torch.nn.ReLU(True),
    last_activation=torch.nn.Tanh(),
)
print(gen(img).shape)
disc = Discriminator(
    nci=3,
    ndf=64,
    no_of_layers=3,
    activation=torch.nn.ReLU(True),
    last_activation=torch.nn.Sigmoid(),
)
print(disc(img).shape)

vanilla_gan

import torch

from ganetic.vanilla_gan import Discriminator, Generator

img = torch.randn(1, 3, 128, 128)

gen = Generator()
print(gen(img).shape)
disc = Discriminator()
print(disc(img).shape)

Citations

@article{radford2015unsupervised,
  title={Unsupervised representation learning with deep convolutional generative adversarial networks},
  author={Radford, Alec and Metz, Luke and Chintala, Soumith},
  journal={arXiv preprint arXiv:1511.06434},
  year={2015}
}
@inproceedings{ledig2017photo,
  title={Photo-realistic single image super-resolution using a generative adversarial network},
  author={Ledig, Christian and Theis, Lucas and Husz{\'a}r, Ferenc and Caballero, Jose and Cunningham, Andrew and Acosta, Alejandro and Aitken, Andrew and Tejani, Alykhan and Totz, Johannes and Wang, Zehan and others},
  booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
  pages={4681--4690},
  year={2017}
}
@inproceedings{isola2017image,
  title={Image-to-image translation with conditional adversarial networks},
  author={Isola, Phillip and Zhu, Jun-Yan and Zhou, Tinghui and Efros, Alexei A},
  booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
  pages={1125--1134},
  year={2017}
}
@article{mirza2014conditional,
  title={Conditional generative adversarial nets},
  author={Mirza, Mehdi and Osindero, Simon},
  journal={arXiv preprint arXiv:1411.1784},
  year={2014}
}
@inproceedings{zhu2017unpaired,
  title={Unpaired image-to-image translation using cycle-consistent adversarial networks},
  author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A},
  booktitle={Proceedings of the IEEE international conference on computer vision},
  pages={2223--2232},
  year={2017}
}

ganetic's People

Contributors

kingjuno avatar sushmanthreddy avatar

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.