首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Oceanus 实践-消费 CMQ 主题模型数据源
Oceanus Flink CMQ connector 支持队列模型的数据源表和目的表,暂时不支持主题模型数据源表和目的表。CMQ 主题订阅可以实时同步主题模型数据到队列模型,借助这种机制,我们可以在 Oceanus 实现 CMQ 主题模型数据源表的读取。
Raigor
2021/08/06
1.1K0
Oceanus 实践-消费 CMQ 主题模型数据源
CKafka系列学习文章 - 对比RabbitMQ、RocketMQ、TDMQ-CMQ、kafka和Ckafka(二)
导语:上一章我们聊到了:什么是消息队列,为什么要用消息队列,有那些消息队列?下来我们聊聊什么样的消息队列适合我们公司。
发哥说消息队列
2019/08/22
5.3K0
Flink 实践教程:入门(2):写入 Elasticsearch
作者:腾讯云流计算 Oceanus 团队 流计算 Oceanus 简介 流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。 本文将为您详细介绍如何使用 datagen 连接器生成随机数据,经过流计算 Oceanus,最终将计算数据存入 Elasticsearch 。 前置准备 创建
腾讯云大数据
2021/11/01
6660
消息队列 CMQ 七大功能实践案例
本文先简单介绍 CMQ 底层的架构实现,然后着重结合CMQ的功能特点来介绍 CMQ 的实践案例,让大家快速理解和上手 CMQ 的开发。
serena
2018/01/15
4.3K0
消息队列 CMQ 七大功能实践案例
Flink 实践教程:进阶11-SQL 关联:Regular Join
流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。
吴云涛
2022/03/28
1.1K5
Flink 实践教程:进阶11-SQL 关联:Regular Join
Flink 实践教程-进阶(2):复杂格式数据抽取
作者:腾讯云流计算 Oceanus 团队 流计算 Oceanus 简介 流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。 本文将为您详细介绍如何实时获取 CKafka 中的 JSON 格式数据,经过数据抽取、平铺转换后存入 MySQL 中。 前置准备 创建流计算 Oceanus
腾讯云大数据
2021/12/06
8740
Flink 实践教程-入门(4):读取 MySQL 数据写入到 ES
作者:腾讯云流计算 Oceanus 团队 流计算 Oceanus 简介 流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。 本文将为您详细介绍如何使用 MySQL 接入数据,经过流计算 Oceanus 对数据进行处理分析(示例中采用小写转换函数对name字段进行了小写转换),最终将处
腾讯云大数据
2021/11/09
1.5K0
Oceanus实践-从0到1开发MySQL-cdc到ES SQL作业
实时即未来,最近在腾讯云Oceanus进行实时计算服务,以下为mysql到flink到ES实践。分享给大家~
吴云涛
2021/08/04
1K0
Oceanus实践-从0到1开发MySQL-cdc到ES SQL作业
Oceanus实践-从0到1开发PG SQL作业
在Oceanus控制台的【集群管理】->【新建集群】页面创建集群,选择地域、可用区、VPC、日志、存储,设置初始密码等。
吴云涛
2021/07/21
8870
Oceanus实践-从0到1开发PG SQL作业
Oceanus 实践-从0到1开发ClickHouse SQL作业
在 Oceanus 控制台的【集群管理】->【新建集群】页面创建集群,选择地域、可用区、VPC、日志、存储,设置初始密码等。
吴云涛
2021/08/09
9110
Oceanus 实践-从0到1开发ClickHouse SQL作业
Flink 实践教程:入门4-读取 MySQL 数据写入 ES
流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。
吴云涛
2021/11/06
1.6K1
Flink 实践教程:入门4-读取 MySQL 数据写入 ES
如何借助 Layer 实现云函数快速打包轻松部署
由于云函数在创建或更新时,需要将函数的业务代码,和依赖库一同打包上传,因此在本地开发时,也经常是将依赖库和业务代码放置在一个文件夹下。
腾讯云serverless团队
2020/05/20
2.3K0
基于流计算 Oceanus 和 Elasticsearch 构建日志分析系统
实时即未来,最近在腾讯云流计算 Oceanus(Flink)进行实时计算服务,以下为MySQL 到 Flink 进行处理分析,再存储到ES的实践。分享给大家~
吴云涛
2021/08/09
1.1K0
基于流计算 Oceanus 和 Elasticsearch 构建日志分析系统
Flink 实践教程:入门3-读取 MySQL 数据
流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。
吴云涛
2021/11/03
2.1K0
Flink 实践教程:入门3-读取 MySQL 数据
Flink 最佳实践:TDSQL Connector 的使用(上)
作者:姚琦,腾讯 CSIG 工程师 本文介绍了如何在 Oceanus 平台使用 tdsql-subscribe-connector [1] ,从 TDSQL-MySQL 订阅任务 [2] 创建,到 Oceanus 作业创建、最终数据验证,实现全流程的操作指导。需要注意的是,本文默认已经创建 TDSQL-MySQL 实例和 Oceanus 集群,并且二者在同一 VPC 下或者不同 VPC 下但网络已经打通。 上述流程图简要说明了使用 tdsql-subscribe-connector 时,整个数据流向情况。
腾讯云大数据
2022/04/22
1.3K0
Flink 最佳实践:TDSQL Connector 的使用(上)
最佳实践:MySQL CDC 同步数据到 ES
作者:于乐,腾讯 CSIG 工程师 一、 方案描述 1.1 概述 在线教育是一种利用大数据、人工智能等新型互联网技术与传统教育行业相结合的新型教育方式。发展在线教育可以更好的构建网络化、数字化、个性化、终生化的教育体系,有利于构建“人人皆学、处处能学、实时可学”的学习型社会。 本文针对某知名在线教育平台在腾讯云流计算 Oceanus 的业务案例,介绍了其中可能存在的一些性能问题,并针对这种问题进行了参数调优相关的介绍。 1.2 方案架构 某知名在线教育平台在流计算 Oceanus 上主要有两个业务应用场景
腾讯云大数据
2022/06/24
4.1K0
最佳实践:MySQL CDC 同步数据到 ES
Oceanus 实践-从0到1接入 CKafka SQL 作业
流计算 Oceanus 是位于云端的流式数据汇聚、计算服务。只需几分钟,您就可以轻松构建网站点击流分析、电商精准推荐、物联网 IoT 等应用。流计算基于 Apache Flink 构建,提供全托管的云上服务,您无须关注基础设施的运维,并能便捷对接云上数据源,获得完善的配套支持。
于乐
2021/08/25
9540
Flink 实践教程:入门(3):读取 MySQL 数据
作者:腾讯云流计算 Oceanus 团队 流计算 Oceanus 简介 流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。 本文将为您详细介绍如何取 MySQL 数据,经过流计算 Oceanus 实时计算引擎分析,输出数据到日志(Logger Sink)当中。 前置准备 创建 流计算
腾讯云大数据
2021/11/01
1.3K0
Flink 实践教程:入门7-消费 Kafka 数据写入 PG
流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。
吴云涛
2021/11/12
1.7K0
Flink 实践教程:入门7-消费 Kafka 数据写入 PG
Flink 实践教程:入门2-写入 Elasticsearch
流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发、无缝连接、亚秒延时、低廉成本、安全稳定等特点的企业级实时大数据分析平台。流计算 Oceanus 以实现企业数据价值最大化为目标,加速企业实时化数字化的建设进程。
吴云涛
2021/11/02
1.2K0
Flink 实践教程:入门2-写入 Elasticsearch
推荐阅读
相关推荐
Oceanus 实践-消费 CMQ 主题模型数据源
更多 >
交个朋友
加入腾讯云官网粉丝站
蹲全网底价单品 享第一手活动信息
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档