source: src/ai/batchnorm.h @ 30cb440e

feature/crepe_org
Last change on this file since 30cb440e was 3ac1426, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[batchnorm] improve docs for return values

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[2fec649]1/*
2  Copyright (C) 2018 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
6  aubio is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  aubio is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#ifndef AUBIO_BATCHNORM_H
22#define AUBIO_BATCHNORM_H
23
24/** \file
25
26 Batch normalization layer.
27
28 References
29 ----------
30
31 Ioffe, Sergey; Szegedy, Christian. "Batch Normalization: Accelerating Deep
32 Network Training by Reducing Internal Covariate Shift", available online
33 at https://arxiv.org/pdf/1502.03167.pdf
34
35*/
36
[75662eb]37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/** batch normalization layer */
[2fec649]42typedef struct _aubio_batchnorm_t aubio_batchnorm_t;
43
[75662eb]44/** create a new batch normalization layer
45
46  This layer takes no parameters. The number of output channels will be
47  determined as the inner-most dimension of the input tensor when calling
48  ::aubio_batchnorm_get_output_shape.
49
50*/
[689ba93]51aubio_batchnorm_t *new_aubio_batchnorm(void);
[2fec649]52
[75662eb]53/** get output shape of the layer
[2fec649]54
[75662eb]55  \param t      ::aubio_batchnorm_t layer
56  \param input  input tensor
57  \param shape  output shape
58
[3ac1426]59  \return 0 on success, non-zero otherwise
60
[75662eb]61  This function determines the number of output channels required and allocate
62  the vectors of weights. The ouptut shape of this layer is identical to the
63  input shape.
64
65*/
66uint_t aubio_batchnorm_get_output_shape(aubio_batchnorm_t *t,
67        aubio_tensor_t *input, uint_t *shape);
[2fec649]68
[75662eb]69/** get a pointer to the gamma vector
70
71  \param t  ::aubio_batchnorm_t layer
72
73  \return   pointer to `fvec_t` holding the gamma parameters
74
75  When called after ::aubio_batchnorm_get_output_shape, this function will
76  return a pointer to the vector allocated to hold the `gamma` weights.
77
78  A NULL pointer will be returned if ::aubio_batchnorm_get_output_shape has not
79  been called yet.
80
81*/
[2fec649]82fvec_t *aubio_batchnorm_get_gamma(aubio_batchnorm_t *t);
[75662eb]83
84/** get a pointer to the beta vector
85
86  \param t  ::aubio_batchnorm_t layer
87
88  \return   pointer to `fvec_t` holding the beta parameters
89*/
[2fec649]90fvec_t *aubio_batchnorm_get_beta(aubio_batchnorm_t *t);
[75662eb]91
92/** get a pointer to the moving mean vector
93
94  \param t  ::aubio_batchnorm_t layer
95
96  \return   pointer to `fvec_t` holding the moving mean parameters
97
98*/
[2fec649]99fvec_t *aubio_batchnorm_get_moving_mean(aubio_batchnorm_t *t);
[75662eb]100
101/** get a pointer to the moving variance vector
102
103  \param t  ::aubio_batchnorm_t layer
104
105  \return   pointer to `fvec_t` holding the moving variance parameters
106
107*/
[2fec649]108fvec_t *aubio_batchnorm_get_moving_variance(aubio_batchnorm_t *t);
109
[75662eb]110/** set gamma vector of batchnorm layer
111
112  \param t      ::aubio_batchnorm_t layer
113  \param gamma  ::fvec_t containing the weights
114
115  \return   0 on success, non-zero otherwise.
116
117  This function will copy the content of an existing vector into
118  the corresponding vector of weights in `t`.
119
120  Note: to spare a copy and load directly the data in `t`,
121  ::aubio_batchnorm_get_gamma can be used instead.
122
123*/
124uint_t aubio_batchnorm_set_gamma(aubio_batchnorm_t *t, fvec_t *gamma);
125
126/** set beta vector of a batchnorm layer
127
128  \param t      ::aubio_batchnorm_t layer
129  \param beta   ::fvec_t containing the weights
130
131  \return   0 on success, non-zero otherwise.
132
133*/
134uint_t aubio_batchnorm_set_beta(aubio_batchnorm_t *t, fvec_t *beta);
135
136/** set moving mean vector of batchnorm layer
[2fec649]137
[75662eb]138  \param t              ::aubio_batchnorm_t layer
139  \param moving_mean    ::fvec_t containing the weights
140
141  \return   0 on success, non-zero otherwise.
142
143*/
144uint_t aubio_batchnorm_set_moving_mean(aubio_batchnorm_t *t,
145        fvec_t *moving_mean);
146
147/** set moving variance vector of batchnorm layer
148
149  \param t                  ::aubio_batchnorm_t layer
150  \param moving_variance    ::fvec_t containing the weights
151
152  \return   0 on success, non-zero otherwise.
153
154*/
155uint_t aubio_batchnorm_set_moving_variance(aubio_batchnorm_t *t,
156        fvec_t *moving_variance);
157
158/** compute batch normalization layer
159
160  \param t             ::aubio_batchnorm_t layer
161  \param input_tensor  input tensor
162  \param activations   output tensor
163
164*/
165void aubio_batchnorm_do(aubio_batchnorm_t *t, aubio_tensor_t *input_tensor,
166        aubio_tensor_t *activations);
167
168/** delete batch normalization layer
169
170  \param t  ::aubio_batchnorm_t layer to delete
171
172*/
[2fec649]173void del_aubio_batchnorm(aubio_batchnorm_t *t);
174
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* AUBIO_BATCHNORM_H */
Note: See TracBrowser for help on using the repository browser.