前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >论文:生成模型采样-类比学习应用 代码

论文:生成模型采样-类比学习应用 代码

作者头像
用户1908973
发布2018-07-25 10:34:32
6500
发布2018-07-25 10:34:32
举报
文章被收录于专栏:CreateAMindCreateAMind

之前发的这篇文章(之前内容在文章底部)介绍了生成模型的高效采样及隐变量空间特征特点,最近的How to Train a GAN? Tips and tricks to make GANs work GANhack又提及了GAN采样使用此论文的采样方法更高效,而且官方的代码开源(代码比较复杂,而且我跑了出错)https://github.com/dribnet/plat 错误已发issue。但代码还是有参考价值。

官方提供的代码效果:

Quickstart

Install this library, code supporting a model type, and go.

代码语言:javascript
复制
$ pip install plat
$ pip install git+https://github.com/dribnet/discgen.git \
  -r https://raw.githubusercontent.com/dribnet/discgen/master/requirements.txt
$ plat sample --model celeba_64.discgen
Model celeba_64.discgen will be downloaded. Continue? [Y/n] y
Saving image file plat_20161006_celeba_64_discgen_01.png

Sampling Examples

By default, plat does a random sampling. The output file will be automatically generated, or can be given explicitly. To make the results repeatable, you can also specify a random seed.

代码语言:javascript
复制
$ plat sample \
  --model celeba_64.discgen \
  --seed 1 \
  --outfile examples/random_sample.jpg

The number of rows and columns can be specified. Interpolation is done by specifying the spacing between samples.

代码语言:javascript
复制
$ plat sample \
  --model celeba_64.discgen \
  --seed 1 \
  --rows 1 --cols 7 \
  --spacing 6 \
  --outfile examples/random_interpolation.jpg

Interpolation can be done across multiple points in two dimensions to create a mine grid (details in paper).

代码语言:javascript
复制
$ plat sample \
  --model celeba_64.discgen \
  --seed 1 \
  --rows 3 --cols 7 \
  --spacing 3 \
  --outfile examples/random_mine_grid.jpg

There are many more options to explore. When experimenting, it can be useful to use a templated output filename.

代码语言:javascript
复制
$ plat sample \
  --model celeba_64.discgen \
  --seed 17 \
  --tight \
  --rows 3 --cols 7 \
  --spacing 2 \
  --outfile examples/%DATE%_experiment_s%SEED%_%SEQ%.jpg

Model types

plat comes with access to a growing list of models and model types in its model zoo. Each model type will have separate dependencies.

It's also possible to run plat on new types of models by providing a simple plat interface. There are a few examplesand a template to get started. Here's an example of how to use plat sample with a manually specified model interface to generate a (random) mine grid from an iGAN model:

代码语言:javascript
复制
PYTHONPATH=. plat sample \
  --model-interface plat.interface.igan.IganModel \
  --model-file models/shoes_64.dcgan_theano \
  --uniform \
  --rows 4 --cols 10 \
  --tight --spacing 3 \
  --image-size 64 \
  --seed 1

代码比较复杂:参数就非常多:

...........................

调用:

plat.sampling.grid_from_latents(z, dmodel, args.rows, args.cols, anchor_images, args.tight, args.shoulders, cur_save_path, cur_basename, args, args.batch_size)

def grid_from_latents(z, dmodel, rows, cols, anchor_images, tight, shoulders, save_path, basename="basename", args=None, batch_size=24):

........

decoded = dmodel.sample_at(cur_z)

采样z的遍历方式计算如下:

具体采样计算:

decoded = dmodel.sample_at(cur_z) 采样操作还依赖另外的模型生成程序:

ref https://github.com/dribnet/discgen 模型也是这个代码及论文介绍生成的。

通过theano实现。

整个代码稍微复杂一些,需要的可以参考一下。

计算机能否学会类比?我的答案是能,不但能,而且有人已经展示了相关效果:

Sampling Generative Networks: Notes on a Few Effective Techniques

今天看的这篇论文题目如上,生成模型能学习到相关语义特征,且这种语义特征可以进行计算和推理。

下面进行论文解读:

生成模型是一种流行的方法来无监督机器学习。生成的神经网络模型进行培训,以产生类似的训练集的数据样本。由于模型参数的数量是显着小于训练数据,模型被迫发现有效的数据表示。这些模型是从一组在高维空间中的潜变量的采样,这里被称为一个潜在的空间。潜在的空间可以被采样,以产生可观察到的数据值。学习的潜表示经常也允许与向量空间算术的语义运算。

这些潜在的空间通常是高度结构化和可使生成的图像的潜在空间简单向量距离算法复杂的操作,比如:

论文首先将传统线性采样修改为球形弧线采样,提高了中间图片的连续性:如下图:

第二:论文介绍了类比学习推理的相关方法和生成模型在此中的应用

生成模型学习到了更加结构化的内部表示,可以方便的应用到类比推理中,比如下图:

the encoder and decoder of the model. The bottom right image shows the result of applying the analogy operation (B + C) – A. All other images are interpolations using the slerp operator. (model: VAE from Lamb 16 on CelebA)

第三论文介绍了不同图片直接的过度状态浏览,如下面大图直接的过度图片生成查看

第四论文提出了属性向量,比如笑脸向量,可以加到普通脸面图片上。

第五论文进行了标签隐含关联的分析,指出生成模型学到的相关向量的关联性反应了事物之间的规律,比如女人普遍比男人爱笑,模糊的图片普遍较暗,人们发笑时普遍会张嘴露牙

通过属性分解,即可分析单独人脸属性的潜在关联。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-12-17,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Quickstart
  • Sampling Examples
  • Model types
  • 计算机能否学会类比?我的答案是能,不但能,而且有人已经展示了相关效果:
  • Sampling Generative Networks: Notes on a Few Effective Techniques
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档