tf.nn.softmax 分類


tf.nn.softmax(logits,axis=None,name=None,dim=None)
參數:
logits:一個非空的Tensor。必須是下列類型之一:half, float32,float64
axis:將在其上執行維度softmax。默認值為-1,表示最后一個維度
name:操作的名稱(可選)
dim:axis的已棄用的別名

返回:
一個Tensor,與logits具有相同的類型和shape

sample

import tensorflow as tf

#tf.enable_eager_execution()
tf.compat.v1.enable_eager_execution()

ones = tf.ones(shape=[2,3])
print(ones)

temp1 = tf.nn.softmax(ones,axis=0) # 列
print(temp1)

temp2 = tf.nn.softmax(ones,axis=1) # 行
print(temp2)

output

tf.Tensor(
[[1. 1. 1.]
 [1. 1. 1.]], shape=(2, 3), dtype=float32)
tf.Tensor(
[[0.5 0.5 0.5]
 [0.5 0.5 0.5]], shape=(2, 3), dtype=float32)
tf.Tensor(
[[0.33333334 0.33333334 0.33333334]
 [0.33333334 0.33333334 0.33333334]], shape=(2, 3), dtype=float32)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM