- Timestamp:
- Dec 29, 2021, 5:52:02 PM (3 years ago)
- Branches:
- feature/crepe
- Children:
- 8e1e753
- Parents:
- 7f915f7
- git-author:
- Paul Brossier <piem@piem.org> (01/29/19 03:04:06)
- git-committer:
- Paul Brossier <piem@piem.org> (12/29/21 17:52:02)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ai/conv2d.h
r7f915f7 recb9f64 22 22 #define AUBIO_CONV2D_H 23 23 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 24 42 #ifdef __cplusplus 25 43 extern "C" { 26 44 #endif 27 45 46 /** conv2d layer */ 28 47 typedef struct _aubio_conv2d_t aubio_conv2d_t; 29 48 30 /** create a new conv2d layer */ 31 aubio_conv2d_t *new_aubio_conv2d(uint_t filters, uint_t *kernel_shape); 49 /** create a new conv2d layer 32 50 33 /** perform forward 2D convolution */ 34 void aubio_conv2d_do(aubio_conv2d_t *t, aubio_tensor_t *input_tensor, 35 aubio_tensor_t *activations); 51 \param n_filters number of filters 52 \param kernel_shape shape of each filter 36 53 37 /** TODO: implement */ 38 void aubio_conv2d_train(aubio_conv2d_t *t, aubio_tensor_t *input_tensor); 54 \return new conv2d layer 39 55 40 /** set internal kernel weights*/41 uint_t aubio_conv2d_set_kernel(aubio_conv2d_t *t, aubio_tensor_t *kernel);56 */ 57 aubio_conv2d_t *new_aubio_conv2d(uint_t n_filters, uint_t kernel_shape[2]); 42 58 43 /** get conv2d weights */ 44 aubio_tensor_t *aubio_conv2d_get_kernel(aubio_conv2d_t *t); 59 /** set padding mode 45 60 46 /** set internal biases */ 47 uint_t aubio_conv2d_set_bias(aubio_conv2d_t *t, fvec_t *bias); 61 \param c layer 62 \param padding_mode padding mode 48 63 49 /** get conv2d biases */ 50 fvec_t *aubio_conv2d_get_bias(aubio_conv2d_t *t); 64 \return 0 on success, non-zero otherwise 51 65 52 /** set conv2d stride */ 53 uint_t aubio_conv2d_set_stride(aubio_conv2d_t *c, 54 uint_t stride[2]); 66 Available padding: "same", and "valid". 55 67 56 uint_t *aubio_conv2d_get_stride(aubio_conv2d_t* t); 57 68 */ 58 69 uint_t aubio_conv2d_set_padding_mode(aubio_conv2d_t *c, 59 70 const char_t *padding_mode); 60 71 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 */ 61 105 uint_t aubio_conv2d_get_output_shape(aubio_conv2d_t *t, 62 106 aubio_tensor_t *input_tensor, uint_t *shape); 63 107 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 */ 64 175 void del_aubio_conv2d(aubio_conv2d_t *t); 65 176
Note: See TracChangeset
for help on using the changeset viewer.