Runtime Error: Disconnected graph for GANs because input can't be obtained

感情迁移 提交于 2019-12-06 06:33:07

You have forgotten to add the temp as one of the inputs of the GAN (that's why the error says it can't feed the corresponding tensor since it is essentially disconnected):

combined = Model([z, temp], valid)

As a side note, I highly recommend to use Keras Functional API for building complicated and multi branch models like your discriminator. It is much easier to use, being more flexible and less error-prone.

For example, this is the descriminator you have written but I have rewritten it using Functional API. I personally think it is much easier to follow:

def build_discriminator(img_shape,embedding_shape):

    input_img = Input(shape=img_shape)
    x = Conv2D(32, kernel_size=5, strides=2, padding="same")(input_img)
    x = LeakyReLU(alpha=0.2)(x)
    x = Dropout(0.25)(x)
    x = Conv2D(48, kernel_size=5, strides=2, padding="same")(x)
    x = BatchNormalization(momentum=0.8)(x)
    x = LeakyReLU(alpha=0.2)(x)
    x = Dropout(0.25)(x)
    x = Conv2D(64, kernel_size=5, strides=2, padding="same")(x)
    x = BatchNormalization(momentum=0.8)(x)
    x = LeakyReLU(alpha=0.2)(x)
    x = Dropout(0.25)(x)
    x = Conv2D(128, kernel_size=5, strides=2, padding="same")(x)
    x = BatchNormalization(momentum=0.8)(x)
    x = LeakyReLU(alpha=0.2)(x)
    x = Dropout(0.25)(x)
    x = Conv2D(256, kernel_size=5, strides=2, padding="same")(x)
    x = BatchNormalization(momentum=0.8)(x)
    x = LeakyReLU(alpha=0.2)(x)
    x = Dropout(0.25)(x)
    x = Flatten()(x)
    output_img = Dense(200)(x)

    input_emb = Input(shape=embedding_shape)
    y = Dense(50)(input_emb)
    y = Dense(100)(y)
    y = Dense(200)(y)
    output_emb = Flatten()(y)

    merged = concatenate([output_img, output_emb])
    output_merge = Dense(1, activation='sigmoid', name='output_layer')(merged)

    return Model([input_img, input_emb], output_merge)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!