Changeset 0067121
- Timestamp:
- Jan 29, 2019, 3:03:51 AM (6 years ago)
- Branches:
- feature/crepe_org
- Children:
- 30ad7e7
- Parents:
- 695a248
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ai/conv1d.h
r695a248 r0067121 22 22 #define AUBIO_CONV1D_H 23 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 24 42 #ifdef __cplusplus 25 43 extern "C" { 26 44 #endif 27 45 46 /** conv1d layer */ 28 47 typedef struct _aubio_conv1d_t aubio_conv1d_t; 29 48 30 /** create a new conv1d layer */ 31 aubio_conv1d_t *new_aubio_conv1d(uint_t filters, uint_t kernel_shape[1]); 49 /** create a new conv1d layer 32 50 33 /** perform forward 1D convolution */ 34 void aubio_conv1d_do(aubio_conv1d_t *t, aubio_tensor_t *input_tensor, 35 aubio_tensor_t *activations); 51 \param n_filters number of filters 52 \param kernel_shape length of each filter 36 53 37 /** TODO: implement */ 38 void aubio_conv1d_train(aubio_conv1d_t *t, aubio_tensor_t *input_tensor); 54 \return new conv1d layer 39 55 40 /** get conv1d weights*/41 aubio_ tensor_t *aubio_conv1d_get_kernel(aubio_conv1d_t *t);56 */ 57 aubio_conv1d_t *new_aubio_conv1d(uint_t n_filters, uint_t kernel_shape[1]); 42 58 43 /** get conv1d biases */ 44 fvec_t *aubio_conv1d_get_bias(aubio_conv1d_t *t); 59 /** set padding mode 45 60 46 /** set conv1d stride */ 47 uint_t aubio_conv1d_set_stride(aubio_conv1d_t *c, uint_t stride[1]); 61 \param c layer 62 \param padding_mode padding mode 48 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 */ 49 72 uint_t aubio_conv1d_set_padding_mode(aubio_conv1d_t *c, 50 73 const char_t *padding_mode); 51 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 */ 83 uint_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 */ 92 uint_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 */ 52 108 uint_t aubio_conv1d_get_output_shape(aubio_conv1d_t *t, 53 109 aubio_tensor_t *input_tensor, uint_t *shape); 54 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 */ 121 aubio_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 */ 133 fvec_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 */ 146 uint_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 */ 159 uint_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 */ 170 void 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 */ 55 178 void del_aubio_conv1d(aubio_conv1d_t *t); 56 179
Note: See TracChangeset
for help on using the changeset viewer.