# 1.14 梯度检验应用的注意事项（Gradient Checking Implementation Notes）

在进行梯度检验的过程中有几点需要注意的地方：

* 不要在训练中使用梯度检验而仅仅在调试时使用。计算所有$$i$$值的$$d\theta\_{approx}\[i]$$是一个非常漫长的计算过程，为了实施梯度下降，必须使用$$W$$和$$b$$ backprop来计算$$d\theta$$**，**&#x5E76;使用backprop来计算导数，所以只有调试的时候才会计算它，来确认数值是否接近$$d\theta$$。完成后要关闭梯度检验。别在每一次进行梯度下降迭代的时候都运行梯度检验，因为太慢了
* 如果$$d\theta\_{approx}$$与$$d\theta$$差距很大, 应检查不同的$$i$$值,看看哪些$$d\theta\_{approx}$$的值与$$d\theta$$的值差距最大
* 进行梯度检验时,如果使用了正则化,注意不要忽略正则化项，计算近似梯度的时候要包括进去
* 梯度检验不能与随机失活(dropout) 一起使用,因为在每一次的迭代中,随机失活(dropout)将随机消除隐藏层单元的不同子集,在使用随机失活(dropout) 进行梯度下降的过程中并不存在一个容易计算的代价函数$$J$$,随机失活(dropout)可以被视为对代价函数的优化, 但是这个代价函数的定义是在每一次迭代中对所有非常大的可消除节点集进行求和,所以这个代价函数是很难计算的,只需要对代价函数进行抽样,在那些使用随机失活(dropout)的集合中每次消除不同的随机集合,所以使用梯度检验来检查包含了随机失活(dropout)的运算是很困难的,可以把keep-prob和dropout设为1.0,然后打开dropout。梯度检查时关闭dropout，检查完毕后再打开dropout。关掉随机失活(dropout) 使用梯度检验来检查算法，在没有dropout的情况下至少是正确的 然后再打开dropout
* 在随机初始化的时候运行梯度检验,然后训练网络一段时间,$$w$$和$$b$$ 将会在0附近摇摆一段时间,即很小的随机初始值,在进行几次训练的迭代后再运行梯度检验。**（不常用）**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-er-men-ke-gai-shan-shen-ceng-shen-jing-wang-luo-chao-can-shu-tiao-shi-zheng-ze-hua-yi-ji-you-hua/improving-deep-neural-networks/practical-aspects-of-deep-learning/114-ti-du-jian-yan-ying-yong-de-zhu-yi-shi-xiang-ff08-gradient-checking-implementation-notes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
