Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 如何将张量传递给model.predict_Tensorflow_Keras - Fatal编程技术网

Tensorflow 如何将张量传递给model.predict

Tensorflow 如何将张量传递给model.predict,tensorflow,keras,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

我定义了一个函数,其中生成器和鉴别器都是两个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

可以完全指定张量的形状。如果您提供更多信息,可能会澄清您的问题。为什么需要第二个代码段?第一个应该很好。我知道第一个实现是正确的。我想扩展我的知识,寻找其他可能的解决方案。我们可以看到,鉴别器模型只是关于它的推理模式,为什么不使用model.predict呢