face-generator

Generate human faces with neural networks
授权协议 MIT License
开发语言 Python
所属分类 神经网络/人工智能、 机器学习/深度学习
软件类型 开源软件
地区 不详
投 递 者 姚星宇
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

About

This is a script to generate new images of human faces using the technique of generative adversarial networks (GAN), as described in the paper by Ian J. Goodfellow.GANs train two networks at the same time: A Generator (G) that draws/creates new images and a Discriminator (D) that distinguishes between real and fake images. G learns to trick D into thinking that his images are real (i.e. learns to produce good looking images). D learns to prevent getting tricked (i.e. learns what real images look like).Ideally you end up with a G that produces beautiful images that look like real ones. On human faces that works reasonably well, probably because they contain a lot of structure (autoencoders work well on them too).

The code in this repository is a modified version of facebook's eyescream project.

Example images

The following images were generated by a model trained with th train.lua --D_L1=0 --D_L2=0 --D_iterations=2.

1024 randomly generated 32x32 face images.

64 generated 32x32 images, rated by D as the best images among 1024 randomly generated ones.

16 generated images (each pair left) and their nearest neighbours from the training set (each pair right). Distance was measured by 2-Norm (torch.dist()). The 16 selected images were the "best" ones among 1024 images according to the rating by D, hence some similarity with the training set is expected.

Requirements

To generate the dataset:

  • Labeled Faces in the Wild (original dataset without funneling)
  • Python 2.7 (only tested with that version)
    • Scipy
    • Numpy
    • scikit-image

To run the GAN part:

  • Torch with the following libraries (most of them are probably already installed by default):
    • pl (luarocks install pl)
    • nn (luarocks install nn)
    • paths (luarocks install paths)
    • image (luarocks install image)
    • optim (luarocks install optim)
    • cutorch (luarocks install cutorch)
    • cunn (luarocks install cunn)
    • cudnn (luarocks install cudnn)
    • dpnn (luarocks install dpnn)
  • display
  • Nvidia GPU with >= 4 GB memory
  • cudnn3

Usage

Building the dataset:

  • Download Labeled Faces in the Wild and extract it somewhere
  • In dataset/ run python generate_dataset.py --path="/foo/bar/lfw", where /foo/bar/lfw is the path to your LFW dataset

To train a new model, follow these steps:

  • Start display with ~/.display/run.js &
  • Open http://localhost:8000 to see the training progress
  • Train a 32x32 color generator with th train.lua (add --grayscale for grayscale images)
  • Sample images with th sample.lua. Add --neighbours to sample nearest neighbours (takes long). Add e.g. --runs=10 to generate 10 times the amount of images.

You might have to work with the command line parameters --D_iterations and --G_iterations to get decent performance.Sometimes you also might have to change --D_L2 (D's L2 norm) or --G_L2 (G's L2 norm). (Similar parameters are available for L1.)

Architecture

G's architecture is mostly copied from the blog post by Anders Boesen Lindbo Larsen and Søren Kaae Sønderby.It is basically a full laplacian pyramid in one network.The network starts with a small linear layer, which roughly generates 8x8 images.That is followed by upsampling layers, which increase the image size to 16x16 and then 32x32 pixels.

local model = nn.Sequential()
model:add(nn.Linear(noiseDim, 128*8*8))
model:add(nn.View(128, 8, 8))
model:add(nn.PReLU(nil, nil, true))

model:add(nn.SpatialUpSamplingNearest(2))
model:add(cudnn.SpatialConvolution(128, 256, 5, 5, 1, 1, (5-1)/2, (5-1)/2))
model:add(nn.SpatialBatchNormalization(256))
model:add(nn.PReLU(nil, nil, true))

model:add(nn.SpatialUpSamplingNearest(2))
model:add(cudnn.SpatialConvolution(256, 128, 5, 5, 1, 1, (5-1)/2, (5-1)/2))
model:add(nn.SpatialBatchNormalization(128))
model:add(nn.PReLU(nil, nil, true))

model:add(cudnn.SpatialConvolution(128, dimensions[1], 3, 3, 1, 1, (3-1)/2, (3-1)/2))
model:add(nn.Sigmoid())

where noiseDim is 100 and dimensions[1] is 3 (color mode) or 1 (grayscale mode).

D is a standard convolutional neural net.

