这一周的initialize和regularation代码方面延续了course的内容,对于权重初始化和正则化理论部分需要研究花书。
问题一:在gradient check方面,遇到了
这个问题在于,数据类型不一致。出现问题的点在
def dictionart_to_vector(parameters):
count = 0
for key in ['W1','b1','W2','b2','W3','b3']:
new_vector = parameters[key].reshape(-1,1)
if count == 0:
theta=new_vector
else:
theta=np.concatenate((theta,new_vector),axis=0)
count+=1
return theta
count在else里,使得theta只有b3的维度。
此外,在计算theta+的时候,没有将theta从向量转化为前向传播后Wi,bi(i为隐含层 层数)维度也会显示这种错误
问题二,gradient check后,梯度不正常,为4.0+而不是吴恩达大佬说的<=1e-7
这次的问题在于
def dictionary_to_vector(parameters):
count = 0
for key in ['W1','b1','W2','b2','W3','b3']:
new_vector = parameters[key].reshape(-1)
if count == 0:
theta=new_vector
else:
theta=np.concatenate((theta,new_vector),axis=0)
count+=1
return theta
将wi,bi转化成向量的时候reshape成了(-1).跟标准答案中reshape(-1,1)的区别在于:
图1.reshape(-1)
图2.reshape(-1,1)
对比可以看出:图一中shape为1,图二为2.因为W属于是np.random.randn