RNNCell 包裝器,可確保將單元輸入添加到輸出中。
繼承自:Module
用法
tf.nn.RNNCellResidualWrapper(
*args, **kwargs
)參數
-
cellRNNCell的一個實例。 -
residual_fn(可選)將原始單元輸入和原始單元輸出映射到殘差網絡的實際單元輸出的函數。默認調用nest.map_structure on (lambda i, o:i + o),輸入和輸出。 -
**kwargs基礎層的關鍵字參數字典。
屬性
-
activity_regularizer該層輸出的可選正則化函數。 -
compute_dtype層計算的 dtype。這相當於
Layer.dtype_policy.compute_dtype。除非使用混合精度,否則這與Layer.dtype相同,即權重的 dtype。層會自動將其輸入轉換為計算 dtype,這會導致計算和輸出也位於計算 dtype 中。這是由
Layer.call中的基礎層類完成的,因此如果實現自己的層,則不必插入這些轉換。當
compute_dtype為 float16 或 bfloat16 以保持數值穩定性時,層通常會以更高的精度執行某些內部計算。在這種情況下,輸出通常仍然是 float16 或 bfloat16。 -
dtype層權重的 dtype。這相當於
Layer.dtype_policy.variable_dtype。除非使用混合精度,否則這與Layer.compute_dtype相同,即圖層計算的 dtype。 -
dtype_policy與該層關聯的 dtype 策略。這是
tf.keras.mixed_precision.Policy的一個實例。 -
dynamic圖層是否動態(eager-only);在構造函數中設置。 -
input檢索層的輸入張量。僅當該層隻有一個輸入時才適用,即如果它連接到一個傳入層。
-
input_specInputSpec說明該層輸入格式的實例。創建圖層子類時,可以設置
self.input_spec以使圖層在調用時運行輸入兼容性檢查。考慮Conv2D層:它隻能在秩為 4 的單個輸入張量上調用。因此,您可以在__init__()中設置:self.input_spec = tf.keras.layers.InputSpec(ndim=4)現在,如果您嘗試在不是 4 級的輸入上調用圖層(例如,形狀為
(2,)的輸入,它將引發 nicely-formatted 錯誤:ValueError:Input 0 of layer conv2d is incompatible with the layer: expected ndim=4, found ndim=1. Full shape received:[2]可以通過
input_spec指定的輸入檢查包括:- 結構(例如,單個輸入、2 個輸入的列表等)
- Shape
- 排名(ndim)
- Dtype
有關詳細信息,請參閱
tf.keras.layers.InputSpec。 -
losses使用添加的損失列表add_loss()API。訪問此屬性時會創建變量正則化張量,因此非常安全:訪問
tf.GradientTape下的losses會將梯度傳播回相應的變量。class MyLayer(tf.keras.layers.Layer): def call(self, inputs): self.add_loss(tf.abs(tf.reduce_mean(inputs))) return inputs l = MyLayer() l(np.ones((10, 1))) l.losses [1.0]inputs = tf.keras.Input(shape=(10,)) x = tf.keras.layers.Dense(10)(inputs) outputs = tf.keras.layers.Dense(1)(x) model = tf.keras.Model(inputs, outputs) # Activity regularization. len(model.losses) 0 model.add_loss(tf.abs(tf.reduce_mean(x))) len(model.losses) 1inputs = tf.keras.Input(shape=(10,)) d = tf.keras.layers.Dense(10, kernel_initializer='ones') x = d(inputs) outputs = tf.keras.layers.Dense(1)(x) model = tf.keras.Model(inputs, outputs) # Weight regularization. model.add_loss(lambda:tf.reduce_mean(d.kernel)) model.losses [<tf.Tensor:shape=(), dtype=float32, numpy=1.0>] -
metrics使用添加的指標列表add_metric()API。input = tf.keras.layers.Input(shape=(3,)) d = tf.keras.layers.Dense(2) output = d(input) d.add_metric(tf.reduce_max(output), name='max') d.add_metric(tf.reduce_min(output), name='min') [m.name for m in d.metrics] ['max', 'min'] -
non_trainable_weights該層跟蹤的所有不可訓練權重的列表。不可訓練的權重在訓練期間不會更新。它們預計將在
call()中手動更新。 -
output檢索層的輸出張量。僅當該層隻有一個輸出時才適用,即如果它連接到一個傳入層。
-
output_size -
state_size -
supports_masking該層是否支持使用compute_mask計算掩碼。 -
trainable -
trainable_weights該層跟蹤的所有可訓練權重的列表。可訓練權重在訓練期間通過梯度下降進行更新。
-
variable_dtypeLayer.dtype的別名,權重的 dtype。 -
weights返回所有層變量/權重的列表。
相關用法
- Python tf.nn.RNNCellResidualWrapper.set_weights用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.add_loss用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.get_weights用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.add_metric用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.set_weights用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.get_weights用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper.set_weights用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.add_loss用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper.add_metric用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.add_metric用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper.add_loss用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper.get_weights用法及代碼示例
- Python tf.nn.embedding_lookup_sparse用法及代碼示例
- Python tf.nn.dropout用法及代碼示例
- Python tf.nn.gelu用法及代碼示例
- Python tf.nn.embedding_lookup用法及代碼示例
- Python tf.nn.local_response_normalization用法及代碼示例
- Python tf.nn.scale_regularization_loss用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.nn.RNNCellResidualWrapper。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
