[bacf0c6] | 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_CONV2D_H |
---|
| 22 | #define AUBIO_CONV2D_H |
---|
| 23 | |
---|
[ecb9f64] | 24 | /** \file |
---|
| 25 | |
---|
| 26 | Convolutional layer (2D) |
---|
| 27 | |
---|
| 28 | Standard implementation of a 2D 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 | |
---|
[bacf0c6] | 42 | #ifdef __cplusplus |
---|
| 43 | extern "C" { |
---|
| 44 | #endif |
---|
| 45 | |
---|
[ecb9f64] | 46 | /** conv2d layer */ |
---|
[bacf0c6] | 47 | typedef struct _aubio_conv2d_t aubio_conv2d_t; |
---|
| 48 | |
---|
[ecb9f64] | 49 | /** create a new conv2d layer |
---|
[bacf0c6] | 50 | |
---|
[ecb9f64] | 51 | \param n_filters number of filters |
---|
| 52 | \param kernel_shape shape of each filter |
---|
[bacf0c6] | 53 | |
---|
[ecb9f64] | 54 | \return new conv2d layer |
---|
[bacf0c6] | 55 | |
---|
[ecb9f64] | 56 | */ |
---|
| 57 | aubio_conv2d_t *new_aubio_conv2d(uint_t n_filters, uint_t kernel_shape[2]); |
---|
[bacf0c6] | 58 | |
---|
[ecb9f64] | 59 | /** set padding mode |
---|
[bacf0c6] | 60 | |
---|
[ecb9f64] | 61 | \param c layer |
---|
| 62 | \param padding_mode padding mode |
---|
[bacf0c6] | 63 | |
---|
[ecb9f64] | 64 | \return 0 on success, non-zero otherwise |
---|
[bacf0c6] | 65 | |
---|
[ecb9f64] | 66 | Available padding: "same", and "valid". |
---|
[bacf0c6] | 67 | |
---|
[ecb9f64] | 68 | */ |
---|
[bacf0c6] | 69 | uint_t aubio_conv2d_set_padding_mode(aubio_conv2d_t *c, |
---|
| 70 | const char_t *padding_mode); |
---|
| 71 | |
---|
[ecb9f64] | 72 | /** set stride |
---|
| 73 | |
---|
| 74 | \param c layer |
---|
| 75 | \param stride array of length 2 containing the strides |
---|
| 76 | |
---|
| 77 | \return 0 on success, non-zero otherwise |
---|
| 78 | |
---|
| 79 | */ |
---|
| 80 | uint_t aubio_conv2d_set_stride(aubio_conv2d_t *c, uint_t stride[2]); |
---|
| 81 | |
---|
| 82 | /** get current stride settings |
---|
| 83 | |
---|
| 84 | \param t layer |
---|
| 85 | |
---|
| 86 | \return array of length 2 containing the stride in each dimension |
---|
| 87 | |
---|
| 88 | */ |
---|
| 89 | uint_t *aubio_conv2d_get_stride(aubio_conv2d_t* t); |
---|
| 90 | |
---|
| 91 | /** get output shape |
---|
| 92 | |
---|
| 93 | \param t layer |
---|
| 94 | \param input_tensor input tensor |
---|
| 95 | \param shape output shape |
---|
| 96 | |
---|
| 97 | \return 0 on success, non-zero otherwise |
---|
| 98 | |
---|
| 99 | Upon return, `shape` will be filled with the output shape of the layer. This |
---|
| 100 | function should be called after ::aubio_conv2d_set_stride or |
---|
| 101 | ::aubio_conv2d_set_padding_mode, and before ::aubio_conv2d_get_kernel or |
---|
| 102 | ::aubio_conv2d_get_bias. |
---|
| 103 | |
---|
| 104 | */ |
---|
[bacf0c6] | 105 | uint_t aubio_conv2d_get_output_shape(aubio_conv2d_t *t, |
---|
| 106 | aubio_tensor_t *input_tensor, uint_t *shape); |
---|
| 107 | |
---|
[ecb9f64] | 108 | /** get kernel weights |
---|
| 109 | |
---|
| 110 | \param t ::aubio_conv2d_t layer |
---|
| 111 | |
---|
| 112 | \return tensor of weights |
---|
| 113 | |
---|
| 114 | When called after ::aubio_conv2d_get_output_shape, this function will return |
---|
| 115 | a pointer to the tensor holding the weights of this layer. |
---|
| 116 | |
---|
| 117 | */ |
---|
| 118 | aubio_tensor_t *aubio_conv2d_get_kernel(aubio_conv2d_t *t); |
---|
| 119 | |
---|
| 120 | /** get biases |
---|
| 121 | |
---|
| 122 | \param t layer |
---|
| 123 | |
---|
| 124 | \return vector of biases |
---|
| 125 | |
---|
| 126 | When called after ::aubio_conv2d_get_output_shape, this function will return |
---|
| 127 | a pointer to the vector holding the biases. |
---|
| 128 | |
---|
| 129 | */ |
---|
| 130 | fvec_t *aubio_conv2d_get_bias(aubio_conv2d_t *t); |
---|
| 131 | |
---|
| 132 | /** set kernel weights |
---|
| 133 | |
---|
| 134 | \param t layer |
---|
| 135 | \param kernel kernel weights |
---|
| 136 | |
---|
| 137 | \return 0 on success, non-zero otherwise |
---|
| 138 | |
---|
| 139 | Copy kernel weights into internal layer memory. This function should be |
---|
| 140 | called after ::aubio_conv2d_get_output_shape. |
---|
| 141 | |
---|
| 142 | */ |
---|
| 143 | uint_t aubio_conv2d_set_kernel(aubio_conv2d_t *t, aubio_tensor_t *kernel); |
---|
| 144 | |
---|
| 145 | /** set biases |
---|
| 146 | |
---|
| 147 | \param t layer |
---|
| 148 | \param bias biases |
---|
| 149 | |
---|
| 150 | \return 0 on success, non-zero otherwise |
---|
| 151 | |
---|
| 152 | Copy vector of biases into internal layer memory. This function should be |
---|
| 153 | called after ::aubio_conv2d_get_output_shape. |
---|
| 154 | |
---|
| 155 | */ |
---|
| 156 | uint_t aubio_conv2d_set_bias(aubio_conv2d_t *t, fvec_t *bias); |
---|
| 157 | |
---|
| 158 | /** compute layer output |
---|
| 159 | |
---|
| 160 | \param t layer |
---|
| 161 | \param input_tensor input tensor |
---|
| 162 | \param output_tensor output tensor |
---|
| 163 | |
---|
| 164 | Perform 2D convolution. |
---|
| 165 | |
---|
| 166 | */ |
---|
| 167 | void aubio_conv2d_do(aubio_conv2d_t *t, aubio_tensor_t *input_tensor, |
---|
| 168 | aubio_tensor_t *output_tensor); |
---|
| 169 | |
---|
| 170 | /** destroy conv2d layer |
---|
| 171 | |
---|
| 172 | \param t layer |
---|
| 173 | |
---|
| 174 | */ |
---|
[bacf0c6] | 175 | void del_aubio_conv2d(aubio_conv2d_t *t); |
---|
| 176 | |
---|
| 177 | #ifdef __cplusplus |
---|
| 178 | } |
---|
| 179 | #endif |
---|
| 180 | |
---|
| 181 | #endif /* AUBIO_CONV2D_H */ |
---|