Changeset f4c5a95 for src/ai/conv1d.c
 Timestamp:
 Dec 29, 2021, 5:51:45 PM (3 years ago)
 Branches:
 feature/cnn, feature/crepe
 Children:
 97985d4
 Parents:
 b508ba6
 gitauthor:
 Paul Brossier <piem@piem.org> (01/01/19 18:39:26)
 gitcommitter:
 Paul Brossier <piem@piem.org> (12/29/21 17:51:45)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/ai/conv1d.c
rb508ba6 rf4c5a95 117 117 case PAD_SAME: 118 118 // compute output shape 119 output_shape[0] = (uint_t)CEIL(input_tensor> dims[0]119 output_shape[0] = (uint_t)CEIL(input_tensor>shape[0] 120 120 / (smpl_t)c>stride_shape); 121 121 122 122 uint_t padding_shape; // total amount of padding 123 123 padding_shape = (output_shape[0]  1) * c>stride_shape + 124 c>kernel_shape  input_tensor> dims[0];124 c>kernel_shape  input_tensor>shape[0]; 125 125 126 126 padding_start = FLOOR(padding_shape / 2); 127 127 break; 128 128 case PAD_VALID: 129 output_shape[0] = (input_tensor> dims[0]  c>kernel_shape + 1)129 output_shape[0] = (input_tensor>shape[0]  c>kernel_shape + 1) 130 130 / c>stride_shape; 131 131 … … 139 139 } 140 140 141 uint_t kernel_ dims[3];142 kernel_ dims[0] = c>kernel_shape; // filter length143 kernel_ dims[1] = input_tensor>dims[1]; // channels144 kernel_ dims[2] = c>n_filters; // outputs141 uint_t kernel_shape[3]; 142 kernel_shape[0] = c>kernel_shape; // filter length 143 kernel_shape[1] = input_tensor>shape[1]; // channels 144 kernel_shape[2] = c>n_filters; // outputs 145 145 146 146 if (c>kernel) del_aubio_tensor(c>kernel); 147 147 if (c>bias) del_fvec(c>bias); 148 148 149 c>kernel = new_aubio_tensor(3, kernel_ dims);149 c>kernel = new_aubio_tensor(3, kernel_shape); 150 150 if (!c>kernel) return AUBIO_FAIL; 151 151 c>bias = new_fvec(c>n_filters); … … 170 170 // print some info 171 171 AUBIO_ASSERT(c); 172 uint_t n_params = (c>kernel> dims[0] * c>kernel>dims[2] + 1)173 * c>kernel> dims[1] * c>kernel>dims[3];172 uint_t n_params = (c>kernel>shape[0] * c>kernel>shape[2] + 1) 173 * c>kernel>shape[1] * c>kernel>shape[3]; 174 174 AUBIO_DBG("conv1d: input (%d, %d) ¤ conv1d (%d, %d, %d)" 175 175 " : (%d, %d)" 176 176 " (%d params, stride (%d), pad_start [%d])\n", 177 input_tensor> dims[0], input_tensor>dims[1],178 c>kernel> dims[0], c>kernel>dims[1], c>kernel>dims[2],177 input_tensor>shape[0], input_tensor>shape[1], 178 c>kernel>shape[0], c>kernel>shape[1], c>kernel>shape[2], 179 179 c>output_shape[0], c>output_shape[1], 180 180 n_params, … … 196 196 197 197 // check we have as many filters as expected activation outputs 198 if (activations> dims[1] != c>n_filters) return AUBIO_FAIL;199 if (activations> dims[1] != c>kernel>dims[2]) return AUBIO_FAIL;200 if (input_tensor> dims[1] != c>kernel>dims[1]) return AUBIO_FAIL;198 if (activations>shape[1] != c>n_filters) return AUBIO_FAIL; 199 if (activations>shape[1] != c>kernel>shape[2]) return AUBIO_FAIL; 200 if (input_tensor>shape[1] != c>kernel>shape[1]) return AUBIO_FAIL; 201 201 202 202 // check tensor activations has the expected sizes 203 if (c>output_shape[0] != activations> dims[0]) return AUBIO_FAIL;204 if (c>output_shape[1] != activations> dims[1]) return AUBIO_FAIL;203 if (c>output_shape[0] != activations>shape[0]) return AUBIO_FAIL; 204 if (c>output_shape[1] != activations>shape[1]) return AUBIO_FAIL; 205 205 return AUBIO_OK; 206 206 } … … 223 223 224 224 // for each kernel filter k 225 for (i = 0; i < activations> dims[1]; i++) {225 for (i = 0; i < activations>shape[1]; i++) { 226 226 // get bias 227 227 bias = c>bias>data[i]; 228 228 stride_a = 0; // k * c>stride_shape 229 229 // for each output 230 for (j = 0; j < activations> dims[0]; j++) {230 for (j = 0; j < activations>shape[0]; j++) { 231 231 // reset output 232 232 acc = 0; … … 234 234 for (a = 0; a < c>kernel_shape; a++) { 235 235 x = stride_a + a  c>padding_start; 236 if ((x > 1) && (x < (sint_t)input_tensor> dims[0])) {236 if ((x > 1) && (x < (sint_t)input_tensor>shape[0])) { 237 237 kk = 0; 238 238 // for each input channel 239 for (k = 0; k < input_tensor> dims[1]; k++) {239 for (k = 0; k < input_tensor>shape[1]; k++) { 240 240 // get kernel weight 241 241 w = c>kernel>data[a][kk + i]; … … 243 243 s = input_tensor>data[x][k]; 244 244 acc += w * s; 245 kk += c>kernel> dims[2];245 kk += c>kernel>shape[2]; 246 246 } 247 247 }
Note: See TracChangeset
for help on using the changeset viewer.