擅长:python、mysql、java
<ol>
<li>在编译/拟合/评估之前,您应该首先描述模型。创建一个序列:第一层是输入层,接下来是一组中间层,然后是输出层</李>
</ol>
<p>比如你的例子:</p>
<pre><code>inputs = keras.Input(shape=(784,)) # input layer
dense = layers.Dense(64, activation="relu") # describe a dense layer
x = dense(inputs) # set x as a result of dense layer with inputs
x = layers.Dense(64, activation="relu")(x) # "update" x with next layer which has previous dense layer as input
outputs = layers.Dense(10)(x) # set your output
model = keras.Model(inputs=inputs, outputs=outputs, name="mnist_model") # incorporate all layers in a model
</code></pre>
<p>所以基本上Keras已经知道模型内部是什么</p>
<ol start=“2”>
<li>您正在考虑获取中间层的输出。这是迁移学习(当您使用预先训练的模型作为特征提取器时)或某些体系结构作为跳过连接时的常见原则。在这种情况下,您将获得多个输出。此外,根据模型用途,网络在模型末尾可以有多个输出。在您的示例中,它们仅用于演示目的,没有任何意义。看看更有意义的<a href="https://keras.io/api/applications/#extract-features-with-vgg16" rel="nofollow noreferrer">feature extraction</a></li>
</ol>