Changeset 05808d5
 Timestamp:
 Dec 29, 2021, 5:51:59 PM (3 weeks ago)
 Branches:
 feature/crepe
 Children:
 9b05ea9
 Parents:
 49688ef
 gitauthor:
 Paul Brossier <piem@piem.org> (01/17/19 23:50:44)
 gitcommitter:
 Paul Brossier <piem@piem.org> (12/29/21 17:51:59)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/ai/batchnorm.c
r49688ef r05808d5 79 79 aubio_tensor_t *input, uint_t *shape) 80 80 { 81 uint_t i; 82 81 83 AUBIO_ASSERT(c && input && shape); 84 AUBIO_ASSERT(c>n_outputs == input>shape[input>ndim  1]); 82 85 83 shape[0] = input>shape[0];84 shape[1] = input>shape[1];85 shape[2] = input>shape[2];86 for (i = 0; i < input>ndim; i++) { 87 shape[i] = input>shape[i]; 88 } 86 89 87 90 aubio_batchnorm_debug(c, input); … … 93 96 aubio_tensor_t *activations) 94 97 { 95 uint_t i, j, k;96 uint_t jj;97 98 smpl_t s; 99 uint_t i, j; 100 uint_t ii = 0; 101 uint_t length = activations>shape[activations>ndim  1]; 102 uint_t height = activations>size / length; 103 98 104 AUBIO_ASSERT(c); 99 105 AUBIO_ASSERT_EQUAL_SHAPE(input_tensor, activations); 100 if (input_tensor>ndim == 3) { 101 for (i = 0; i < activations>shape[0]; i++) { 102 jj = 0; 103 for (j = 0; j < activations>shape[1]; j++) { 104 for (k = 0; k < activations>shape[2]; k++) { 105 s = input_tensor>data[i][jj + k]; 106 s = c>moving_mean>data[k]; 107 s *= c>gamma>data[k]; 108 s /= SQRT(c>moving_variance>data[k] + 1.e4); 109 s += c>beta>data[k]; 110 activations>data[i][jj + k] = s; 111 } 112 jj += activations>shape[2]; 113 } 106 AUBIO_ASSERT(length == c>n_outputs); 107 AUBIO_ASSERT(height * length == activations>size); 108 109 for (i = 0; i < height; i++) { 110 for (j = 0; j < length; j++) { 111 s = input_tensor>buffer[ii + j]; 112 s = c>moving_mean>data[j]; 113 s *= c>gamma>data[j]; 114 s /= SQRT(c>moving_variance>data[j] + 1.e4); 115 s += c>beta>data[j]; 116 activations>buffer[ii + j] = s; 114 117 } 115 } else if (input_tensor>ndim == 2) { 116 for (i = 0; i < activations>shape[0]; i++) { 117 for (j = 0; j < activations>shape[1]; j++) { 118 s = input_tensor>data[i][j]; 119 s = c>moving_mean>data[j]; 120 s *= c>gamma>data[j]; 121 s /= SQRT(c>moving_variance>data[j] + 1.e4); 122 s += c>beta>data[j]; 123 activations>data[i][j] = s; 124 } 125 } 118 ii += length; 126 119 } 127 120 }
Note: See TracChangeset
for help on using the changeset viewer.