Skip to content
Snippets Groups Projects
Commit 90f53c3d authored by Gallas Gaye's avatar Gallas Gaye
Browse files

fix: Only allow possitive value of variances in batchnorm

parent 0ee3b761
No related branches found
No related tags found
2 merge requests!39Update 0.2.1 -> 0.3.0,!36feat: Add missing operators for AIDGE model benchmarking
......@@ -26,7 +26,14 @@ void batchnorm_forward (
const Rescaling_T& __restrict rescaling)
{
for (unsigned int output = 0; output < NB_OUTPUTS; ++output) {
const Output_T var = sqrt(variances[output] + epsilon);
// If the variance is 0, we need to avoid division by 0
const Output_T var = epsilon;
// If the variance is negative, we need to set it to 0 to avoid a sqrt of a negative number
if (variances[output] > 0.0)
{
var = sqrt(variances[output] + epsilon);
}
for (int oy = 0; oy < OUTPUTS_HEIGHT; ++oy) {
for (int ox = 0; ox < OUTPUTS_WIDTH; ++ox) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment