![](/img/trans.png)
[英]Syntax for creating layers in keras functional api for tensorflow2.0 documentation
[英]Tensorflow2.0 Keras: Is dropout disabled during testing by default?
我想知道是否在以下模型中,當我調用model.evaluate(...).
時將禁用輟學model.evaluate(...).
layers = [tf.keras.layers.Dense(size, activation='relu')
for size in (20, 40, 20)]
layers.insert(1, tf.keras.layers.Dropout(0.2))
layers.append(tf.keras.layers.Dense(1, activation="sigmoid"))
model = tf.keras.models.Sequential(layers)
model.compile(
optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),
loss=tf.keras.losses.BinaryCrossentropy())
model.fit(...)
model.evaluate(...) #==> will dropout be deactivated here?
是的,推斷時始終禁用輟學( evaluate
/ predict
)。
根據文檔:
Call arguments:
inputs: Input tensor (of any rank).
training: Python boolean indicating whether the layer should behave in
training mode (adding dropout) or in inference mode (doing nothing).
"""
因此,是的,測試時禁用了輟學,這在邏輯上是正確的。 SpatialDropout也是如此。
請找到以下文檔的鏈接。 https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/layers/Dropout
Tensorflow Keras API使用學習階段標志來標識我們是培訓還是測試。 學習階段標志是布爾張量(0 =測試,1 =火車),將其作為輸入傳遞給在火車時間和測試時間使用不同行為的任何Keras函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.