Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >一个很牛的GAN工具项目:HyperGAN

一个很牛的GAN工具项目:HyperGAN

作者头像
CreateAMind
发布于 2018-07-24 09:53:45
发布于 2018-07-24 09:53:45
98300
代码可运行
举报
文章被收录于专栏:CreateAMindCreateAMind
运行总次数:0
代码可运行

关注GAN的易于使用和可扩展

子模块丰富:

WGAN也有了;LS-GAN也有。

HyperGAN

A versatile GAN(generative adversarial network) implementation focused on scalability and ease-of-use.

Table of contents

  • Changelog
  • Quick start
    • Minimum Requirements
    • Install
    • Train
    • Increasing Performance
    • Development Mode
    • Running on CPU
  • Configuration
    • Usage
  • The pip package hypergan
    • Training
    • Sampling
    • Web Server
  • API
    • GAN object
  • Datasets
    • Supervised learning
    • Unsupervised learning
    • Creating a Dataset
    • Downloadable Datasets
  • About
    • WGAN

Changelog

0.7 - "WGAN API" (samples to come)

  • New loss function based on wgan :. Fixes many classes of mode collapse! See wgan implementation
  • Initial Public API Release
  • API example: colorizer - re-colorize an image!
  • API example: inpainter - remove a section of an image and have your GAN repaint it
  • API example: super-resolution - zoom in and enhance. We've caught the bad guy!
  • 4 new samplers. --sampler flag. Valid options are: batch,progressive,static_batch,grid.

0.6 ~ "MultiGAN"

  • 3 new encoders
  • New discriminator: densenet - based loosely on https://arxiv.org/abs/1608.06993
  • Updated discriminator: pyramid_no_stride - conv and avg_pool together
  • New generator: dense_resize_conv - original type of generator that seems to work well
  • Updated generator: resize_conv - standard resize-conv generator. This works much better than deconv, which is not supported.
  • Several quality of life improvements
  • Support for multiple discriminators
  • Support for discriminators on different image resolutions

0.5 ~ "FaceGAN"

0.5.x

  • fixed configuration save/load
  • cleaner cli output
  • documentation cleanup

图太大。

0.5.0

  • pip package released!
  • Better defaults. Good variance. 256x256. The broken images showed up after training for 5 days.

0.1-0.4

  • Initial private release

Quick start

Minimum requirements

  1. For 256x256, we recommend a GTX 1080 or better. 32x32 can be run on lower-end GPUs.
  2. CPU mode is extremely slow. Never train with it!
  3. Python3

Install hypergan

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  pip3 install hypergan --upgrade

Installing a specific version

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  pip3 install hypergan==0.5.8 --upgrade

Train

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  # Train a 32x32 gan with batch size 32 on a folder of pngs
  hypergan train [folder] -s 32x32x3 -f png -b 32

Increasing performance

On ubuntu sudo apt-get install libgoogle-perftools4 and make sure to include this environment variable before training

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  LD_PRELOAD="/usr/lib/libtcmalloc.so.4" hypergan train my_dataset

Development mode

If you wish to modify hypergan

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
git clone https://github.com/255BITS/hypergancd hypergan
python3 setup.py develop

Running on CPU

Make sure to include the following 2 arguments:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
CUDA_VISIBLE_DEVICES= hypergan --device '/cpu:0'

Configuration

Configuration in HyperGAN uses JSON files. You can create a new config by running hypergan train. By default, configurations are randomly generated using Hyperchamber.

Configurations are located in:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  ~/.hypergan/configs/

Usage

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  --config [name]

Naming a configuration during training is recommended. If your config is not named, a uuid will be used.

CLI

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 hypergan -h

Training

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  # Train a 256x256 gan with batch size 32 on a folder of pngs
  hypergan train [folder] -s 32x32x3 -f png -b 32 --config [name]

