TensorFlow实现GAN
这里的生成模型和判别模型均为多层感知机(当然也可以换为CNN或LSTM),多层感知机的层数为四层,中间有两个隐藏层。使用的数据集为mnist数据集,训练GAN之后得到的模型能达到的效果是:在生成模型中输入一个随机高斯噪声,生成模型可以输出一张和mnist数据集类似的图片。参考论文:《Generative Adversarial Nets》。 #coding=utf-8 import pickle import tensorflow as tf import numpy as np import matplotlib.gridspec as gridspec import os import shutil from scipy.misc import imsave # 定义一个mnist数据集的类 class mnistReader(): def __init__(self,mnistPath,onehot=True): self.mnistPath=mnistPath self.onehot=onehot self.batch_index=0 print ('read:',self.mnistPath) fo = open(self.mnistPath, 'rb') self.train_set,self.valid_set,self.test_set = pickle.load