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