Commit ceb6a119 authored by Davis King's avatar Davis King

Fixed a bug in the cuDNN binding that on rare occasions caused NaN outputs from

batch normalization.  The running mean and variance need to be initialized when
calling cuDNN, even if the averaging factor is 1.  I don't think this was the
case prior to cuDNN v5, but it certainly is the case now.  This patch fixes
this.
parent 98da589f
......@@ -445,6 +445,14 @@ namespace dlib
invstds.copy_size(means);
running_means.copy_size(means);
running_variances.copy_size(means);
// cuDNN requires that running_means and running_variances be initialized to
// some valid float values even if the averaging factor would have ignored
// them.
if (averaging_factor == 1)
{
running_means = 0;
running_variances = 1;
}
CHECK_CUDNN(cudnnBatchNormalizationForwardTraining(
context(),
......@@ -627,6 +635,14 @@ namespace dlib
invstds.copy_size(means);
running_means.copy_size(means);
running_variances.copy_size(means);
// cuDNN requires that running_means and running_variances be initialized to
// some valid float values even if the averaging factor would have ignored
// them.
if (averaging_factor == 1)
{
running_means = 0;
running_variances = 1;
}
CHECK_CUDNN(cudnnBatchNormalizationForwardTraining(
context(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment