Skip to content

Commit

Permalink
Precompute part of expensive multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
bouncyphoton committed Aug 18, 2020
1 parent 05dee78 commit 6a2d50f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,12 +1240,14 @@ void fuse_conv_batchnorm(network net)
{
l->biases[f] = l->biases[f] - (double)l->scales[f] * l->rolling_mean[f] / (sqrt((double)l->rolling_variance[f] + .00001));

double precomputed = l->scales[f] / (sqrt((double)l->rolling_variance[f] + .00001));

const size_t filter_size = l->size*l->size*l->c / l->groups;
int i;
for (i = 0; i < filter_size; ++i) {
int w_index = f*filter_size + i;

l->weights[w_index] = (double)l->weights[w_index] * l->scales[f] / (sqrt((double)l->rolling_variance[f] + .00001));
l->weights[w_index] *= precomputed;
}
}

Expand Down

0 comments on commit 6a2d50f

Please sign in to comment.