如何确认keras.layer密集层的第一个参数

时间:2019-04-01 03:23:41

标签: python keras

这是一大进步,我只是研究它的鉴别器。如您所知,这是一个分类模型。原因是我尝试打印此模型的结构但出了错。 密集层(d9)看起来不正确,我需要您的帮助。您可以使用keras运行此脚本。

from keras.datasets import mnist
from keras.layers import Input, Dense, Reshape, Flatten, Dropout, Concatenate
from keras.layers import BatchNormalization, Activation, ZeroPadding2D, Add
from keras.layers.advanced_activations import PReLU, LeakyReLU
from keras.layers.convolutional import UpSampling2D, Conv2D
from keras.applications import VGG19
from keras.models import Sequential, Model
from keras.optimizers import Adam
import numpy as np

def d_block(layer_input, filters, strides=1, bn=True):
    """Discriminator layer"""
    d = Conv2D(filters, kernel_size=3, strides=strides, padding='same')(layer_input)
    d = LeakyReLU(alpha=0.2)(d)
    if bn:
         BatchNormalization(momentum=0.8)(d)
    return d
def discriminator(df,hr_shape):
    # Input img
    d0 = Input(shape=hr_shape)
    print(d0)
    d1 = d_block(d0, df, bn=False)
    print(d1)
    d2 = d_block(d1, df, strides=2)
    print(d2)
    d3 = d_block(d2, df*2)
    print(d3)
    d4 = d_block(d3, df*2, strides=2)
    print(d4)
    d5 = d_block(d4, df*4)
    print(d5)
    d6 = d_block(d5, df*4, strides=2)
    d7 = d_block(d6, df*8)
    d8 = d_block(d7, df*8, strides=2)
    print(d8)
    d9 = Dense(output_dim=df*16)(d8)
    print(d9)
    d10 = LeakyReLU(alpha=0.2)(d9)
    print(d10)
    validity = Dense(1, activation='sigmoid')(d10)

    #return Model(d0, validity)

def main():
    discriminator(64,(3,64*4,64*4))


if __name__=="__main__":
    main()

错误信息是:

  

ValueError:尺寸必须相等,但对于512和1024   输入形状为[?,512,16,1024]的“ dense_6 / BiasAdd”(操作:“ BiasAdd”),   [1024]。 d9不正确

。希望您能告诉我为什么是错的。实际上,它来自GitHub project

0 个答案:

没有答案