辍学前向传播

时间:2017-09-13 19:33:10

标签: neural-network conv-neural-network

我正在通过Andrew Ng新的深度学习课程。

我们正在实施以下代码:

def forward_propagation_with_dropout(X,参数,keep_prob = 0.5):

np.random.seed(1)

# retrieve parameters
W1 = parameters["W1"]
b1 = parameters["b1"]
W2 = parameters["W2"]
b2 = parameters["b2"]
W3 = parameters["W3"]
b3 = parameters["b3"]

# LINEAR -> RELU -> LINEAR -> RELU -> LINEAR -> SIGMOID
Z1 = np.dot(W1, X) + b1
A1 = relu(Z1)
### START CODE HERE ### (approx. 4 lines)         # Steps 1-4 below correspond to the Steps 1-4 described above. 
D1 = np.random.rand(*A1.shape)                                # Step 1: initialize matrix D1 = np.random.rand(..., ...)
D1 = (D1 < 0.5)                                        # Step 2: convert entries of D1 to 0 or 1 (using keep_prob as the threshold)
A1 = A1*D1                                        # Step 3: shut down some neurons of A1
A1 = A1 / keep_prob                                         # Step 4: scale the value of neurons that haven't been shut down
### END CODE HERE ###
Z2 = np.dot(W2, A1) + b2
A2 = relu(Z2)
### START CODE HERE ### (approx. 4 lines)
D2 =np.random.rand(*A2.shape)                                        # Step 1: initialize matrix D2 = np.random.rand(..., ...)
D2 = (D2 < 0.5)                                        # Step 2: convert entries of D2 to 0 or 1 (using keep_prob as the threshold)
A2 = A2 * D2                                         # Step 3: shut down some neurons of A2
A2 = A2 / keep_prob                                         # Step 4: scale the value of neurons that haven't been shut down
### END CODE HERE ###
Z3 = np.dot(W3, A2) + b3
A3 = sigmoid(Z3)

cache = (Z1, D1, A1, W1, b1, Z2, D2, A2, W2, b2, Z3, A3, W3, b3)

return A3, cache

X_assess,parameters = forward_propagation_with_dropout_test_case()

A3,cache = forward_propagation_with_dropout(X_assess,parameters,keep_prob = 0.7) 打印(&#34; A3 =&#34; + str(A3))

我的输出是:

A3 = [[0.36974721 0.49683389 0.04565099 0.49683389 0.36974721]]

预期输出应为:

A3 [[0.36974721 0.00305176 0.04565099 0.49683389 0.36974721]]

只有一个数字差异。有什么想法吗?

我认为这是因为我塑造了D1和D2的方式。

1 个答案:

答案 0 :(得分:3)

我认为这是因为你把D1 =(D1 <0.5)和D2 =(D2 <0.5)
你需要把#34; keep_prob&#34;而不是0.5