这么久才进行了这个作业,其实只要专心地做不走神就能很快地完成作业。梯度检查很实用,需要注意的是在用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)
这里的逗号后面的下划线是什么意思呢,百度了一下也没有解决。