官网实例详解4.22(mnist_acgan.py)-keras学习笔记四

基于MINIST数据集训练辅助分类器ACGAN(生成对抗网络)

Keras实例目录

运行生成文件


效果展示

plot_epoch_073_generated(图片文件)

代码注释

# -*- coding: utf-8 -*-
"""
Train an Auxiliary Classifier Generative Adversarial Network (ACGAN) on the
MNIST dataset. See https://arxiv.org/abs/1610.09585 for more details.
基于MINIST数据集训练辅助分类器ACGAN(生成对抗网络)
详情见:https://arxiv.org/abs/1610.09585

You should start to see reasonable images after ~5 epochs, and good images
by ~15 epochs. You should use a GPU, as the convolution-heavy operations are
very slow on the CPU. Prefer the TensorFlow backend if you plan on iterating,
as the compilation time can be a blocker using Theano.
5周期后,开始看到合理的图像,大约15周期后,看到合理的图像。
应该使用GPU,因为卷积运算在CPU上的速度非常慢。如果计划迭代,则首选TensorFlow后端,
因为使用Theano编译时速度慢。

Timings:

Hardware           | Backend | Time / Epoch
-------------------------------------------
 CPU               | TF      | 3 hrs
 Titan X (maxwell) | TF      | 4 min
 Titan X (maxwell) | TH      | 7 min

Consult https://github.com/lukedeo/keras-acgan for more information and
example output
更多信息和示例输出,请参阅https://github.com/lukedeo/keras-acgan
"""
from __future__ import print_function

from collections import defaultdict
try:
    import cPickle as pickle
except ImportError:
    import pickle
from PIL import Image

from six.moves import range

from keras.datasets import mnist
from keras import layers
from keras.layers import Input, Dense, Reshape, Flatten, Embedding, Dropout
from keras.layers import BatchNormalization
from keras.layers.advanced_activations import LeakyReLU
from keras.layers.convolutional import Conv2DTranspose, Conv2D
from keras.models import Sequential, Model
from keras.optimizers import Adam
from keras.utils.generic_utils import Progbar
import numpy as np

np.random.seed(1337)
num_classes = 10


def build_generator(latent_size):
    # we will map a pair of (z, L), where z is a latent vector and L is a
    # label drawn from P_c, to image space (..., 28, 28, 1)
    #映射一对(z, L),其中z是一个隐矢,L是P_c绘制的标签。,到图像空间(…,28, 28, 1)
    cnn = Sequential()

    cnn.add(Dense(3 * 3 * 384, input_dim=latent_size, activation='relu'))
    cnn.add(Reshape((3, 3, 384)))

    # upsample to (7, 7, ...)
    # 上采样到(7, 7,…)
    cnn.add(Conv2DTranspose(192, 5, strides=1, padding='valid',
                            activation='relu',
                            kernel_initializer='glorot_normal'))
    cnn.add(BatchNormalization())

    # upsample to (14, 14, ...)
    # 上采样到(14, 14, ...)
    cnn.add(Conv2DTranspose(96, 5, strides=2, padding='same',
                            activation='relu',
                            kernel_initializer='glorot_normal'))
    cnn.add(BatchNormalization())

    # upsample to (28, 28, ...)
    # 上采样到(28, 28, ...)
    cnn.add(Conv2DTranspose(1, 5, strides=2, padding='same',
                            activation='tanh',
                            kernel_initializer='glorot_normal'))

    # this is the z space commonly referred to in GAN papers
    # GAN文献中常用的Z空间。
    latent = Input(shape=(latent_size, ))

    # this will be our label
    # 标签
    image_class = Input(shape=(1,), dtype='int32')

    cls = Flatten()(Embedding(num_classes, latent_size,
                              embeddings_initializer='glorot_normal')(image_class))

    # hadamard product between z-space and a class conditional embedding
    # z-space与条件嵌入的Hadamard积
    h = layers.multiply([latent, cls])

    fake_image = cnn(h)

    return Model([latent, image_class], fake_image)


def build_discriminator():
    # build a relatively standard conv net, with LeakyReLUs as suggested in
    # the reference paper
    # 根据论文,建立一个相对标准的conv网络(卷积网络)
    cnn = Sequential()

    cnn.add(Conv2D(32, 3, padding='same', strides=2,
                   input_shape=(28, 28, 1)))
    cnn.add(LeakyReLU(0.2))
    cnn.add(Dropout(0.3))

    cnn.add(Conv2D(64, 3, padding='same', strides=1))
    cnn.add(LeakyReLU(0.2))
    cnn.add(Dropout(0.3))

    cnn.add(Conv2D(128, 3, padding='same', strides=2))
    cnn.add(LeakyReLU(0.2))
    cnn.add(Dropout(0.3))

    cnn.add(Conv2D(256, 3, padding='same', strides=1))
    cnn.add(LeakyReLU(0.2))
    cnn.add(Dropout(0.3))

    cnn.add(Flatten())

    image = Input(shape=(28, 28, 1))

    features = cnn(image)

    # first output (name=generation) is whether or not the discriminator
    # thinks the image that is being shown is fake, and the second output
    # (name=auxiliary) is the class that the discriminator thinks the image
    # belongs to.
    # 第一输出(name=generation)是鉴别器是否认为所显示的图像是假的,而第二输出(名称=辅助)是鉴别器认为图像属于的类。
    fake = Dense(1, activation='sigmoid', name='generation')(features)
    aux = Dense(num_classes, activation='softmax', name='auxiliary')(features)

    return Model(image, [fake, aux])

