tensorflow2 学习笔记(一) 前向传播

前向传播

前向传播 ,Y=aW+b, 并且输出y的概率。

import tensorflow as tf

a= tf.constant([[5.8, 4.0, 1.2, 0.2]])  # 5.8,4.0,1.2,0.2(0)
w = 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]])
b = tf.constant([2.52, -3.1, 5.62])
y = tf.matmul(a, w) + b1
print("x1.shape:", x.shape)
print("w1.shape:", w.shape)
print("b1.shape:", b.shape)
print("y.shape:", y.shape)
print("y:", y)
#####以下代码可将输出结果y转化为概率值#####
y_dim = tf.squeeze(y)  # 去掉y中纬度1(观察y_dim与 y 效果对比)
y_pro = tf.nn.softmax(y_dim)  # 使y_dim符合概率分布,输出为概率值了
print("y_dim:", y_dim)
print("y_pro:", y_pro)

这里:
Softmax的含义:Softmax简单的说就是把一个N*1的向量归一化为(0,1)之间的值,由于其中采用指数运算,使得向量中数值较大的量特征更加明显。

猜你喜欢

转载自blog.csdn.net/qq_40575024/article/details/105863565