Download presentation
Presentation is loading. Please wait.
1
Gradient Checks for ANN
Yujia Bao Mar 7, 2017
2
Finite Difference Let π(π₯) be any differentiable function, we can approximate its derivative by dπ(π₯) dπ₯ = π π₯+π βπ(π₯βπ) 2π +π( π 2 ) for some very small number π.
3
How to compare the numerical gradient with the analytic gradient?
4
Relative Error Let π π β² be the numerical gradient calculated using finite difference, and π π β² be the analytic gradient calculated using back prop. Define the relative error πππππ= π π β² β π π β² max π π β² , π π β² , πππ ππππ
5
Relative Error πππππ> 10 β4 usually means the analytic gradient is wrong. πππππ< 10 β4 is fine for sigmoid activation (including logistic, tanh, softmax). But if you are using (leaky) ReLU, then 10 β4 might be too large. πππππ< 10 β7 means your analytic gradient is correct.
6
Debugging Procedure Goal: Check the gradient for a single weight π€ is computed correctly. Given: One example (Input features with a label) Forward prop and Backward prop to get the gradient for π€. Let π€βπ€+π (I usually choose π= 10 β5 ). Forward prop to get the output, and then compute the loss. Let π€βπ€β2π (Now π€ is π€ ππππππ βπ). Check the relative error. Recover the origin weight by π€βπ€+π.
7
Debugging Procedure Suppose our network has the following structure:
Input -> Conv1 -> Pool1 -> Conv2 -> Pool2 -> ReLU -> Output If the gradients from Input to Conv1 are correct, then we are done! Otherwise, we check the gradients from Pool1 to Conv2 (since there is no weights from Conv1 to Pool1). If it is correct, then this means there are some bugs in our Back prop code from Pool1 to Input. And so onβ¦
8
Thanks.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.