if __name__ == '__main__':

    # batch and latent size taken from the paper
    # 来自论文的批次和尺寸
    epochs = 100
    batch_size = 100
    latent_size = 100

    # Adam parameters suggested in https://arxiv.org/abs/1511.06434
    # Adm参数详见:https://arxiv.org/abs/1511.06434
    adam_lr = 0.0002
    adam_beta_1 = 0.5

    # build the discriminator
    # 创建判别器
    print('Discriminator model:')
    discriminator = build_discriminator()
    discriminator.compile(
        optimizer=Adam(lr=adam_lr, beta_1=adam_beta_1),
        loss=['binary_crossentropy', 'sparse_categorical_crossentropy']
    )
    discriminator.summary()

    # build the generator
    # 创建生成器
    generator = build_generator(latent_size)

    latent = Input(shape=(latent_size, ))
    image_class = Input(shape=(1,), dtype='int32')

    # get a fake image
    # 获取赝品图片
    fake = generator([latent, image_class])

    # we only want to be able to train generation for the combined model
    # 为组合模型训练生成器。
    discriminator.trainable = False
    fake, aux = discriminator(fake)
    combined = Model([latent, image_class], [fake, aux])

    print('Combined model:')
    combined.compile(
        optimizer=Adam(lr=adam_lr, beta_1=adam_beta_1),
        loss=['binary_crossentropy', 'sparse_categorical_crossentropy']
    )
    combined.summary()

    # get our mnist data, and force it to be of shape (..., 28, 28, 1) with
    # range [-1, 1]
    # 获取MNIST数据集,并强制调整它的形状为(…,28, 28, 1)。取值范围[-1, 1]
    (x_train, y_train), (x_test, y_test) = mnist.load_data()
    x_train = (x_train.astype(np.float32) - 127.5) / 127.5 # 图像像素取值范围[0,255],以其1/2作为基准
    x_train = np.expand_dims(x_train, axis=-1)

    x_test = (x_test.astype(np.float32) - 127.5) / 127.5
    x_test = np.expand_dims(x_test, axis=-1)

    num_train, num_test = x_train.shape[0], x_test.shape[0]

    train_history = defaultdict(list)
    test_history = defaultdict(list)

    for epoch in range(1, epochs + 1):
        print('Epoch {}/{}'.format(epoch, epochs))

        num_batches = int(x_train.shape[0] / batch_size)
        progress_bar = Progbar(target=num_batches)

        # we don't want the discriminator to also maximize the classification
        # accuracy of the auxiliary classifier on generated images, so we
        # don't train discriminator to produce class labels for generated
        # images (see https://openreview.net/forum?id=rJXTf9Bxg).
        # 我们不希望鉴别器也最大化辅助分类器在生成图像上的分类精度,所以我们不训练鉴别器来产生生成图像的类标签
        # (详见:https://openreview.net/forum?id=rJXTf9Bxg)
        # To preserve sum of sample weights for the auxiliary classifier,
        # we assign sample weight of 2 to the real images.
        # 为了保持辅助分类器的样本权重之和,分配2个相同的实际图像的样本权重。
        disc_sample_weight = [np.ones(2 * batch_size),
                              np.concatenate((np.ones(batch_size) * 2,
                                              np.zeros(batch_size)))]

        epoch_gen_loss = []
        epoch_disc_loss = []

        for index in range(num_batches):
            # generate a new batch of noise
            # 产生新一批噪声
            noise = np.random.uniform(-1, 1, (batch_size, latent_size))

            # get a batch of real images
            # 获取一批真实图像
            image_batch = x_train[index * batch_size:(index + 1) * batch_size]
            label_batch = y_train[index * batch_size:(index + 1) * batch_size]

            # sample some labels from p_c
            # 从p_c取样标签
            sampled_labels = np.random.randint(0, num_classes, batch_size)

            # generate a batch of fake images, using the generated labels as a
            # conditioner. We reshape the sampled labels to be
            # (batch_size, 1) so that we can feed them into the embedding
            # layer as a length one sequence
            # 生成一批假图像,使用生成的标签作为调节器。我们将采样标签整形为(batch_size, 1),
            # 这样我们就可以把它们作为长度一个序列输入到嵌入层中。
            generated_images = generator.predict(
                [noise, sampled_labels.reshape((-1, 1))], verbose=0)

            x = np.concatenate((image_batch, generated_images))

            # use one-sided soft real/fake labels
            # 使用单面软真/假标签
            # Salimans et al., 2016
            # https://arxiv.org/pdf/1606.03498.pdf (Section 3.4)
            soft_zero, soft_one = 0, 0.95
            y = np.array([soft_one] * batch_size + [soft_zero] * batch_size)
            aux_y = np.concatenate((label_batch, sampled_labels), axis=0)

            # see if the discriminator can figure itself out...
            # 看看鉴别器是否能算出它自己…
            epoch_disc_loss.append(discriminator.train_on_batch(
                x, [y, aux_y], sample_weight=disc_sample_weight))

            # make new noise. we generate 2 * batch size here such that we have
            # the generator optimize over an identical number of images as the
            # discriminator
            # 制造新的噪音。产生 * batch大小在这里,这样我们有生成器优化在相同数量的图像作为鉴别器
            noise = np.random.uniform(-1, 1, (2 * batch_size, latent_size))
            sampled_labels = np.random.randint(0, num_classes, 2 * batch_size)

            # we want to train the generator to trick the discriminator
            # For the generator, we want all the {fake, not-fake} labels to say
            # not-fake
            # 训练生成器来欺骗鉴别器,希望鉴别器对所有的{假,不假}标签都说不是假的。
            trick = np.ones(2 * batch_size) * soft_one

            epoch_gen_loss.append(combined.train_on_batch(
                [noise, sampled_labels.reshape((-1, 1))],
                [trick, sampled_labels]))

            progress_bar.update(index + 1)

        print('Testing for epoch {}:'.format(epoch))

        # evaluate the testing loss here
        # 评估测试损失

        # generate a new batch of noise
        # 产生新一批噪声
        noise = np.random.uniform(-1, 1, (num_test, latent_size))

        # sample some labels from p_c and generate images from them
        # 从p_c中采样一些标签并根据标签生成图像
        sampled_labels = np.random.randint(0, num_classes, num_test)
        generated_images = generator.predict(
            [noise, sampled_labels.reshape((-1, 1))], verbose=False)

        x = np.concatenate((x_test, generated_images))
        y = np.array([1] * num_test + [0] * num_test)
        aux_y = np.concatenate((y_test, sampled_labels), axis=0)

        # see if the discriminator can figure itself out...
        # 看看鉴别器是否能算出…
        discriminator_test_loss = discriminator.evaluate(
            x, [y, aux_y], verbose=False)

        discriminator_train_loss = np.mean(np.array(epoch_disc_loss), axis=0)

        # make new noise
        # 制造新噪音
        noise = np.random.uniform(-1, 1, (2 * num_test, latent_size))
        sampled_labels = np.random.randint(0, num_classes, 2 * num_test)

        trick = np.ones(2 * num_test)

        generator_test_loss = combined.evaluate(
            [noise, sampled_labels.reshape((-1, 1))],
            [trick, sampled_labels], verbose=False)

        generator_train_loss = np.mean(np.array(epoch_gen_loss), axis=0)

        # generate an epoch report on performance
        # 生成有关性能的周期性报告
        train_history['generator'].append(generator_train_loss)
        train_history['discriminator'].append(discriminator_train_loss)

        test_history['generator'].append(generator_test_loss)
        test_history['discriminator'].append(discriminator_test_loss)

        print('{0:<22s} | {1:4s} | {2:15s} | {3:5s}'.format(
            'component', *discriminator.metrics_names))
        print('-' * 65)

        ROW_FMT = '{0:<22s} | {1:<4.2f} | {2:<15.4f} | {3:<5.4f}'
        print(ROW_FMT.format('generator (train)',
                             *train_history['generator'][-1]))
        print(ROW_FMT.format('generator (test)',
                             *test_history['generator'][-1]))
        print(ROW_FMT.format('discriminator (train)',
                             *train_history['discriminator'][-1]))
        print(ROW_FMT.format('discriminator (test)',
                             *test_history['discriminator'][-1]))

        # save weights every epoch
        # 保存每个周期的权重
        generator.save_weights(
            'params_generator_epoch_{0:03d}.hdf5'.format(epoch), True)
        discriminator.save_weights(
            'params_discriminator_epoch_{0:03d}.hdf5'.format(epoch), True)

        # generate some digits to display
        # 生成一些数字显示
        num_rows = 40
        noise = np.tile(np.random.uniform(-1, 1, (num_rows, latent_size)),
                        (num_classes, 1))

        sampled_labels = np.array([
            [i] * num_rows for i in range(num_classes)
        ]).reshape(-1, 1)

        # get a batch to display
        # 获得批量显示
        generated_images = generator.predict(
            [noise, sampled_labels], verbose=0)

        # prepare real images sorted by class label
        # 准备按类标签排序的真实图像
        real_labels = y_train[(epoch - 1) * num_rows * num_classes:
                              epoch * num_rows * num_classes]
        indices = np.argsort(real_labels, axis=0)
        real_images = x_train[(epoch - 1) * num_rows * num_classes:
                              epoch * num_rows * num_classes][indices]

        # display generated images, white separator, real images
        # 显示生成的图像,白色分离器,真实图像
        img = np.concatenate(
            (generated_images,
             np.repeat(np.ones_like(x_train[:1]), num_rows, axis=0),
             real_images))

        # arrange them into a grid
        # 将它们排列成网格
        img = (np.concatenate([r.reshape(-1, 28)
                               for r in np.split(img, 2 * num_classes + 1)
                               ], axis=-1) * 127.5 + 127.5).astype(np.uint8)

        Image.fromarray(img).save(
            'plot_epoch_{0:03d}_generated.png'.format(epoch))

    with open('acgan-history.pkl', 'wb') as f:
        pickle.dump({'train': train_history, 'test': test_history}, f)

