当前位置:网站首页>The softmax function is used in TF;

The softmax function is used in TF;

2022-08-11 07:51:00 phac123

简介

在这里插入图片描述

代码


import tensorflow as tf

x1 = tf.constant([[5.8, 4.0, 1.2, 0.2]])  # 5.8,4.0,1.2,0.2(0)
w1 = tf.constant([[-0.8, -0.34, -1.4],
                  [0.6, 1.3, 0.25],
                  [0.5, 1.45, 0.9],
                  [0.65, 0.7, -1.2]])
b1 = tf.constant([2.52, -3.1, 5.62])
y = tf.matmul(x1, w1) + b1
print("x1.shape:", x1.shape)
print("w1.shape:", w1.shape)
print("b1.shape:", b1.shape)
print("y.shape:", y.shape)
print("y:", y)

#####The following code will output the resultyConvert to probability value#####
y_dim = tf.squeeze(y)  # 去掉y中纬度1(观察y_dim与 y 效果对比)
y_pro = tf.nn.softmax(y_dim)  # 使y_dim符合概率分布,The output is a probability value
print("y_dim:", y_dim)
print("y_pro:", y_pro)
原网站

版权声明
本文为[phac123]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110645026870.html