Changeset 689ba93


Ignore:
Timestamp:
Jan 18, 2019, 10:47:14 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/crepe_org
Children:
e75a48e
Parents:
3977b4f
Message:

[batchnorm] accepts any input size, allocate weights in get_output_shape

Location:
src/ai
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ai/batchnorm.c

    r3977b4f r689ba93  
    3535    aubio_tensor_t *input_tensor);
    3636
    37 aubio_batchnorm_t *new_aubio_batchnorm(uint_t n_outputs)
     37aubio_batchnorm_t *new_aubio_batchnorm(void)
    3838{
    3939  aubio_batchnorm_t *c = AUBIO_NEW(aubio_batchnorm_t);
    40 
    41   AUBIO_GOTO_FAILURE((sint_t)n_outputs > 0);
    42 
    43   c->n_outputs = n_outputs;
    44 
    45   c->gamma = new_fvec(n_outputs);
    46   c->beta = new_fvec(n_outputs);
    47   c->moving_mean = new_fvec(n_outputs);
    48   c->moving_variance = new_fvec(n_outputs);
    49 
    5040  return c;
    51 
     41#if 0 // no argument so no other possible failure
    5242failure:
    5343  del_aubio_batchnorm(c);
    5444  return NULL;
     45#endif
    5546}
    5647
    57 void del_aubio_batchnorm(aubio_batchnorm_t* c) {
     48static void aubio_batchnorm_reset(aubio_batchnorm_t *c) {
    5849  AUBIO_ASSERT(c);
    5950  if (c->gamma)
     
    6556  if (c->moving_variance)
    6657    del_fvec(c->moving_variance);
     58}
     59
     60void del_aubio_batchnorm(aubio_batchnorm_t* c) {
     61  aubio_batchnorm_reset(c);
    6762  AUBIO_FREE(c);
    6863}
     
    8277
    8378  AUBIO_ASSERT(c && input && shape);
    84   AUBIO_ASSERT(c->n_outputs == input->shape[input->ndim - 1]);
    8579
    8680  for (i = 0; i < input->ndim; i++) {
    8781    shape[i] = input->shape[i];
     82  }
     83
     84  aubio_batchnorm_reset(c);
     85
     86  c->n_outputs = input->shape[input->ndim - 1];
     87
     88  c->gamma = new_fvec(c->n_outputs);
     89  c->beta = new_fvec(c->n_outputs);
     90  c->moving_mean = new_fvec(c->n_outputs);
     91  c->moving_variance = new_fvec(c->n_outputs);
     92
     93  if (!c->gamma || !c->beta || !c->moving_mean || !c->moving_variance)
     94  {
     95    aubio_batchnorm_reset(c);
     96    return AUBIO_FAIL;
    8897  }
    8998
  • src/ai/batchnorm.h

    r3977b4f r689ba93  
    4141typedef struct _aubio_batchnorm_t aubio_batchnorm_t;
    4242
    43 aubio_batchnorm_t *new_aubio_batchnorm(uint_t n_outputs);
     43aubio_batchnorm_t *new_aubio_batchnorm(void);
    4444
    4545void aubio_batchnorm_do(aubio_batchnorm_t *t,
Note: See TracChangeset for help on using the changeset viewer.