DC - 生成逆境网络。理解代码的问题

时间:2017-12-24 20:36:23

标签: python-3.x tensorflow machine-learning deep-learning conv-neural-network

这是解卷积 - 对话生成对抗网络(DC-GAN)的一部分代码

discriminator.trainable = False
ganInput = Input(shape=(100,))
# getting the output of the generator
# and then feeding it to the discriminator
# new model = D(G(input))
x = generator(ganInput)
ganOutput = discriminator(x)
gan = Model(input=ganInput, output=ganOutput)
gan.compile(loss='binary_crossentropy', optimizer=Adam())

我不明白行ganInput = Input(shape=(100,))的作用。 显然ganInput是一个变量,但Input是什么?这是一个功能吗? 如果Input是一个函数,那么ganInput包含什么?

然后将ganInput输入到生成器中,因为它是一个空变量(假设)它无关紧要。下一个ganOutput会捕获discriminator的输出。

然后出现了问题。我读到了Model API,但我完全不了解它的作用。

总结一下这些是我的问题:ganInput的作用是什么,Input在第二行是什么。什么是Model做什么,它是什么?

将Keras与TensorFlow后端一起使用 完整的源代码:https://github.com/yashk2810/DCGAN-Keras/blob/master/DCGAN.ipynb

请要求提供更多澄清/详细信息。如果您知道我的一个查询的答案,我会请求您回答它将是一个巨大的帮助。感谢

1 个答案:

答案 0 :(得分:0)

什么是输入:注意keras.layers的通配符导入。在上下文中,Inputkeras.layers.Input。通常,如果您看到一个未在Python中定义或显式导入的函数或类,它通过通配符导入到达那里,即

from keras.layers import *

这意味着将keras.layers的所有内容直接导入工作区。

什么是modelmodel对象本质上是与Keras建立神经网络的接口。

您可以在model docs或此model guide上阅读modelkeras.layers.Input,因为我对Keras不是很熟悉。

示例中的内容是将生成器和鉴别器定义为Sequential s。但是GAN模型比标准旧Sequential稍微复杂一些。作者通过将每次迭代所需的数据(在这种情况下,只是生成器的随机噪声 - ganInput)标记为keras.layers.Input来处理这一问题。然后,就像你说的那样,ganOutput捕获了鉴别器的输出。由于我们有两个不同的Sequential需要包装在一起,所以作者使用model API。