計算 softmax 激活。
用法
tf.compat.v1.math.softmax(
logits, axis=None, name=None, dim=None
)
參數
-
logits
非空Tensor
。必須是以下類型之一:half
,float32
,float64
。 -
axis
將在維度上執行 softmax。默認值為 -1,表示最後一個維度。 -
name
操作的名稱(可選)。
返回
-
一個
Tensor
。具有與logits
相同的類型和形狀。
拋出
-
InvalidArgumentError
如果logits
為空或axis
超出logits
的最後一個維度。
用於multi-class 預測。 softmax 生成的所有輸出的總和為 1。
此函數執行等效於
softmax = tf.exp(logits) / tf.reduce_sum(tf.exp(logits), axis)
示例用法:
softmax = tf.nn.softmax([-1, 0., 1.])
softmax
<tf.Tensor:shape=(3,), dtype=float32,
numpy=array([0.09003057, 0.24472848, 0.66524094], dtype=float32)>
sum(softmax)
<tf.Tensor:shape=(), dtype=float32, numpy=1.0>
相關用法
- Python tf.compat.v1.math.log_softmax用法及代碼示例
- Python tf.compat.v1.map_fn用法及代碼示例
- Python tf.compat.v1.make_template用法及代碼示例
- Python tf.compat.v1.mixed_precision.enable_mixed_precision_graph_rewrite用法及代碼示例
- Python tf.compat.v1.metrics.mean用法及代碼示例
- Python tf.compat.v1.multinomial用法及代碼示例
- Python tf.compat.v1.mixed_precision.MixedPrecisionLossScaleOptimizer用法及代碼示例
- Python tf.compat.v1.metrics.accuracy用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代碼示例
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.math.softmax。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。