DL之DCGAN:基于keras框架利用深度卷积对抗网络DCGAN算法对MNIST数据集实现图像生成

DL之DCGAN:基于keras框架利用深度卷积对抗网络DCGAN算法对MNIST数据集实现图像生成


相关文章
DL之DCGAN:基于keras框架利用深度卷积对抗网络DCGAN算法对MNIST数据集实现图像生成
DL之DCGAN:基于keras框架利用深度卷积对抗网络DCGAN算法对MNIST数据集实现图像生成实现

基于keras框架利用深度卷积对抗网络DCGAN算法对MNIST数据集实现图像生成

设计思路

输出结果

X像素取值范围是[-1.0, 1.0]
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense_1 (Dense)              (None, 1024)              103424
_________________________________________________________________
activation_1 (Activation)    (None, 1024)              0
_________________________________________________________________
dense_2 (Dense)              (None, 6272)              6428800
_________________________________________________________________
batch_normalization_1 (Batch (None, 6272)              25088
_________________________________________________________________
activation_2 (Activation)    (None, 6272)              0
_________________________________________________________________
reshape_1 (Reshape)          (None, 7, 7, 128)         0
_________________________________________________________________
up_sampling2d_1 (UpSampling2 (None, 14, 14, 128)       0
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 14, 14, 64)        204864
_________________________________________________________________
activation_3 (Activation)    (None, 14, 14, 64)        0
_________________________________________________________________
up_sampling2d_2 (UpSampling2 (None, 28, 28, 64)        0
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 28, 28, 1)         1601
_________________________________________________________________
activation_4 (Activation)    (None, 28, 28, 1)         0
=================================================================
Total params: 6,763,777
Trainable params: 6,751,233
Non-trainable params: 12,544
_________________________________________________________________
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d_3 (Conv2D)            (None, 28, 28, 64)        1664
_________________________________________________________________
activation_5 (Activation)    (None, 28, 28, 64)        0
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 14, 14, 64)        0
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 10, 10, 128)       204928
_________________________________________________________________
activation_6 (Activation)    (None, 10, 10, 128)       0
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 5, 5, 128)         0
_________________________________________________________________
flatten_1 (Flatten)          (None, 3200)              0
_________________________________________________________________
dense_3 (Dense)              (None, 1024)              3277824
_________________________________________________________________
activation_7 (Activation)    (None, 1024)              0
_________________________________________________________________
dense_4 (Dense)              (None, 1)                 1025
_________________________________________________________________
activation_8 (Activation)    (None, 1)                 0
=================================================================
Total params: 3,485,441
Trainable params: 3,485,441
Non-trainable params: 0
_________________________________________________________________
2020-11-24 21:53:56.659897: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
(25, 28, 28, 1)

核心代码

def generator_model():
    model = Sequential()
    model.add(Dense(input_dim=100, units=1024))     #  1034  1024
    model.add(Activation('tanh'))
    model.add(Dense(128*7*7))
    model.add(BatchNormalization())
    model.add(Activation('tanh'))
    model.add(Reshape((7, 7, 128), input_shape=(128*7*7,)))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(Conv2D(64, (5, 5), padding='same'))
    model.add(Activation('tanh'))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(Conv2D(1, (5, 5), padding='same'))
    model.add(Activation('tanh'))
    return model
def discriminator_model():     # 定义鉴别网络:输入一张图像,输出0(伪造)/1(真实)
    model = Sequential()
    model.add(
            Conv2D(64, (5, 5),
            padding='same',
            input_shape=(28, 28, 1))
            )
    model.add(Activation('tanh'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(128, (5, 5)))
    model.add(Activation('tanh'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Flatten())
    model.add(Dense(1024))
    model.add(Activation('tanh'))
    model.add(Dense(1))
    model.add(Activation('sigmoid'))
    return model

g = generator_model()
g.summary()

d = discriminator_model()
d.summary()
(0)

相关推荐