local conv = nn.Sequential()
conv:add(nn.SpatialConvolution(dimensions[1], 64, 3, 3, 1, 1, (3-1)/2))
conv:add(nn.PReLU(nil, nil, true))
conv:add(nn.SpatialDropout(0.2))
conv:add(nn.SpatialAveragePooling(2, 2, 2, 2))

conv:add(nn.SpatialConvolution(64, 128, 3, 3, 1, 1, (3-1)/2))
conv:add(nn.PReLU(nil, nil, true))
conv:add(nn.SpatialDropout(0.2))
conv:add(nn.SpatialAveragePooling(2, 2, 2, 2))

conv:add(nn.SpatialConvolution(128, 256, 3, 3, 1, 1, (3-1)/2))
conv:add(nn.PReLU(nil, nil, true))
conv:add(nn.SpatialDropout(0.2))
conv:add(nn.SpatialAveragePooling(2, 2, 2, 2))

conv:add(nn.SpatialConvolution(256, 512, 3, 3, 1, 1, (3-1)/2))
conv:add(nn.PReLU(nil, nil, true))
conv:add(nn.SpatialDropout(0.2))
conv:add(nn.SpatialAveragePooling(2, 2, 2, 2))

conv:add(nn.View(512 * 0.25 * 0.25 * 0.25 * 0.25 * dimensions[2] * dimensions[3]))
conv:add(nn.Linear(512 * 0.25 * 0.25 * 0.25 * 0.25 * dimensions[2] * dimensions[3], 512))
conv:add(nn.PReLU(nil, nil, true))
conv:add(nn.Dropout())
conv:add(nn.Linear(512, 512))
conv:add(nn.PReLU(nil, nil, true))
conv:add(nn.Dropout())
conv:add(nn.Linear(512, 1))
conv:add(nn.Sigmoid())

where dimensions[1] is 3 (color) or 1 (grayscale), and dimensions[2] is the height of 32 (same as dimensions[3]).

Training is done with Adam (by default).

Command Line Parameters

