前引


最后一个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实现 看最下方的图 可以发现我们实际已经实现了

在这里插入图片描述

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