source: src/ai/batchnorm.h @ 7f270f8

feature/crepe
Last change on this file since 7f270f8 was 7f270f8, checked in by Paul Brossier <piem@piem.org>, 2 years ago

[batchnorm] add basic documentation, shuffle declarations to match usage order

  • Property mode set to 100644
File size: 4.7 KB
Line 
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
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/** batch normalization layer */
42typedef struct _aubio_batchnorm_t aubio_batchnorm_t;
43
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*/
51aubio_batchnorm_t *new_aubio_batchnorm(void);
52
53/** get output shape of the layer
54
55  \param t      ::aubio_batchnorm_t layer
56  \param input  input tensor
57  \param shape  output shape
58
59  This function determines the number of output channels required and allocate
60  the vectors of weights. The ouptut shape of this layer is identical to the
61  input shape.
62
63*/
64uint_t aubio_batchnorm_get_output_shape(aubio_batchnorm_t *t,
65        aubio_tensor_t *input, uint_t *shape);
66
67/** get a pointer to the gamma vector
68
69  \param t  ::aubio_batchnorm_t layer
70
71  \return   pointer to `fvec_t` holding the gamma parameters
72
73  When called after ::aubio_batchnorm_get_output_shape, this function will
74  return a pointer to the vector allocated to hold the `gamma` weights.
75
76  A NULL pointer will be returned if ::aubio_batchnorm_get_output_shape has not
77  been called yet.
78
79*/
80fvec_t *aubio_batchnorm_get_gamma(aubio_batchnorm_t *t);
81
82/** get a pointer to the beta vector
83
84  \param t  ::aubio_batchnorm_t layer
85
86  \return   pointer to `fvec_t` holding the beta parameters
87*/
88fvec_t *aubio_batchnorm_get_beta(aubio_batchnorm_t *t);
89
90/** get a pointer to the moving mean vector
91
92  \param t  ::aubio_batchnorm_t layer
93
94  \return   pointer to `fvec_t` holding the moving mean parameters
95
96*/
97fvec_t *aubio_batchnorm_get_moving_mean(aubio_batchnorm_t *t);
98
99/** get a pointer to the moving variance vector
100
101  \param t  ::aubio_batchnorm_t layer
102
103  \return   pointer to `fvec_t` holding the moving variance parameters
104
105*/
106fvec_t *aubio_batchnorm_get_moving_variance(aubio_batchnorm_t *t);
107
108/** set gamma vector of batchnorm layer
109
110  \param t      ::aubio_batchnorm_t layer
111  \param gamma  ::fvec_t containing the weights
112
113  \return   0 on success, non-zero otherwise.
114
115  This function will copy the content of an existing vector into
116  the corresponding vector of weights in `t`.
117
118  Note: to spare a copy and load directly the data in `t`,
119  ::aubio_batchnorm_get_gamma can be used instead.
120
121*/
122uint_t aubio_batchnorm_set_gamma(aubio_batchnorm_t *t, fvec_t *gamma);
123
124/** set beta vector of a batchnorm layer
125
126  \param t      ::aubio_batchnorm_t layer
127  \param beta   ::fvec_t containing the weights
128
129  \return   0 on success, non-zero otherwise.
130
131*/
132uint_t aubio_batchnorm_set_beta(aubio_batchnorm_t *t, fvec_t *beta);
133
134/** set moving mean vector of batchnorm layer
135
136  \param t              ::aubio_batchnorm_t layer
137  \param moving_mean    ::fvec_t containing the weights
138
139  \return   0 on success, non-zero otherwise.
140
141*/
142uint_t aubio_batchnorm_set_moving_mean(aubio_batchnorm_t *t,
143        fvec_t *moving_mean);
144
145/** set moving variance vector of batchnorm layer
146
147  \param t                  ::aubio_batchnorm_t layer
148  \param moving_variance    ::fvec_t containing the weights
149
150  \return   0 on success, non-zero otherwise.
151
152*/
153uint_t aubio_batchnorm_set_moving_variance(aubio_batchnorm_t *t,
154        fvec_t *moving_variance);
155
156/** compute batch normalization layer
157
158  \param t             ::aubio_batchnorm_t layer
159  \param input_tensor  input tensor
160  \param activations   output tensor
161
162  \return   0 on success, non-zero otherwise.
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*/
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.