source: src/ai/conv1d.h @ bf3ce2c

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

[conv1d] add basic documentation

  • Property mode set to 100644
File size: 4.2 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_CONV1D_H
22#define AUBIO_CONV1D_H
23
24/** \file
25
26  Convolutional layer (1D)
27
28  Standard implementation of a 1D convolutional layer, partly optimized for
29  CPU.
30
31  Note
32  ----
33  Only the forward pass is implemented for now.
34
35  References
36  ----------
37  Vincent Dumoulin, Francesco Visin - A guide to convolution arithmetic for
38  deep learning. https://github.com/vdumoulin/conv_arithmetic
39
40*/
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/** conv1d layer */
47typedef struct _aubio_conv1d_t aubio_conv1d_t;
48
49/** create a new conv1d layer
50
51  \param n_filters number of filters
52  \param kernel_shape length of each filter
53
54  \return new conv1d layer
55
56*/
57aubio_conv1d_t *new_aubio_conv1d(uint_t n_filters, uint_t kernel_shape[1]);
58
59/** set padding mode
60
61  \param c                  layer
62  \param padding_mode       padding mode
63
64  \return 0 on success, non-zero otherwise
65
66  Available padding: "same", and "valid".
67
68  Todo:
69  - add causal mode
70
71*/
72uint_t aubio_conv1d_set_padding_mode(aubio_conv1d_t *c,
73    const char_t *padding_mode);
74
75/** set stride
76
77  \param c      layer
78  \param stride array of length 1 containing the stride parameter
79
80  \return 0 on success, non-zero otherwise
81
82*/
83uint_t aubio_conv1d_set_stride(aubio_conv1d_t *c, uint_t stride[1]);
84
85/** get current stride settings
86
87  \param t  layer
88
89  \return   array of length 1 containing the stride parameter
90
91*/
92uint_t *aubio_conv1d_get_stride(aubio_conv1d_t* t);
93
94/** get output shape
95
96  \param t                  layer
97  \param input_tensor       input tensor
98  \param shape              output shape
99
100  \return 0 on success, non-zero otherwise
101
102  Upon return, `shape` will be filled with the output shape of the layer. This
103  function should be called after ::aubio_conv1d_set_stride or
104  ::aubio_conv1d_set_padding_mode, and before ::aubio_conv1d_get_kernel or
105  ::aubio_conv1d_get_bias.
106
107*/
108uint_t aubio_conv1d_get_output_shape(aubio_conv1d_t *t,
109        aubio_tensor_t *input_tensor, uint_t *shape);
110
111/** get kernel weights
112
113  \param t ::aubio_conv1d_t layer
114
115  \return tensor of weights
116
117  When called after ::aubio_conv1d_get_output_shape, this function will return
118  a pointer to the tensor holding the weights of this layer.
119
120*/
121aubio_tensor_t *aubio_conv1d_get_kernel(aubio_conv1d_t *t);
122
123/** get biases
124
125  \param t layer
126
127  \return vector of biases
128
129  When called after ::aubio_conv1d_get_output_shape, this function will return
130  a pointer to the vector holding the biases.
131
132*/
133fvec_t *aubio_conv1d_get_bias(aubio_conv1d_t *t);
134
135/** set kernel weights
136
137  \param t          layer
138  \param kernel     kernel weights
139
140  \return 0 on success, non-zero otherwise
141
142  Copy kernel weights into internal layer memory.  This function should be
143  called after ::aubio_conv1d_get_output_shape.
144
145*/
146uint_t aubio_conv1d_set_kernel(aubio_conv1d_t *t, aubio_tensor_t *kernel);
147
148/** set biases
149
150  \param t          layer
151  \param bias       biases
152
153  \return 0 on success, non-zero otherwise
154
155  Copy vector of biases into internal layer memory. This function should be
156  called after ::aubio_conv1d_get_output_shape.
157
158*/
159uint_t aubio_conv1d_set_bias(aubio_conv1d_t *t, fvec_t *bias);
160
161/** compute layer output
162
163  \param t              layer
164  \param input_tensor   input tensor
165  \param output_tensor  output tensor
166
167  Perform 1D convolution.
168
169*/
170void aubio_conv1d_do(aubio_conv1d_t *t, aubio_tensor_t *input_tensor,
171        aubio_tensor_t *output_tensor);
172
173/** destroy conv1d layer
174
175  \param t  layer
176
177*/
178void del_aubio_conv1d(aubio_conv1d_t *t);
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif /* AUBIO_CONV1D_H */
Note: See TracBrowser for help on using the repository browser.