从零开始的机器学习之路(十七)---- Practice Lab 4 Neural Networks for Handwritten Digit Recognition, Multiclass
【代码】从零开始的机器学习之路(十七)---- Practice Lab 4 Neural Networks for Handwritten Digit Recognition, Multiclass。
·
文章目录
前引
最后一个lab 写完就睡觉
从零开始的机器学习之路(十七)---- Practice Lab 4 Neural Networks for Handwritten Digit Recognition, Multiclass
1、Neural Network Recognize Digits 0-9 Start
识别0-9的图片 简单的做一下这个lab


2、Practice 1(my_softmax)
# UNQ_C1
# GRADED CELL: my_softmax
def my_softmax(z):
""" Softmax converts a vector of values to a probability distribution.
Args:
z (ndarray (N,)) : input data, N features
Returns:
a (ndarray (N,)) : softmax of z
"""
### START CODE HERE ###
ez = np.exp(z)
a = ez / np.sum(ez)
### END CODE HERE ###
return a

3、Practice 2(model Sequential)
# UNQ_C2
# GRADED CELL: Sequential model
tf.random.set_seed(1234) # for consistent results
model = Sequential(
[
### START CODE HERE ###
tf.keras.Input(shape=(400,)),
Dense(units=25, activation='relu', name = 'layer1'),
Dense(units=15, activation='relu', name = 'layer2'),
Dense(units=10, activation='linear', name = 'layer3'),
### END CODE HERE ###
], name = "my_model"
)
model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True))

4、model fit


5、predict
下面的图则是实际predict实现 看最下方的图 可以发现我们实际已经实现了


更多推荐
所有评论(0)