代码执行

C:\ProgramData\Anaconda3\python.exe E:/keras-master/examples/mnist_acgan.py
Using TensorFlow backend.
Discriminator model:
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            (None, 28, 28, 1)    0
__________________________________________________________________________________________________
sequential_1 (Sequential)       (None, 12544)        387840      input_1[0][0]
__________________________________________________________________________________________________
generation (Dense)              (None, 1)            12545       sequential_1[1][0]
__________________________________________________________________________________________________
auxiliary (Dense)               (None, 10)           125450      sequential_1[1][0]
==================================================================================================
Total params: 525,835
Trainable params: 525,835
Non-trainable params: 0
__________________________________________________________________________________________________

Combined model:
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_4 (InputLayer)            (None, 100)          0
__________________________________________________________________________________________________
input_5 (InputLayer)            (None, 1)            0
__________________________________________________________________________________________________
model_2 (Model)                 (None, 28, 28, 1)    2657897     input_4[0][0]
                                                                 input_5[0][0]
__________________________________________________________________________________________________
model_1 (Model)                 [(None, 1), (None, 1 525835      model_2[1][0]
==================================================================================================
Total params: 3,183,732
Trainable params: 2,657,321
Non-trainable params: 526,411
__________________________________________________________________________________________________
Epoch 1/100


  1/600 [..............................] - ETA: 45:16
  2/600 [..............................] - ETA: 27:37
  3/600 [..............................] - ETA: 19:05
  4/600 [..............................] - ETA: 14:50
  5/600 [..............................] - ETA: 12:17
  6/600 [..............................] - ETA: 10:33
  7/600 [..............................] - ETA: 9:20
  8/600 [..............................] - ETA: 8:25
  9/600 [..............................] - ETA: 7:42
 10/600 [..............................] - ETA: 7:08
 11/600 [..............................] - ETA: 6:41
 12/600 [..............................] - ETA: 6:17
 13/600 [..............................] - ETA: 5:57
 14/600 [..............................] - ETA: 5:40
 15/600 [..............................] - ETA: 5:24
 16/600 [..............................] - ETA: 5:13
 17/600 [..............................] - ETA: 5:02
 18/600 [..............................] - ETA: 4:51
 19/600 [..............................] - ETA: 4:42
 20/600 [>.............................] - ETA: 4:34
 21/600 [>.............................] - ETA: 4:26
 22/600 [>.............................] - ETA: 4:19
 23/600 [>.............................] - ETA: 4:12
 24/600 [>.............................] - ETA: 4:07
 25/600 [>.............................] - ETA: 4:01
 26/600 [>.............................] - ETA: 3:56
 27/600 [>.............................] - ETA: 3:51
 28/600 [>.............................] - ETA: 3:51
 29/600 [>.............................] - ETA: 3:47
 30/600 [>.............................] - ETA: 3:43
 31/600 [>.............................] - ETA: 3:39
 32/600 [>.............................] - ETA: 3:37
 33/600 [>.............................] - ETA: 3:34
 34/600 [>.............................] - ETA: 3:31
 35/600 [>.............................] - ETA: 3:28
 36/600 [>.............................] - ETA: 3:25
 37/600 [>.............................] - ETA: 3:23
 38/600 [>.............................] - ETA: 3:20
 39/600 [>.............................] - ETA: 3:18
 40/600 [=>............................] - ETA: 3:16
 41/600 [=>............................] - ETA: 3:14
 42/600 [=>............................] - ETA: 3:12
 43/600 [=>............................] - ETA: 3:11
 44/600 [=>............................] - ETA: 3:09
 45/600 [=>............................] - ETA: 3:07
 46/600 [=>............................] - ETA: 3:06
 47/600 [=>............................] - ETA: 3:04
 48/600 [=>............................] - ETA: 3:02
 49/600 [=>............................] - ETA: 3:01
 50/600 [=>............................] - ETA: 2:59
 51/600 [=>............................] - ETA: 2:58
 52/600 [=>............................] - ETA: 2:56
 53/600 [=>............................] - ETA: 2:55
 54/600 [=>............................] - ETA: 2:53
 55/600 [=>............................] - ETA: 2:52
 56/600 [=>............................] - ETA: 2:51
 57/600 [=>............................] - ETA: 2:49
 58/600 [=>............................] - ETA: 2:48
 59/600 [=>............................] - ETA: 2:47
 60/600 [==>...........................] - ETA: 2:46
 61/600 [==>...........................] - ETA: 2:44
 62/600 [==>...........................] - ETA: 2:43
 63/600 [==>...........................] - ETA: 2:42
 64/600 [==>...........................] - ETA: 2:41
 65/600 [==>...........................] - ETA: 2:40
 66/600 [==>...........................] - ETA: 2:39
 67/600 [==>...........................] - ETA: 2:38
 68/600 [==>...........................] - ETA: 2:37
 69/600 [==>...........................] - ETA: 2:36
 70/600 [==>...........................] - ETA: 2:35
 71/600 [==>...........................] - ETA: 2:35
 72/600 [==>...........................] - ETA: 2:34
 73/600 [==>...........................] - ETA: 2:33
 74/600 [==>...........................] - ETA: 2:32
 75/600 [==>...........................] - ETA: 2:31
 76/600 [==>...........................] - ETA: 2:30
 77/600 [==>...........................] - ETA: 2:29
 78/600 [==>...........................] - ETA: 2:29
 79/600 [==>...........................] - ETA: 2:28
 80/600 [===>..........................] - ETA: 2:27
 81/600 [===>..........................] - ETA: 2:26
 82/600 [===>..........................] - ETA: 2:26
 83/600 [===>..........................] - ETA: 2:25
 84/600 [===>..........................] - ETA: 2:24
 85/600 [===>..........................] - ETA: 2:24
 86/600 [===>..........................] - ETA: 2:23
 87/600 [===>..........................] - ETA: 2:22
 88/600 [===>..........................] - ETA: 2:22
 89/600 [===>..........................] - ETA: 2:21
 90/600 [===>..........................] - ETA: 2:20
 91/600 [===>..........................] - ETA: 2:20
 92/600 [===>..........................] - ETA: 2:19
 93/600 [===>..........................] - ETA: 2:18
 94/600 [===>..........................] - ETA: 2:18
 95/600 [===>..........................] - ETA: 2:17
 96/600 [===>..........................] - ETA: 2:17
 97/600 [===>..........................] - ETA: 2:16
 98/600 [===>..........................] - ETA: 2:16
 99/600 [===>..........................] - ETA: 2:15
100/600 [====>.........................] - ETA: 2:15
101/600 [====>.........................] - ETA: 2:14
102/600 [====>.........................] - ETA: 2:13
103/600 [====>.........................] - ETA: 2:13
104/600 [====>.........................] - ETA: 2:13
105/600 [====>.........................] - ETA: 2:12
106/600 [====>.........................] - ETA: 2:11
107/600 [====>.........................] - ETA: 2:11
108/600 [====>.........................] - ETA: 2:10
109/600 [====>.........................] - ETA: 2:10
110/600 [====>.........................] - ETA: 2:09
111/600 [====>.........................] - ETA: 2:09
112/600 [====>.........................] - ETA: 2:08
113/600 [====>.........................] - ETA: 2:08
114/600 [====>.........................] - ETA: 2:07
115/600 [====>.........................] - ETA: 2:07
116/600 [====>.........................] - ETA: 2:06
117/600 [====>.........................] - ETA: 2:06
118/600 [====>.........................] - ETA: 2:06
119/600 [====>.........................] - ETA: 2:05
120/600 [=====>........................] - ETA: 2:05
121/600 [=====>........................] - ETA: 2:04
122/600 [=====>........................] - ETA: 2:04
123/600 [=====>........................] - ETA: 2:03
124/600 [=====>........................] - ETA: 2:03
125/600 [=====>........................] - ETA: 2:02
126/600 [=====>........................] - ETA: 2:02
127/600 [=====>........................] - ETA: 2:02
128/600 [=====>........................] - ETA: 2:01
129/600 [=====>........................] - ETA: 2:01
130/600 [=====>........................] - ETA: 2:00
131/600 [=====>........................] - ETA: 2:00
132/600 [=====>........................] - ETA: 2:00
133/600 [=====>........................] - ETA: 1:59
134/600 [=====>........................] - ETA: 1:59
135/600 [=====>........................] - ETA: 1:58
136/600 [=====>........................] - ETA: 1:58
137/600 [=====>........................] - ETA: 1:58
138/600 [=====>........................] - ETA: 1:57
139/600 [=====>........................] - ETA: 1:57
140/600 [======>.......................] - ETA: 1:57
141/600 [======>.......................] - ETA: 1:56
142/600 [======>.......................] - ETA: 1:56
143/600 [======>.......................] - ETA: 1:55
144/600 [======>.......................] - ETA: 1:55
145/600 [======>.......................] - ETA: 1:55
146/600 [======>.......................] - ETA: 1:54
147/600 [======>.......................] - ETA: 1:54
148/600 [======>.......................] - ETA: 1:54
149/600 [======>.......................] - ETA: 1:53
150/600 [======>.......................] - ETA: 1:54
151/600 [======>.......................] - ETA: 1:53
152/600 [======>.......................] - ETA: 1:53
153/600 [======>.......................] - ETA: 1:54
154/600 [======>.......................] - ETA: 1:54
155/600 [======>.......................] - ETA: 1:53
156/600 [======>.......................] - ETA: 1:53
157/600 [======>.......................] - ETA: 1:52
158/600 [======>.......................] - ETA: 1:52
159/600 [======>.......................] - ETA: 1:52
160/600 [=======>......................] - ETA: 1:51
161/600 [=======>......................] - ETA: 1:51
162/600 [=======>......................] - ETA: 1:51
163/600 [=======>......................] - ETA: 1:50
164/600 [=======>......................] - ETA: 1:50
165/600 [=======>......................] - ETA: 1:50
166/600 [=======>......................] - ETA: 1:49
167/600 [=======>......................] - ETA: 1:49
168/600 [=======>......................] - ETA: 1:48
169/600 [=======>......................] - ETA: 1:48
170/600 [=======>......................] - ETA: 1:48
171/600 [=======>......................] - ETA: 1:47
172/600 [=======>......................] - ETA: 1:47
173/600 [=======>......................] - ETA: 1:47
174/600 [=======>......................] - ETA: 1:46
175/600 [=======>......................] - ETA: 1:46
176/600 [=======>......................] - ETA: 1:46
177/600 [=======>......................] - ETA: 1:45
178/600 [=======>......................] - ETA: 1:45
179/600 [=======>......................] - ETA: 1:45
180/600 [========>.....................] - ETA: 1:44
181/600 [========>.....................] - ETA: 1:44
182/600 [========>.....................] - ETA: 1:44
183/600 [========>.....................] - ETA: 1:43
184/600 [========>.....................] - ETA: 1:43
185/600 [========>.....................] - ETA: 1:43
186/600 [========>.....................] - ETA: 1:42
187/600 [========>.....................] - ETA: 1:42
188/600 [========>.....................] - ETA: 1:42
189/600 [========>.....................] - ETA: 1:41
190/600 [========>.....................] - ETA: 1:41
191/600 [========>.....................] - ETA: 1:41
192/600 [========>.....................] - ETA: 1:40
193/600 [========>.....................] - ETA: 1:40
194/600 [========>.....................] - ETA: 1:40
195/600 [========>.....................] - ETA: 1:39
196/600 [========>.....................] - ETA: 1:39
197/600 [========>.....................] - ETA: 1:39
198/600 [========>.....................] - ETA: 1:38
199/600 [========>.....................] - ETA: 1:38
200/600 [=========>....................] - ETA: 1:38
201/600 [=========>....................] - ETA: 1:37
202/600 [=========>....................] - ETA: 1:37
203/600 [=========>....................] - ETA: 1:37
204/600 [=========>....................] - ETA: 1:37
205/600 [=========>....................] - ETA: 1:36
206/600 [=========>....................] - ETA: 1:36
207/600 [=========>....................] - ETA: 1:36
208/600 [=========>....................] - ETA: 1:35
209/600 [=========>....................] - ETA: 1:35
210/600 [=========>....................] - ETA: 1:35
211/600 [=========>....................] - ETA: 1:34
212/600 [=========>....................] - ETA: 1:34
213/600 [=========>....................] - ETA: 1:34
214/600 [=========>....................] - ETA: 1:34
215/600 [=========>....................] - ETA: 1:33
216/600 [=========>....................] - ETA: 1:33
217/600 [=========>....................] - ETA: 1:33
218/600 [=========>....................] - ETA: 1:32
219/600 [=========>....................] - ETA: 1:32
220/600 [==========>...................] - ETA: 1:32
221/600 [==========>...................] - ETA: 1:31
222/600 [==========>...................] - ETA: 1:31
223/600 [==========>...................] - ETA: 1:31
224/600 [==========>...................] - ETA: 1:31
225/600 [==========>...................] - ETA: 1:30
226/600 [==========>...................] - ETA: 1:30
227/600 [==========>...................] - ETA: 1:30
228/600 [==========>...................] - ETA: 1:30
229/600 [==========>...................] - ETA: 1:29
230/600 [==========>...................] - ETA: 1:29
231/600 [==========>...................] - ETA: 1:29
232/600 [==========>...................] - ETA: 1:28
233/600 [==========>...................] - ETA: 1:28
234/600 [==========>...................] - ETA: 1:28
235/600 [==========>...................] - ETA: 1:28
236/600 [==========>...................] - ETA: 1:27
237/600 [==========>...................] - ETA: 1:27
238/600 [==========>...................] - ETA: 1:27
239/600 [==========>...................] - ETA: 1:26
240/600 [===========>..................] - ETA: 1:26
241/600 [===========>..................] - ETA: 1:26
242/600 [===========>..................] - ETA: 1:26
243/600 [===========>..................] - ETA: 1:25
244/600 [===========>..................] - ETA: 1:25
245/600 [===========>..................] - ETA: 1:25
246/600 [===========>..................] - ETA: 1:24
247/600 [===========>..................] - ETA: 1:24
248/600 [===========>..................] - ETA: 1:24
249/600 [===========>..................] - ETA: 1:24
250/600 [===========>..................] - ETA: 1:23
251/600 [===========>..................] - ETA: 1:23
252/600 [===========>..................] - ETA: 1:23
253/600 [===========>..................] - ETA: 1:22
254/600 [===========>..................] - ETA: 1:22
255/600 [===========>..................] - ETA: 1:22
256/600 [===========>..................] - ETA: 1:22
257/600 [===========>..................] - ETA: 1:21
258/600 [===========>..................] - ETA: 1:21
259/600 [===========>..................] - ETA: 1:21
260/600 [============>.................] - ETA: 1:20
261/600 [============>.................] - ETA: 1:20
262/600 [============>.................] - ETA: 1:20
263/600 [============>.................] - ETA: 1:20
264/600 [============>.................] - ETA: 1:19
265/600 [============>.................] - ETA: 1:19
266/600 [============>.................] - ETA: 1:19
267/600 [============>.................] - ETA: 1:19
268/600 [============>.................] - ETA: 1:18
269/600 [============>.................] - ETA: 1:18
270/600 [============>.................] - ETA: 1:18
271/600 [============>.................] - ETA: 1:18
272/600 [============>.................] - ETA: 1:17
273/600 [============>.................] - ETA: 1:17
274/600 [============>.................] - ETA: 1:17
275/600 [============>.................] - ETA: 1:17
276/600 [============>.................] - ETA: 1:16
277/600 [============>.................] - ETA: 1:16
278/600 [============>.................] - ETA: 1:16
279/600 [============>.................] - ETA: 1:15
280/600 [=============>................] - ETA: 1:15
281/600 [=============>................] - ETA: 1:15
282/600 [=============>................] - ETA: 1:15
283/600 [=============>................] - ETA: 1:14
284/600 [=============>................] - ETA: 1:14
285/600 [=============>................] - ETA: 1:14
286/600 [=============>................] - ETA: 1:14
287/600 [=============>................] - ETA: 1:13
288/600 [=============>................] - ETA: 1:13
289/600 [=============>................] - ETA: 1:13
290/600 [=============>................] - ETA: 1:13
291/600 [=============>................] - ETA: 1:12
292/600 [=============>................] - ETA: 1:12
293/600 [=============>................] - ETA: 1:12
294/600 [=============>................] - ETA: 1:12
295/600 [=============>................] - ETA: 1:12
296/600 [=============>................] - ETA: 1:11
297/600 [=============>................] - ETA: 1:11
298/600 [=============>................] - ETA: 1:11
299/600 [=============>................] - ETA: 1:11
300/600 [==============>...............] - ETA: 1:10
301/600 [==============>...............] - ETA: 1:10
302/600 [==============>...............] - ETA: 1:10
303/600 [==============>...............] - ETA: 1:09
304/600 [==============>...............] - ETA: 1:09
305/600 [==============>...............] - ETA: 1:09
306/600 [==============>...............] - ETA: 1:09
307/600 [==============>...............] - ETA: 1:09
308/600 [==============>...............] - ETA: 1:08
309/600 [==============>...............] - ETA: 1:08
310/600 [==============>...............] - ETA: 1:08
311/600 [==============>...............] - ETA: 1:08
312/600 [==============>...............] - ETA: 1:07
313/600 [==============>...............] - ETA: 1:07
314/600 [==============>...............] - ETA: 1:07
315/600 [==============>...............] - ETA: 1:06
316/600 [==============>...............] - ETA: 1:06
317/600 [==============>...............] - ETA: 1:06
318/600 [==============>...............] - ETA: 1:06
319/600 [==============>...............] - ETA: 1:05
320/600 [===============>..............] - ETA: 1:05
321/600 [===============>..............] - ETA: 1:05
322/600 [===============>..............] - ETA: 1:05
323/600 [===============>..............] - ETA: 1:04
324/600 [===============>..............] - ETA: 1:04
325/600 [===============>..............] - ETA: 1:04
326/600 [===============>..............] - ETA: 1:04
327/600 [===============>..............] - ETA: 1:04
328/600 [===============>..............] - ETA: 1:04
329/600 [===============>..............] - ETA: 1:03
330/600 [===============>..............] - ETA: 1:03
331/600 [===============>..............] - ETA: 1:03
332/600 [===============>..............] - ETA: 1:03
333/600 [===============>..............] - ETA: 1:02
334/600 [===============>..............] - ETA: 1:02
335/600 [===============>..............] - ETA: 1:02
336/600 [===============>..............] - ETA: 1:02
337/600 [===============>..............] - ETA: 1:01
338/600 [===============>..............] - ETA: 1:01
339/600 [===============>..............] - ETA: 1:01
340/600 [================>.............] - ETA: 1:01
341/600 [================>.............] - ETA: 1:00
342/600 [================>.............] - ETA: 1:00
343/600 [================>.............] - ETA: 1:00
344/600 [================>.............] - ETA: 1:00
345/600 [================>.............] - ETA: 59s
346/600 [================>.............] - ETA: 59s
347/600 [================>.............] - ETA: 59s
348/600 [================>.............] - ETA: 59s
349/600 [================>.............] - ETA: 58s
350/600 [================>.............] - ETA: 58s
351/600 [================>.............] - ETA: 58s
352/600 [================>.............] - ETA: 58s
353/600 [================>.............] - ETA: 57s
354/600 [================>.............] - ETA: 57s
355/600 [================>.............] - ETA: 57s
356/600 [================>.............] - ETA: 57s
357/600 [================>.............] - ETA: 56s
358/600 [================>.............] - ETA: 56s
359/600 [================>.............] - ETA: 56s
360/600 [=================>............] - ETA: 56s
361/600 [=================>............] - ETA: 55s
362/600 [=================>............] - ETA: 55s
363/600 [=================>............] - ETA: 55s
364/600 [=================>............] - ETA: 55s
365/600 [=================>............] - ETA: 54s
366/600 [=================>............] - ETA: 54s
367/600 [=================>............] - ETA: 54s
368/600 [=================>............] - ETA: 54s
369/600 [=================>............] - ETA: 54s
370/600 [=================>............] - ETA: 53s
371/600 [=================>............] - ETA: 53s
372/600 [=================>............] - ETA: 53s
373/600 [=================>............] - ETA: 53s
374/600 [=================>............] - ETA: 52s
375/600 [=================>............] - ETA: 52s
376/600 [=================>............] - ETA: 52s
377/600 [=================>............] - ETA: 52s
378/600 [=================>............] - ETA: 51s
379/600 [=================>............] - ETA: 51s
380/600 [==================>...........] - ETA: 51s
381/600 [==================>...........] - ETA: 51s
382/600 [==================>...........] - ETA: 50s
383/600 [==================>...........] - ETA: 50s
384/600 [==================>...........] - ETA: 50s
385/600 [==================>...........] - ETA: 50s
386/600 [==================>...........] - ETA: 49s
387/600 [==================>...........] - ETA: 49s
388/600 [==================>...........] - ETA: 49s
389/600 [==================>...........] - ETA: 49s
390/600 [==================>...........] - ETA: 48s
391/600 [==================>...........] - ETA: 48s
392/600 [==================>...........] - ETA: 48s
393/600 [==================>...........] - ETA: 48s
394/600 [==================>...........] - ETA: 47s
395/600 [==================>...........] - ETA: 47s
396/600 [==================>...........] - ETA: 47s
397/600 [==================>...........] - ETA: 47s
398/600 [==================>...........] - ETA: 46s
399/600 [==================>...........] - ETA: 46s
400/600 [===================>..........] - ETA: 46s
401/600 [===================>..........] - ETA: 46s
402/600 [===================>..........] - ETA: 45s
403/600 [===================>..........] - ETA: 45s
404/600 [===================>..........] - ETA: 45s
405/600 [===================>..........] - ETA: 45s
406/600 [===================>..........] - ETA: 44s
407/600 [===================>..........] - ETA: 44s
408/600 [===================>..........] - ETA: 44s
409/600 [===================>..........] - ETA: 44s
410/600 [===================>..........] - ETA: 43s
411/600 [===================>..........] - ETA: 43s
412/600 [===================>..........] - ETA: 43s
413/600 [===================>..........] - ETA: 43s
414/600 [===================>..........] - ETA: 43s
415/600 [===================>..........] - ETA: 42s
416/600 [===================>..........] - ETA: 42s
417/600 [===================>..........] - ETA: 42s
418/600 [===================>..........] - ETA: 42s
419/600 [===================>..........] - ETA: 41s
420/600 [====================>.........] - ETA: 41s
421/600 [====================>.........] - ETA: 41s
422/600 [====================>.........] - ETA: 41s
423/600 [====================>.........] - ETA: 40s
424/600 [====================>.........] - ETA: 40s
425/600 [====================>.........] - ETA: 40s
426/600 [====================>.........] - ETA: 40s
427/600 [====================>.........] - ETA: 39s
428/600 [====================>.........] - ETA: 39s
429/600 [====================>.........] - ETA: 39s
430/600 [====================>.........] - ETA: 39s
431/600 [====================>.........] - ETA: 38s
432/600 [====================>.........] - ETA: 38s
433/600 [====================>.........] - ETA: 38s
434/600 [====================>.........] - ETA: 38s
435/600 [====================>.........] - ETA: 37s
436/600 [====================>.........] - ETA: 37s
437/600 [====================>.........] - ETA: 37s
438/600 [====================>.........] - ETA: 37s
439/600 [====================>.........] - ETA: 37s
440/600 [=====================>........] - ETA: 36s
441/600 [=====================>........] - ETA: 36s
442/600 [=====================>........] - ETA: 36s
443/600 [=====================>........] - ETA: 36s
444/600 [=====================>........] - ETA: 35s
445/600 [=====================>........] - ETA: 35s
446/600 [=====================>........] - ETA: 35s
447/600 [=====================>........] - ETA: 35s
448/600 [=====================>........] - ETA: 34s
449/600 [=====================>........] - ETA: 34s
450/600 [=====================>........] - ETA: 34s
451/600 [=====================>........] - ETA: 34s
452/600 [=====================>........] - ETA: 33s
453/600 [=====================>........] - ETA: 33s
454/600 [=====================>........] - ETA: 33s
455/600 [=====================>........] - ETA: 33s
456/600 [=====================>........] - ETA: 33s
457/600 [=====================>........] - ETA: 32s
458/600 [=====================>........] - ETA: 32s
459/600 [=====================>........] - ETA: 32s
460/600 [======================>.......] - ETA: 32s
461/600 [======================>.......] - ETA: 31s
462/600 [======================>.......] - ETA: 31s
463/600 [======================>.......] - ETA: 31s
464/600 [======================>.......] - ETA: 31s
465/600 [======================>.......] - ETA: 30s
466/600 [======================>.......] - ETA: 30s
467/600 [======================>.......] - ETA: 30s
468/600 [======================>.......] - ETA: 30s
469/600 [======================>.......] - ETA: 29s
470/600 [======================>.......] - ETA: 29s
471/600 [======================>.......] - ETA: 29s
472/600 [======================>.......] - ETA: 29s
473/600 [======================>.......] - ETA: 29s
474/600 [======================>.......] - ETA: 28s
475/600 [======================>.......] - ETA: 28s
476/600 [======================>.......] - ETA: 28s
477/600 [======================>.......] - ETA: 28s
478/600 [======================>.......] - ETA: 27s
479/600 [======================>.......] - ETA: 27s
480/600 [=======================>......] - ETA: 27s
481/600 [=======================>......] - ETA: 27s
482/600 [=======================>......] - ETA: 26s
483/600 [=======================>......] - ETA: 26s
484/600 [=======================>......] - ETA: 26s
485/600 [=======================>......] - ETA: 26s
486/600 [=======================>......] - ETA: 26s
487/600 [=======================>......] - ETA: 25s
488/600 [=======================>......] - ETA: 25s
489/600 [=======================>......] - ETA: 25s
490/600 [=======================>......] - ETA: 25s
491/600 [=======================>......] - ETA: 24s
492/600 [=======================>......] - ETA: 24s
493/600 [=======================>......] - ETA: 24s
494/600 [=======================>......] - ETA: 24s
495/600 [=======================>......] - ETA: 23s
496/600 [=======================>......] - ETA: 23s
497/600 [=======================>......] - ETA: 23s
498/600 [=======================>......] - ETA: 23s
499/600 [=======================>......] - ETA: 23s
500/600 [========================>.....] - ETA: 22s
501/600 [========================>.....] - ETA: 22s
502/600 [========================>.....] - ETA: 22s
503/600 [========================>.....] - ETA: 22s
504/600 [========================>.....] - ETA: 21s
505/600 [========================>.....] - ETA: 21s
506/600 [========================>.....] - ETA: 21s
507/600 [========================>.....] - ETA: 21s
508/600 [========================>.....] - ETA: 20s
509/600 [========================>.....] - ETA: 20s
510/600 [========================>.....] - ETA: 20s
511/600 [========================>.....] - ETA: 20s
512/600 [========================>.....] - ETA: 20s
513/600 [========================>.....] - ETA: 19s
514/600 [========================>.....] - ETA: 19s
515/600 [========================>.....] - ETA: 19s
516/600 [========================>.....] - ETA: 19s
517/600 [========================>.....] - ETA: 18s
518/600 [========================>.....] - ETA: 18s
519/600 [========================>.....] - ETA: 18s
520/600 [=========================>....] - ETA: 18s
521/600 [=========================>....] - ETA: 17s
522/600 [=========================>....] - ETA: 17s
523/600 [=========================>....] - ETA: 17s
524/600 [=========================>....] - ETA: 17s
525/600 [=========================>....] - ETA: 17s
526/600 [=========================>....] - ETA: 16s
527/600 [=========================>....] - ETA: 16s
528/600 [=========================>....] - ETA: 16s
529/600 [=========================>....] - ETA: 16s
530/600 [=========================>....] - ETA: 15s
531/600 [=========================>....] - ETA: 15s
532/600 [=========================>....] - ETA: 15s
533/600 [=========================>....] - ETA: 15s
534/600 [=========================>....] - ETA: 14s
535/600 [=========================>....] - ETA: 14s
536/600 [=========================>....] - ETA: 14s
537/600 [=========================>....] - ETA: 14s
538/600 [=========================>....] - ETA: 14s
539/600 [=========================>....] - ETA: 13s
540/600 [==========================>...] - ETA: 13s
541/600 [==========================>...] - ETA: 13s
542/600 [==========================>...] - ETA: 13s
543/600 [==========================>...] - ETA: 12s
544/600 [==========================>...] - ETA: 12s
545/600 [==========================>...] - ETA: 12s
546/600 [==========================>...] - ETA: 12s
547/600 [==========================>...] - ETA: 12s
548/600 [==========================>...] - ETA: 11s
549/600 [==========================>...] - ETA: 11s
550/600 [==========================>...] - ETA: 11s
551/600 [==========================>...] - ETA: 11s
552/600 [==========================>...] - ETA: 10s
553/600 [==========================>...] - ETA: 10s
554/600 [==========================>...] - ETA: 10s
555/600 [==========================>...] - ETA: 10s
556/600 [==========================>...] - ETA: 9s
557/600 [==========================>...] - ETA: 9s
558/600 [==========================>...] - ETA: 9s
559/600 [==========================>...] - ETA: 9s
560/600 [===========================>..] - ETA: 9s
561/600 [===========================>..] - ETA: 8s
562/600 [===========================>..] - ETA: 8s
563/600 [===========================>..] - ETA: 8s
564/600 [===========================>..] - ETA: 8s
565/600 [===========================>..] - ETA: 7s
566/600 [===========================>..] - ETA: 7s
567/600 [===========================>..] - ETA: 7s
568/600 [===========================>..] - ETA: 7s
569/600 [===========================>..] - ETA: 7s
570/600 [===========================>..] - ETA: 6s
571/600 [===========================>..] - ETA: 6s
572/600 [===========================>..] - ETA: 6s
573/600 [===========================>..] - ETA: 6s
574/600 [===========================>..] - ETA: 5s
575/600 [===========================>..] - ETA: 5s
576/600 [===========================>..] - ETA: 5s
577/600 [===========================>..] - ETA: 5s
578/600 [===========================>..] - ETA: 4s
579/600 [===========================>..] - ETA: 4s
580/600 [============================>.] - ETA: 4s
581/600 [============================>.] - ETA: 4s
582/600 [============================>.] - ETA: 4s
583/600 [============================>.] - ETA: 3s
584/600 [============================>.] - ETA: 3s
585/600 [============================>.] - ETA: 3s
586/600 [============================>.] - ETA: 3s
587/600 [============================>.] - ETA: 2s
588/600 [============================>.] - ETA: 2s
589/600 [============================>.] - ETA: 2s
590/600 [============================>.] - ETA: 2s
591/600 [============================>.] - ETA: 2s
592/600 [============================>.] - ETA: 1s
593/600 [============================>.] - ETA: 1s
594/600 [============================>.] - ETA: 1s
595/600 [============================>.] - ETA: 1s
596/600 [============================>.] - ETA: 0s
597/600 [============================>.] - ETA: 0s
598/600 [============================>.] - ETA: 0s
599/600 [============================>.] - ETA: 0s
600/600 [==============================] - 135s 225ms/step
Testing for epoch 1:
component              | loss | generation_loss | auxiliary_loss
-----------------------------------------------------------------
generator (train)      | 1.40 | 0.9750          | 0.4249
generator (test)       | 1.18 | 1.1657          | 0.0161
discriminator (train)  | 1.55 | 0.6922          | 0.8536
discriminator (test)   | 0.59 | 0.4920          | 0.0960
Epoch 2/100

  1/600 [..............................] - ETA: 2:14
  2/600 [..............................] - ETA: 2:09


599/600 [============================>.] - ETA: 0s
600/600 [==============================] - 124s 206ms/step
Testing for epoch 100:
component              | loss | generation_loss | auxiliary_loss
-----------------------------------------------------------------
generator (train)      | 0.76 | 0.7628          | 0.0005
generator (test)       | 0.82 | 0.8151          | 0.0000
discriminator (train)  | 0.71 | 0.6932          | 0.0145
discriminator (test)   | 0.70 | 0.6942          | 0.0106

Process finished with exit code 0

Keras详细介绍

英文:https://keras.io/

中文:http://keras-cn.readthedocs.io/en/latest/

实例下载

https://github.com/keras-team/keras

https://github.com/keras-team/keras/tree/master/examples

完整项目下载

方便没积分童鞋,请加企鹅452205574,共享文件夹。

包括:代码、数据集合(图片)、已生成model、安装库文件等。

猜你喜欢

转载自blog.csdn.net/wyx100/article/details/80821709
今日推荐