首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带Dropout的前向传播

带Dropout的前向传播
EN

Stack Overflow用户
提问于 2017-09-14 03:33:10
回答 1查看 1.6K关注 0票数 0

我正在通过Andrew Ng新的深度学习Coursera课程进行工作。

我们正在实现以下代码:

def forward_propagation_with_dropout(X,parameters,keep_prob = 0.5):

np.random.seed(1)

代码语言:javascript
复制
# 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 = forward_propagation_with_dropout_test_case()

A3,缓存= forward_propagation_with_dropout(X_assess,parameters,keep_prob = 0.7)打印("A3 =“+ 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的方式。

EN

回答 1

Stack Overflow用户

发布于 2017-09-27 01:35:50

我想是因为你把D1 = (D1 < 0.5)和D2 = (D2 < 0.5)

你需要把"keep_prob“而不是0.5

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46205516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档