如何将张量传递给model.predict

时间:2019-11-27 00:05:28

标签: tensorflow keras

我定义了如下函数,其中生成器和鉴别器都是两个Keras模型。

def build_combined():
    # The generator takes noise as input and generates imgs
    z = Input(shape=(latent_dim,))
    img = generator(z)

    # For the combined model we will only train the generator
    discriminator.trainable = False

    # The discriminator takes generated images as input and determines validity
    validity = discriminator(img)

    # The combined model  (stacked generator and discriminator)
    # Trains the generator to fool the discriminator
    combined = Model(z, validity)
    combined.compile(loss='binary_crossentropy',optimizer=optimizer)
    return combined

如何通过以下方式写下与上述功能相同的功能:

def build_combined():
    # The generator takes noise as input and generates imgs
    z = Input(shape=(latent_dim,))
    img = generator(z)

    # For the combined model we will only train the generator
    # The discriminator takes generated images as input and determines validity
    validity = discriminator.predict(K.eval(img))


    # The combined model  (stacked generator and discriminator)
    # Trains the generator to fool the discriminator
     combined = Model(z, validity)
     combined.compile(loss='binary_crossentropy',optimizer=optimizer)
     return combined

0 个答案:

没有答案