PyTorch implements a simple GAN neural network structure.
Project description
DCGAN-PyTorch
Update (January 29, 2020)
The mnist and fmnist models are now available. Their usage is identical to the other models:
from dcgan_pytorch import Generator
model = Generator.from_pretrained('g-mnist')
Overview
This repository contains an op-for-op PyTorch reimplementation of Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks.
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
- About Deep Convolutional Generative Adversarial Networks
- Model Description
- Installation
- Usage
- Contributing
About Deep Convolutional Generative Adversarial Networks
If you're new to DCGAN, here's an abstract straight from the paper:
In recent years, supervised learning with convolutional networks (CNNs) has seen huge adoption in computer vision applications. Comparatively, unsupervised learning with CNNs has received less attention. In this work we hope to help bridge the gap between the success of CNNs for supervised learning and unsupervised learning. We introduce a class of CNNs called deep convolutional generative adversarial networks (DCGANs), that have certain architectural constraints, and demonstrate that they are a strong candidate for unsupervised learning. Training on various image datasets, we show convincing evidence that our deep convolutional adversarial pair learns a hierarchy of representations from object parts to scenes in both the generator and discriminator. Additionally, we use the learned features for novel tasks - demonstrating their applicability as general image representations.
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 dcgan_pytorch
Install from source:
git clone https://github.com/Lornatang/DCGAN-PyTorch.git
cd DCGAN-PyTorch
pip install -e .
Usage
Loading pretrained models
Load an Deep-Convolutional-Generative-Adversarial-Networks:
from dcgan_pytorch import Generator
model = Generator.from_name("g-mnist")
Load a pretrained Deep-Convolutional-Generative-Adversarial-Networks:
from dcgan_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 dcgan_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, 1, 1, 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:10001/. 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!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dcgan_pytorch-0.2.0.tar.gz
.
File metadata
- Download URL: dcgan_pytorch-0.2.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efde0b8455c8a6e62d295b0e7c48800c0c0f93ca865b22948ef9d948e841f5c9 |
|
MD5 | 9ce125811837817526a2435a9582eec2 |
|
BLAKE2b-256 | 317b910e839ce4f45129ee16b843bc71c98c69a8a9c2a8d2c7a8607552b48afd |
File details
Details for the file dcgan_pytorch-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: dcgan_pytorch-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c068c93a98533f9cf40541f122fa1a674bdd99b340a92d8f6bcf6dd91a9673ac |
|
MD5 | 29d8c50ec01865cd6880800108a45e4b |
|
BLAKE2b-256 | 145281fd76a2efbc2e6e4dc1cb1e2abc44567c65303f32e87cd41f10bc5acc1f |