Tensorflow 如何将张量传递给model.predict
我定义了一个函数,其中生成器和鉴别器都是两个Keras模型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
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呢