Skip to content

Commit f9c9903

Browse files
authored
Avoid NaN in feature normalization. (#2186)
1 parent f00066d commit f9c9903

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sherpa-onnx/csrc/offline-stream.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ static void ComputeMeanAndInvStd(const float *p, int32_t num_rows,
4949
(*mean)[i] = t;
5050

5151
float stddev = std::sqrt(sum_sq[i] / num_rows - t * t);
52+
53+
if (stddev != stddev) {
54+
stddev = 0;
55+
}
56+
5257
(*inv_stddev)[i] = 1.0f / (stddev + 1e-5f);
5358
}
5459
}

0 commit comments

Comments
 (0)