Sampling

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  # Train a 256x256 gan with batch size 32 on a folder of pngs
  hypergan train [folder] -s 32x32x3 -f png -b 32 --config [name] --sampler static_batch --sample_every 5

One way a network learns:

图太大。

To create videos:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  ffmpeg -i samples/%06d.png -vcodec libx264 -crf 22 -threads 0 gan.mp4

Web Server

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  # Train a 256x256 gan with batch size 32 on a folder of pngs
  hypergan serve [folder] -s 32x32x3 -f png -b 32 --config [name]

To prevent the GPU from allocating space, see Running on CPU.

API

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  import hypergan as hg

GAN object

The GAN object consists of:

  • The config(configuration) used
  • The graph - specific named Tensors in the Tensorflow graph
  • The tensorflow sess(session)

Constructor

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
GAN(config, initial_graph, graph_type='full', device='/gpu:0')

When a GAN constructor is called, the Tensorflow graph will be constructed.

Properties

gan.graph|Dictionary|Maps names to tensors gan.config|Dictionary|Maps names to options(from the json) gan.sess|tf.Session|The tensorflow session

Methods

save
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 gan.save(save_file)

save_file - a string designating the save path

Saves the GAN

sample_to_file
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 gan.sample_to_file(name, sampler=grid_sampler.sample)
  • name - the name of the file to sample to
  • sampler - the sampler method to use

Sample to a specified path.

train
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 gan.train()

Steps the gan forward in training once. Trains the D and G according to your specified trainer.

Datasets

To build a new network you need a dataset. Your data should be structured like:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  [folder]/[directory]/*.png

Creating a Dataset

Supervised learning

Training with labels allows you to train a classifier.

Each directory in your dataset represents a classification.

Example: Dataset setup for classification of apple and orange images:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 /dataset/apples
 /dataset/oranges

Unsupervised learning

You can still build a GAN if your dataset is unlabelled. Just make sure your folder is formatted like

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 [folder]/[directory]/*.png

where all files are in 1 directory.

Downloadable datasets

  • CelebA aligned faces http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html
  • MS Coco http://mscoco.org/
  • ImageNet http://image-net.org/

Building

hypergan build

Build takes the same arguments as train and builds a generator. It's required for serve.

Building does 2 things:

  • Loads the training model, which include the discriminator
  • Saves into a ckpt model containing only the generator

Server mode

hypergan serve

Serve starts a flask server. You can then access:

http://localhost:5000/sample.png?type=batch

Saves

Saves are stored in ~/.hypergan/saves/

They can be large.

Formats

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
--format <type>

Type can be one of:

  • jpg
  • png

Arguments

To see a detailed list, run

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  hypergan -h
  • -s, --size, optional(default 64x64x3), the size of your data in the form 'width'x'height'x'channels'
  • -f, --format, optional(default png), file format of the images. Only supports jpg and png for now.

Discriminators

The discriminators job is to tell if a piece of data is real or fake. In hypergan, a discriminator can also be a classifier.

You can combine multiple discriminators in a single GAN.

pyramid_stride

pyramid_nostride

Progressive enhancement is enabled by default:

Default.

densenet

Progressive enhancement is enabled by default here too.

resnet

Note: This is currently broken

Encoders

Vae

For Vae-GANs

RandomCombo

Default

RandomNormal

Generators

resize-conv

Standard resize-conv.

dense-resize-conv

Default. Inspired by densenet.

Trainers

Adam

Default.

Slowdown

Experimental.

About

Generative Adversarial Networks consist of 2 learning systems that learn together. HyperGAN implements these learning systems in Tensorflow with deep learning.

The discriminator learns the difference between real and fake data. The generator learns to create fake data.

For a more in-depth introduction, see here http://blog.aylien.com/introduction-generative-adversarial-networks-code-tensorflow/

A single fully trained GAN consists of the following useful networks:

  • generator - Generates content that fools the discriminator. If using supervised learning mode, can generate data on a specific classification.
  • discriminator - The discriminator learns how to identify real data and how to detect fake data from the generator.
  • classifier - Only available when using supervised learning. Classifies an image by type. Some examples of possible datasets are 'apple/orange', 'cat/dog/squirrel'. See Creating a Dataset.

HyperGAN is currently in open beta.

Wasserstein GAN in Tensorflow

Our implementation of WGAN is based off the paper. WGAN loss in Tensorflow can look like:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 d_fake = tf.reduce_mean(d_fake,axis=1)
 d_real = tf.reduce_mean(d_real,axis=1)
 d_loss = d_real - d_fake
 g_loss = d_fake

d_loss and g_loss can be reversed as well - just add a '-' sign.

Papers

  • GAN - https://arxiv.org/abs/1406.2661
  • DCGAN - https://arxiv.org/abs/1511.06434
  • InfoGAN - https://arxiv.org/abs/1606.03657
  • Improved GAN - https://arxiv.org/abs/1606.03498
  • Adversarial Inference - https://arxiv.org/abs/1606.00704
  • WGAN - https://arxiv.org/abs/1701.07875

Sources

  • DCGAN - https://github.com/carpedm20/DCGAN-tensorflow
  • InfoGAN - https://github.com/openai/InfoGAN
  • Improved GAN - https://github.com/openai/improved-gan
  • Hyperchamber - https://github.com/255bits/hyperchamber

Contributing

Contributions are welcome and appreciated. To help out, just issue a pull request or file a bug report.

If you create something cool with this let us know!

In case you are interested, our pivotal board is here: https://www.pivotaltracker.com/n/projects/1886395

Citation

If you wish to cite this project, do so like this:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  255bits (M. Garcia),
  HyperGAN, (2017), 
  GitHub repository, 
  https://github.com/255BITS/HyperGAN
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-03-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 CreateAMind 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
利用pytorch实现GAN(生成对抗网络)-MNIST图像-cs231n-assignment3
In 2014, Goodfellow et al. presented a method for training generative models called Generative Adversarial Networks (GANs for short). In a GAN, we build two different neural networks. Our first network is a traditional classification network, called the discriminator. We will train the discriminator to take images, and classify them as being real (belonging to the training set) or fake (not present in the training set). Our other network, called the generator, will take random noise as input and transform it using a neural network to produce images. The goal of the generator is to fool the discriminator into thinking the images it produced are real. 在生成网络中,我们建立了两个神经网络。第一个网络是典型的分类神经网络,称为discriminator重点内容,我们训练这个网络对图像进行识别,以区别真假的图像(真的图片在训练集当中,而假的则不在。另一个网络称之为generator,它将随机的噪声作为输入,将其转化为使用神经网络训练出来产生出来的图像,它的目的是混淆discriminator使其认为它生成的图像是真的。
老潘
2018/06/21
2.5K0
利用pytorch实现GAN(生成对抗网络)-MNIST图像-cs231n-assignment3
基于Gan的cifar10数据生成器
上一篇介绍了关于mnist手写数字,基于GAN的生成模型,这一次我们来看看cifar10数据集的生成器,当然也是基于GAN的
Tom2Code
2023/02/14
1.2K0
基于Gan的cifar10数据生成器
TensorFlow 2 和 Keras 高级深度学习:1~5
在第一章中,我们将介绍在本书中将使用的三个深度学习人工神经网络。 这些网络是 MLP,CNN 和 RNN(在第 2 节中定义和描述),它们是本书涵盖的所选高级深度学习主题的构建块,例如自回归网络(自编码器,GAN 和 VAE),深度强化学习 ,对象检测和分割以及使用互信息的无监督学习。
ApacheCN_飞龙
2023/04/26
2.2K0
TensorFlow从1到2(十二)生成对抗网络GAN和图片自动生成
上一篇中介绍的VAE自动编码器具备了一定程度的创造特征,能够“无中生有”的由一组随机数向量生成手写字符的图片。 这个“创造能力”我们在模型中分为编码器和解码器两个部分。其能力来源实际上是大量样本经过学习编码后,在数字层面对编码结果进行微调,再解码生成图片的过程。所生成的图片,是对原样本图的某种变形模仿。
俺踏月色而来
2019/05/15
1.3K0
TensorFlow从1到2(十二)生成对抗网络GAN和图片自动生成
如何快速理解GAN?这里有一篇最直观的解读
本文授权转自雷克世界(ID:raicworld) 编译 | 嗯~阿童木呀、KABUDA 让我们假设这样一种情景:你的邻居正在举办一场非常酷的聚会,你非常想去参加。但有要参加聚会的话,你需要一张特价票,而这个票早就已经卖完了。 而对于这次聚会的组织者来说,为了让聚会能够成功举办,他们雇佣了一个合格的安全机构。主要目标就是不允许任何人破坏这次的聚会。为了做到这一点,他们在会场入口处安置了很多警卫,检查每个人所持门票的真实性。 考虑到你没有任何武术上的天赋,而你又特别想去参加聚会,那么唯一的办法就是用一张非
AI科技大本营
2018/04/26
7630
如何快速理解GAN?这里有一篇最直观的解读
数据集难找?GAN生成你想要的数据!!!
GAN创始人 Ian Goodfellow 在酒吧微醉后与同事讨论学术问题,当时灵光乍现提出了GAN初步的想法,不过当时并没有得到同事的认可,在从酒吧回去后发现女朋友已经睡了,于是自己熬夜写了代码,发现还真有效果,于是经过一番研究后,GAN就诞生了,一篇开山之作。论文《Generative Adversarial Nets》首次提出GAN。
Python研究者
2020/11/09
4.2K0
数据集难找?GAN生成你想要的数据!!!
深度学习 | GAN,什么是生成对抗网络
GAN是由两部分组成的,第一部分是生成,第二部分是对抗。简单来说,就是有一个生成网络G和一个判别网络D,通过训练让两个网络相互竞争,生成网络G接受一个随机噪声z来生成假的数据G(z),对抗网络D通过判别器去判别真伪概率,最后希望生成器G生成的数据能够以假乱真。在最理想的状态下,D(G(z)) = 0.5。
Justlovesmile
2021/12/14
1.4K0
深度学习 | GAN,什么是生成对抗网络
利用tensorflow训练简单的生成对抗网络GAN
对抗网络是14年Goodfellow Ian在论文Generative Adversarial Nets中提出来的。 原理方面,对抗网络可以简单归纳为一个生成器(generator)和一个判断器(discriminator)之间博弈的过程。整个网络训练的过程中,
狼啸风云
2020/09/27
1.3K0
一个快速构造GAN的教程:如何用pytorch构造DCGAN
在本教程中,我们将在PyTorch中构建一个简单的DCGAN,并在手写数据集上对它进行训练。我们将讨论PyTorch DataLoader,以及如何使用它将图像数据提供给PyTorch神经网络进行训练。PyTorch是本教程的重点,所以我假设您熟悉GAN的工作方式。
deephub
2020/08/04
1.6K0
一个快速构造GAN的教程:如何用pytorch构造DCGAN
生成对抗网络(GAN)如何推动AIGC的发展
为了更深入理解生成对抗网络(GAN),我们需要探索其更复杂的变种和技术细节。这些变种通常旨在解决GAN的训练不稳定性、生成质量以及应用范围等问题。以下是一些主要的GAN变种及其特性。
用户11292525
2024/11/21
2260
内容创造:GANs技术在图像与视频生成中的应用
生成对抗网络(Generative Adversarial Networks,简称GANs)是近年来在机器学习领域引起广泛关注的一种新型算法框架。它通过让两个神经网络——生成器和判别器——相互竞争来生成新的、与真实数据相似的数据样本。GANs在图像与视频生成领域的应用前景广阔,本文将探讨GANs技术的基本原理、在内容创造中的应用案例、面临的挑战以及未来的发展方向。
二一年冬末
2024/05/09
4900
生成型对抗性网络入门实战一波流
前几节用代码介绍了生成型对抗性网络的实现,但后来我觉得代码的实现七拐八弯,很多不必要的烦琐会增加读者的理解负担,于是花时间把代码进行强力精简,希望由此能帮助有需要的读者更顺利的入门生成型对抗性网络。
望月从良
2020/03/25
4570
生成型对抗性网络入门实战一波流
深度卷积生成对抗网络(DCGAN)
GAN的基本原理其实非常简单,它包含两个网络,G网络(Generator)和D网络(Discriminator)。G网络的目标是尽量生成真实的图片去欺骗判别网络D,D网络的目标是尽量把G网络生成的图片和真实的图片分别开来。
YoungTimes
2022/04/28
1.4K0
深度卷积生成对抗网络(DCGAN)
Tensorflow2.0实战之GAN
本文主要带领读者了解生成对抗神经网络(GAN),并使用提供的face数据集训练网络
陶陶name
2022/05/13
3630
基于GAN的MNIST手写数字生成器
今天我们就使用Mnist数据集来训练一个GAN model然后单独把GAN中的生成器模型抽取出来
Tom2Code
2023/02/14
6370
基于GAN的MNIST手写数字生成器
GAN笔记——理论与实现
GAN这一概念是由Ian Goodfellow于2014年提出,并迅速成为了非常火热的研究话题,GAN的变种更是有上千种,深度学习先驱之一的Yann LeCun就曾说,"GAN及其变种是数十年来机器学习领域最有趣的idea"。那么什么是GAN呢?GAN的应用有哪些呢?GAN的原理是什么呢?怎样去实现一个GAN呢?本文将一一阐述。具体大纲如下:
努力努力再努力F
2018/09/11
1.1K0
GAN笔记——理论与实现
对抗生成网络学习(七)——SRGAN生成超分辨率影像(tensorflow实现)「建议收藏」
大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说对抗生成网络学习(七)——SRGAN生成超分辨率影像(tensorflow实现)「建议收藏」,希望能够帮助大家进步!!!
Java架构师必看
2022/06/13
7.6K1
对抗生成网络学习(七)——SRGAN生成超分辨率影像(tensorflow实现)「建议收藏」
教你如何使用GAN为口袋妖怪上色
在之前的Demo中,我们使用了条件GAN来生成了手写数字图像。那么除了生成数字图像以外我们还能用神经网络来干些什么呢?
矩池云
2020/03/13
8400
教你如何使用GAN为口袋妖怪上色
基于CelebA数据集的GAN模型-2
前两篇我们介绍了celeB数据集 CelebA Datasets——Readme 基于CelebA数据集的GAN模型 直接上代码咯 导入依赖: # example of a gan for generating faces from numpy import load from numpy import zeros from numpy import ones from numpy.random import randn from numpy.random import randint from ker
Tom2Code
2023/02/14
7020
基于CelebA数据集的GAN模型-2
【干货】基于GAN实现图像锐化应用(附代码)
【导读】生成对抗网络(GAN)是Ian Goodfellow在2014年在其论文Generative Adversarial Nets中提出来的,可以说是当前最炙手可热的技术了。本文基于Keras框架构建GAN网络,解决图像锐化问题。首先介绍了GAN的基本网络架构,然后从数据、模型、训练等几个方面介绍GAN在图像锐化的应用。本文是一篇很好的GAN学习实例,并且给出了许多不错的GAN学习链接,对GAN感兴趣的读者不容错过! 作者 | Raphaël Meudec 编译 | 专知 参与 | Li Yongxi,
WZEARW
2018/06/05
2.3K0
推荐阅读
相关推荐
利用pytorch实现GAN(生成对抗网络)-MNIST图像-cs231n-assignment3
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档