Densely-connected圖層類。
用法
tf.compat.v1.layers.Dense(
units, activation=None, use_bias=True, kernel_initializer=None,
bias_initializer=tf.compat.v1.zeros_initializer(), kernel_regularizer=None,
bias_regularizer=None, activity_regularizer=None, kernel_constraint=None,
bias_constraint=None, trainable=True, name=None, **kwargs
)
參數
-
units
整數或長整數,輸出空間的維度。 -
activation
激活函數(可調用)。將其設置為 None 以保持線性激活。 -
use_bias
布爾值,圖層是否使用偏差。 -
kernel_initializer
權重矩陣的初始化函數。如果None
(默認),權重使用tf.compat.v1.get_variable
使用的默認初始化程序進行初始化。 -
bias_initializer
偏差的初始化函數。 -
kernel_regularizer
權重矩陣的正則化函數。 -
bias_regularizer
偏差的正則化函數。 -
activity_regularizer
輸出的正則化函數。 -
kernel_constraint
由Optimizer
更新後應用於內核的可選投影函數(例如,用於實現層權重的範數約束或值約束)。該函數必須將未投影變量作為輸入,並且必須返回投影變量(必須具有相同的形狀)。在進行異步分布式訓練時使用約束是不安全的。 -
bias_constraint
由Optimizer
更新後應用於偏差的可選投影函數。 -
trainable
布爾值,如果True
還將變量添加到圖形集合GraphKeys.TRAINABLE_VARIABLES
(請參見tf.Variable
)。 -
name
字符串,圖層的名稱。具有相同名稱的層將共享權重,但為了避免錯誤,我們需要在這種情況下重用=True。 -
_reuse
布爾值,是否重用前一層同名的權重。
屬性
-
graph
-
scope_name
遷移到 TF2
警告:這個 API 是為 TensorFlow v1 設計的。繼續閱讀有關如何從該 API 遷移到本機 TensorFlow v2 等效項的詳細信息。見TensorFlow v1 到 TensorFlow v2 遷移指南有關如何遷移其餘代碼的說明。
此 API 是一個遺留 api,僅與 Eager Execution 和 tf.function
兼容,如果您將其與 tf.compat.v1.keras.utils.track_tf1_style_variables
結合使用
請參閱遷移指南的 tf.layers 模型映射部分,了解如何在 TF2 中將 TensorFlow v1 模型與 Keras 一起使用。
對應的 TensorFlow v2 層是 tf.keras.layers.Dense
。
到原生 TF2 的結構映射
支持的參數均未更改名稱。
前:
dense = tf.compat.v1.layers.Dense(units=3)
後:
dense = tf.keras.layers.Dense(units=3)
該層實現操作:outputs = activation(inputs * kernel + bias)
其中 activation
是作為 activation
參數傳遞的激活函數(如果不是 None
),kernel
是該層創建的權重矩陣,而 bias
是層創建的偏置向量(僅當 use_bias
為 True
時)。
特性:
units
:Python 整數,輸出空間的維度。activation
:激活函數(可調用)。use_bias
:Boolean,圖層是否使用了偏差。kernel_initializer
: 內核矩陣的初始化器實例(或名稱)。bias_initializer
: 偏差的初始化器實例(或名稱)。kernel_regularizer
:內核矩陣的正則化器實例(可調用)bias_regularizer
: 偏差的正則化器實例(可調用)。activity_regularizer
:輸出的正則化器實例(可調用)kernel_constraint
:核矩陣的約束函數。bias_constraint
:偏差的約束函數。kernel
:權重矩陣(TensorFlow 變量或張量)。bias
:偏置向量,如果適用(TensorFlow 變量或張量)。
相關用法
- Python tf.compat.v1.layers.Dropout用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.layers.Conv3D用法及代碼示例
- Python tf.compat.v1.layers.dense用法及代碼示例
- Python tf.compat.v1.layers.AveragePooling3D用法及代碼示例
- Python tf.compat.v1.layers.Conv2DTranspose用法及代碼示例
- Python tf.compat.v1.layers.max_pooling3d用法及代碼示例
- Python tf.compat.v1.layers.average_pooling1d用法及代碼示例
- Python tf.compat.v1.layers.experimental.keras_style_scope用法及代碼示例
- Python tf.compat.v1.layers.flatten用法及代碼示例
- Python tf.compat.v1.layers.conv1d用法及代碼示例
- Python tf.compat.v1.layers.experimental.set_keras_style用法及代碼示例
- Python tf.compat.v1.layers.conv2d_transpose用法及代碼示例
- Python tf.compat.v1.layers.dropout用法及代碼示例
- Python tf.compat.v1.layers.batch_normalization用法及代碼示例
- Python tf.compat.v1.layers.average_pooling2d用法及代碼示例
- Python tf.compat.v1.layers.MaxPooling1D用法及代碼示例
- Python tf.compat.v1.layers.conv2d用法及代碼示例
- Python tf.compat.v1.layers.Conv2D用法及代碼示例
- Python tf.compat.v1.layers.AveragePooling1D用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.layers.Dense。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。