GAN就像是假币伪造者（Generative）和警察（Discriminator）之间的故事。最开始时假币团伙的假钱将被警方发现，警方发现假币后，将向广大人民群众张贴假币实例和辨伪方法。这相当于警察向伪造者提供了反馈，告诉了为什幺钱是假的。 假币团伙试图根据收到的反馈制作新的假钱。警方表示，这些钱仍然是假的，并向人民群众提供了一套新的辨伪方法。 假币团伙试图根据最新反馈制作新的假钱。这个循环无限期地持续下去，直到警察被假币愚弄，因为它现在看起来真的很真实。

## 鉴别器

self.D = Sequential()

depth = 64

dropout = 0.4

# In: 28 x 28 x 1, depth = 1

# Out: 14 x 14 x 1, depth=64

input_shape = (self.img_rows, self.img_cols, self.channel)

activation=LeakyReLU(alpha=0.2)))

activation=LeakyReLU(alpha=0.2)))

activation=LeakyReLU(alpha=0.2)))

# Out: 1-dim probability

self.D.summary()

## 生成器

self.G = Sequential()

dropout = 0.4

depth = 64+64+64+64

dim = 7

# In: 100

# Out: dim x dim x depth

# In: dim x dim x depth

# Out: 2*dim x 2*dim x depth/2

# Out: 28 x 28 x 1 grayscale image [0.0,1.0] per pix

self.G.summary()

return self.G

## 鉴别器模型

optimizer = RMSprop(lr=0.0008, clipvalue=1.0, decay=6e-8)

self.DM = Sequential()

self.DM.compile(loss=’binary_crossentropy’, optimizer=optimizer,\

metrics=[‘accuracy’])

## 反模型

optimizer = RMSprop(lr=0.0004, clipvalue=1.0, decay=3e-8)

self.AM = Sequential()

self.AM.compile(loss=’binary_crossentropy’, optimizer=optimizer,\

metrics=[‘accuracy’])

## 训练

images_train = self.x_train[np.random.randint(0,

self.x_train.shape[0], size=batch_size), :, :, :]

noise = np.random.uniform(-1.0, 1.0, size=[batch_size, 100])

images_fake = self.generator.predict(noise)

x = np.concatenate((images_train, images_fake))

y = np.ones([2*batch_size, 1])

y[batch_size:, :] = 0

d_loss = self.discriminator.train_on_batch(x, y)

y = np.ones([batch_size, 1])

noise = np.random.uniform(-1.0, 1.0, size=[batch_size, 100])

## 样本输出

https://towardsdatascience.com/gan-by-example-using-keras-on-tensorflow-backend-1a6d515a60d0