The train.lua script has the following parameters:

  • --batchSize (default 16): The size of each batch, which will be split in two parts for G and D, making each one of them half-size. So a setting of 4 will create a batch of size of 2 for D (one image fake, one real) and another batch of size 2 for G. Because of that, the minimum size is 4 (and batches must be even sized).
  • --save (default "logs"): Directory to save the weights to.
  • --saveFreq (default 30): Save weights every N epochs.
  • --network (default ""): Name of a weights file in the save directory to load.
  • --noplot: Whether to NOT plot during training.
  • --N_epoch (default 1000): How many examples to use during each epoch (-1 means "use the whole dataset").
  • --G_SGD_lr (default 0.02): Learning rate for G's SGD, if SGD is used as the optimizer. (Note: There is no decay. You should use Adam or Adagrad.)
  • --G_SGD_momentum (default 0): Momentum for G's SGD.
  • --D_SGD_lr (default 0.02): Learning rate for D's SGD, if SGD is used as the optimizer. (Note: There is no decay. You should use Adam or Adagrad.)
  • --D_SGD_momentum (default 0): Momentum for D's SGD.
  • --G_adam_lr (default -1): Adam learning rate for G (-1 is automatic).
  • --D_adam_lr (default -1): Adam learning rate for D (-1 is automatic).
  • --G_L1 (default 0): L1 penalty on the weights of G.
  • --G_L2 (default 0): L2 penalty on the weights of G.
  • --D_L1 (default 0): L1 penalty on the weights of D.
  • --D_L2 (default 1e-4): L2 penalty on the weights of D.
  • --D_iterations (default 1): How often to optimize D per batch (e.g. 2 for D and 1 for G means that D will be trained twice as much).
  • --G_iterations (default 1): How often to optimize G per batch.
  • --D_maxAcc (default 1.01): Stop training of D roughly around that accuracy level until G has catched up. (Sounds good in theory, doesn't produce good results in practice.)
  • --D_clamp (default 1): To which value to clamp D's gradients (e.g. 5 means -5 to +5, 0 is off).
  • --G_clamp (default 5): To which value to clamp G's gradients (e.g. 5 means -5 to +5, 0 is off).
  • --D_optmethod (default "adam"): Optimizer to use for D, either "sgd" or "adam" or "adagrad".
  • --G_optmethod (default "adam"): Optimizer to use for D, either "sgd" or "adam" or "adagrad".
  • --threads (default 8): Number of threads.
  • --gpu (default 0): Index of the GPU to train on (0-4 or -1 for cpu). Nothing is optimized for CPU.
  • --noiseDim (default 100): Dimensionality of noise vector that will be fed into G.
  • --window (default 3): ID of the first plotting window (in display), will also use about 3 window-ids beyond that.
  • --scale (default 32): Scale of the images to train on (height, width). Loaded images will be converted to that size. Only optimized for 32.
  • --seed (default 1): Seed to use for the RNG.
  • --weightsVisFreq (default 0): How often to update the windows showing the activity of the network (only if >0; implies starting with qlua instead of th if set to >0).
  • --grayscale: Whether to activate grayscale mode on the images, i.e. training will happen on grayscale images.
  • --denoise: If added as parameter, the script will try to load a denoising autoencoder from logs/denoiser_CxHxW.net, where C is the number of image channels (1 or 3), H is the height of the images (see --scale) and W is the width. A denoiser can be trained using train_denoiser.lua.

Other

  • Training was done with Adam.
  • Batch size was 32.
  • The file train_c2f.lua is used to train a coarse to fine network of the laplacian pyramid. (Deprecated)
  • """ 人脸生成项目 本项目中:使用生成式对抗网络(Generative Adversarial Nets)来生成新的人脸图像。 ### 获取数据 使用以下数据集: - MNIST - CelebA 由于 CelebA 数据集非常大。所以先在 MNIST 数据集上测试 GANs模型,然后再将其应用到CelebA数据集上。 """ import os import helper from glob

  • Retinaface提出的动机 Insight Face在2019年提出的最新人脸检测模型,原模型使用了deformable convolution和dense regression loss, 在 WiderFace 数据集上达到SOTA。 截止2019年8月,原始模型尚未全部开源,目前开源的简化版是基于传统物体检测网络RetinaNet的改进版,添加了SSH网络的检测模块,提升检测精度。 作者

  • 参考资料:https://www.w3cplus.com/content/css3-font-face @font-face是CSS3中的一个模块,主要是把自定义的Web字体嵌入到网页中。 @font-face的语法规则 // 以iconfont为例 @font-face {font-family: "iconfont"; src: url('../fonts/iconfont.eot?t

  • 抱着试试水的想法参加了robocup校赛,想借此试试人工智能识别。比赛给了诸多实现方案,我选择了其中需要自己搭网络的方案。不料配置环境一路坎坷,特此记录 比赛分为人脸识别和物体识别。人脸识别是face_recognition,物体识别是yolov5。出于电脑洁癖和项目本身要求,我租了个ubuntu服务器,在上面折腾,随心所欲下环境。 服务器配置:  apt-get update apt insta

 相关资料
  • Represents a section bounded by a specific amount of half-edges. The current implmentation assumes that a face always consist of three edges. Constructor Face() Creates a new instance of Face. Propert

  • 1.接口描述 该 API 用于识别人脸各项属性的值。 图片要求 格式为 JPG(JPEG),BMP,PNG,GIF,TIFF 宽和高大于 8px,小于等于4000px 小于等于 5 MB 支持自动识别人脸方向 请求方式 POST 请求 URL https://cloudapi.linkface.cn/face/face_attributes_detect 2.请求参数 字段 类型 必需 描述 a

  • 一款超轻量级通用人脸检测模型(模型文件大小仅 1MB,320x240 输入下计算量仅 90MFlops),适用于边缘计算设备、移动端设备以及 PC。 Ultra-Light-Fast-Generic-Face-Detector-1MB 超轻量级通用人脸检测模型 该模型设计是针对边缘计算设备或低算力设备(如用 ARM 推理)设计的一款实时超轻量级通用人脸检测模型,旨在能在低算力设备中如用ARM进行实

  • Face Detection是一个很强悍的jQuery插件,它所实现的是图像面部识别功能。它可以检测待测图片中的面部信息,匹配到面部信息后将会返回图片中面部的座标位置等信息,你可以用它来实现一些图片分析的功能。

  • Face Recognition 是一个基于 Python 的人脸识别库,它还提供了一个命令行工具,让你通过命令行对任意文件夹中的图像进行人脸识别操作。 该库使用 dlib 顶尖的深度学习人脸识别技术构建,在户外脸部检测数据库基准(Labeled Faces in the Wild benchmark)上的准确率高达 99.38%。 具有以下特性: 查找出图片中所有的人脸 查找和操作图片中的脸部特

  • 将设备前置摄像头的拍摄画面显示在视图右下角,类似FaceTime。 [Code4App.com]