Changeset 6e4ef27 for src


Ignore:
Timestamp:
Jan 1, 2019, 6:39:26 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn_org, feature/crepe_org
Children:
60c9db0
Parents:
5010e61
Message:

[conv1d] update to new tensor members

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ai/conv1d.c

    r5010e61 r6e4ef27  
    117117    case PAD_SAME:
    118118      // 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]
    120120          / (smpl_t)c->stride_shape);
    121121
    122122      uint_t padding_shape;  // total amount of padding
    123123      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];
    125125
    126126      padding_start = FLOOR(padding_shape / 2);
    127127      break;
    128128    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)
    130130        / c->stride_shape;
    131131
     
    139139  }
    140140
    141   uint_t kernel_dims[3];
    142   kernel_dims[0] = c->kernel_shape; // filter length
    143   kernel_dims[1] = input_tensor->dims[1]; // channels
    144   kernel_dims[2] = c->n_filters; // outputs
     141  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
    145145
    146146  if (c->kernel) del_aubio_tensor(c->kernel);
    147147  if (c->bias) del_fvec(c->bias);
    148148
    149   c->kernel = new_aubio_tensor(3, kernel_dims);
     149  c->kernel = new_aubio_tensor(3, kernel_shape);
    150150  if (!c->kernel) return AUBIO_FAIL;
    151151  c->bias = new_fvec(c->n_filters);
     
    170170  // print some info
    171171  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];
    174174  AUBIO_DBG("conv1d: input (%d, %d) ¤ conv1d (%d, %d, %d)"
    175175      " : (%d, %d)"
    176176      " (%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],
    179179    c->output_shape[0], c->output_shape[1],
    180180    n_params,
     
    196196
    197197  // 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;
    201201
    202202  // 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;
    205205  return AUBIO_OK;
    206206}
     
    223223
    224224  // for each kernel filter k
    225   for (i = 0; i < activations->dims[1]; i++) {
     225  for (i = 0; i < activations->shape[1]; i++) {
    226226    // get bias
    227227    bias = c->bias->data[i];
    228228    stride_a = 0; // k * c->stride_shape
    229229    // for each output
    230     for (j = 0; j < activations->dims[0]; j++) {
     230    for (j = 0; j < activations->shape[0]; j++) {
    231231      // reset output
    232232      acc = 0;
     
    234234      for (a = 0; a < c->kernel_shape; a++) {
    235235        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])) {
    237237          kk = 0;
    238238          // for each input channel
    239           for (k = 0; k < input_tensor->dims[1]; k++) {
     239          for (k = 0; k < input_tensor->shape[1]; k++) {
    240240            // get kernel weight
    241241            w = c->kernel->data[a][kk + i];
     
    243243            s = input_tensor->data[x][k];
    244244            acc += w * s;
    245             kk += c->kernel->dims[2];
     245            kk += c->kernel->shape[2];
    246246          }
    247247        }
Note: See TracChangeset for help on using the changeset viewer.