mlp.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (c) 2017 Jean-Marc Valin */
  2. /*
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  12. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  13. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  14. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  15. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef _MLP_H_
  24. #define _MLP_H_
  25. #include "opus_types.h"
  26. #define WEIGHTS_SCALE (1.f/128)
  27. #define MAX_NEURONS 32
  28. typedef struct {
  29. const opus_int8 *bias;
  30. const opus_int8 *input_weights;
  31. int nb_inputs;
  32. int nb_neurons;
  33. int sigmoid;
  34. } DenseLayer;
  35. typedef struct {
  36. const opus_int8 *bias;
  37. const opus_int8 *input_weights;
  38. const opus_int8 *recurrent_weights;
  39. int nb_inputs;
  40. int nb_neurons;
  41. } GRULayer;
  42. extern const DenseLayer layer0;
  43. extern const GRULayer layer1;
  44. extern const DenseLayer layer2;
  45. void compute_dense(const DenseLayer *layer, float *output, const float *input);
  46. void compute_gru(const GRULayer *gru, float *state, const float *input);
  47. #endif /* _MLP_H_ */