[英]Keras model building
I am coming from tensorflow learning more about keras and came across this notation. 我来自tensorflow,了解更多关于keras的知识,并遇到了这种表示法。 I looked in the documentation but couldn't find any examples.
我查看了文档,但找不到任何示例。 The syntax is when a function is followed with a variable in parenthesis.
语法是当函数后跟括号中的变量时。
model_input = Input(shape=input_shape)
z = model_input
z = Dropout(dropout_prob[0])(z) # Not sure what this means
The only idea I had is this may be a layer multiplication, but I am not sure thank you for your help. 我唯一的想法是这可能是一个图层乘法,但是我不确定谢谢您的帮助。
It's part of the Sequential model in Keras; 它是Keras中顺序模型的一部分; as it's stated in the doc here
因为它是在doc陈述这里
So following up your code (that is only a portion), first probably you imported 因此,跟进代码(仅是一部分),首先可能要导入
from keras.layers import Input, Dropout
Then in var "model_input" you return a tensor 然后在var“ model_input”中返回一个张量
model_input = Input(shape=input_shape)
And then a layer instance is callable on a tensor, and returns a tensor 然后可以在张量上调用图层实例,并返回张量
z = model_input
z = Dropout(dropout_prob[0])(z) # This returns another tensor
After that, for example, you can follow with a model like this: 之后,例如,您可以使用如下模型:
from keras.models import Model
model = Model(inputs=model_input, outputs=z)
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(data, labels) # starts training
So now, it is easy to reuse trained models: you can treat any model as if it were a layer, by calling it on a tensor, like this: 因此,现在可以轻松地重用经过训练的模型:您可以通过在张量上调用任何模型,将其视为层,就像这样:
x = Input(shape=(784,))
y = model(x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.