DCGAN简介
DCGAN在GAN的基础上优化了网络结构,加入了 conv
,batch_norm
等层,使得网络更容易训练,网络结构如下:
注意:本图只是示例,与下面实际网络参数不对应。
Tensorflow实现DCGAN
1 | from __future__ import division, print_function, absolute_import |
导入数据集
1 | # Import MNIST data |
Extracting ./data/train-images-idx3-ubyte.gz
Extracting ./data/train-labels-idx1-ubyte.gz
Extracting ./data/t10k-images-idx3-ubyte.gz
Extracting ./data/t10k-labels-idx1-ubyte.gz
设置参数
1 | # 训练参数 |
构建DCGAN网络
1 | # 构建网络 |
训练
1 | # Start Training |
Step 1: Generator Loss: 4.064141, Discriminator Loss: 1.679586
Step 500: Generator Loss: 1.472707, Discriminator Loss: 0.974612
Step 1000: Generator Loss: 1.918907, Discriminator Loss: 0.964812
Step 1500: Generator Loss: 2.567637, Discriminator Loss: 0.717904
Step 2000: Generator Loss: 2.398796, Discriminator Loss: 0.512406
Step 2500: Generator Loss: 3.057401, Discriminator Loss: 1.235215
Step 3000: Generator Loss: 2.620444, Discriminator Loss: 0.539795
Step 3500: Generator Loss: 3.193395, Discriminator Loss: 0.265896
Step 4000: Generator Loss: 5.071162, Discriminator Loss: 0.409445
Step 4500: Generator Loss: 5.213869, Discriminator Loss: 0.203033
Step 5000: Generator Loss: 6.087250, Discriminator Loss: 0.350634
Step 5500: Generator Loss: 5.467363, Discriminator Loss: 0.424895
Step 6000: Generator Loss: 4.910432, Discriminator Loss: 0.196554
Step 6500: Generator Loss: 3.230242, Discriminator Loss: 0.268745
Step 7000: Generator Loss: 4.777361, Discriminator Loss: 0.676658
Step 7500: Generator Loss: 4.165446, Discriminator Loss: 0.150221
Step 8000: Generator Loss: 5.681596, Discriminator Loss: 0.108955
Step 8500: Generator Loss: 6.023059, Discriminator Loss: 0.114312
Step 9000: Generator Loss: 4.660669, Discriminator Loss: 0.182506
Step 9500: Generator Loss: 4.492438, Discriminator Loss: 0.411817
Step 10000: Generator Loss: 5.906080, Discriminator Loss: 0.088082
测试
1 | # Testing |