完成了Gradient+Checking

理解与应用Gradient Checking
这篇博客分享了作者完成Gradient Checking作业的体会,强调专注能有效提高效率。作者指出,梯度检查在应用dropout前是必要的,以验证反向传播的正确性,但之后则不再适用。同时,作者提到了正在进行的英语竞赛练习,但由于事务繁多,进度受到影响,且提出对于一道题目中逗号后下划线含义的疑问。

这么久才进行了这个作业,其实只要专心地做不走神就能很快地完成作业。梯度检查很实用,需要注意的是在用dropout之前用梯度检查确保反向传播是正确的,用了dropout以后就不要梯度检查了。

把所有的theta转换成各个参数对应的:

# 向量theta分解为适用于计算的W1, b1, W2, b2, W3, b3
def vector_to_dictionary(theta):
    """
    Unroll all our parameters dictionary from a single vector satisfying our specific required shape.
    """
    parameters = {}
    parameters["W1"] = theta[:20].reshape((5,4))
    parameters["b1"] = theta[20:25].reshape((5,1))
    parameters["W2"] = theta[25:40].reshape((3,5))
    parameters["b2"] = theta[40:43].reshape((3,1))
    parameters["W3"] = theta[43:46].reshape((1,3))
    parameters["b3"] = theta[46:47].reshape((1,1))

    return parameters


# 向量theta分解为适用于计算的W1, b1, W2, b2, W3, b3
def gradients_to_vector(gradients):
    """
    Roll all our gradients dictionary into a single vector satisfying our specific required shape.
    """
    
    count = 0
    for key in ["dW1", "db1", "dW2", "db2", "dW3", "db3"]:
        # flatten parameter
        new_vector = np.reshape(gradients[key], (-1,1))
        
        if count == 0:
            theta = new_vector
        else:
            theta = np.concatenate((theta, new_vector), axis=0)
        count = count + 1

    return theta

英语竞赛的题做完了第二套,最近事情比较多计划总是被打乱。还是没有连贯的做一整套题,这样对做题速度的提升来说很不好。

有一个问题,

parameters_values, _ = dictionary_to_vector(parameters)

这里的逗号后面的下划线是什么意思呢,百度了一下也没有解决。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值