本博客记录学习龙书的学习历程:
gtitub :https://github.com/dragen1860/Deep-Learning-with-TensorFlow-book
向开源大神致敬!
1.感知机
2.全连接层
2.1 用张量方式实现全连接层,要求:输入为2个样本,784维特征值,输出维256个特征。激活函数使用relu函数。
# 创建 W,b 张量
x = tf.random.normal([2,784])
w1 = tf.Variable(tf.random.truncated_normal([784, 256], stddev=0.1))
b1 = tf.Variable(tf.zeros([256]))
# 线性变换
o1 = tf.matmul(x,w1) + b1
# 激活函数
o1 = tf.nn.relu(o1)
o1
运行,可见是一个(2,256)的输出。
2.2 使用层方式实现
x = tf.random.normal([4,28*28])
from tensorflow.keras import layers # 导入层模块
# 创建全连接层,指定输出节点数和激活函数
fc = layers.Dense(512, activation=tf.nn.relu)
h1 = fc(x) # 通过 fc 类实例完成一次全连接层的计算,返回输出张量
3.神经网络