|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +#ifndef __DSCNN_H__ |
| 5 | +#define __DSCNN_H__ |
| 6 | + |
| 7 | +// Function pointer for the Conv layer to be passed as a parameter. (conv1d or conv1d_lr only) |
| 8 | +typedef int (*conv_layer)(float*, unsigned, unsigned, const float*, |
| 9 | + unsigned, unsigned, unsigned, unsigned, |
| 10 | + const void*, unsigned, unsigned); |
| 11 | + |
| 12 | +/** |
| 13 | + * @brief Model definition for the 1D Convolution block applied before the RNN |
| 14 | + * @brief sub-layers : batchnorm1d -> conv1d_lr |
| 15 | + * @param[out] output_signal pointer to the final output signal, minimum size = out_time * in_channels. out_time has to be calculated based on the reduction from all the conv and pool layers |
| 16 | + * @param[in] input_signal pointer to the input signal. size = in_time * in_channels |
| 17 | + * @param[in] cnn function pointer for the CNN layer. (any of the conv layers can be passed with appropriate params) |
| 18 | + * @param[in] in_time number of time steps in the input_signal |
| 19 | + * @param[in] in_channels number of input channels |
| 20 | + * @param[in] mean pointer to the mean for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2 |
| 21 | + * @param[in] var pointer to the variance for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2 |
| 22 | + * @param[in] affine_config whether the affine operations are applied |
| 23 | + * if affine_config = 0, then only mean and var are used |
| 24 | + * if affine_config = 1, then mean, var, gamma and beta are used for the final computation. |
| 25 | + * if affine_config = 2, then only the gamma and beta are used. gamma = original_gamma/sqrt(var), beta = original_beta - gamma * mean/sqrt(var) |
| 26 | + * Note: Use affine_config = 2 for faster calculations. The new gamma and beta would need to be pre-computed, stored and passed |
| 27 | + * @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0 |
| 28 | + * @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0 |
| 29 | + * @param[in] in_place in-place computation check for the batchnorm. Storage efficient |
| 30 | + * @param[in] cnn_hidden hidden state/out_channels dimensions for the low-rank CNN. The final channel size of this block |
| 31 | + * @param[in] cnn_padding padding for the low-rank CNN layer. Note: applied to both sides of the input |
| 32 | + * @param[in] cnn_kernel_size kernel size of the low-rank CNN |
| 33 | + * @param[in] cnn_params weights, bias and other essential parameters for the low-rank CNN |
| 34 | + * @param[in] cnn_stride stride factor for the low-rank CNN |
| 35 | + * @param[in] cnn_activation an integer to choose the type of activation function. |
| 36 | + * 0: none |
| 37 | + * 1: sigmoid |
| 38 | + * 2: tanh |
| 39 | + * 3: relu |
| 40 | + */ |
| 41 | +int phon_pred_lr_cnn(float* output_signal, float* input_signal, |
| 42 | + conv_layer cnn, unsigned in_time, unsigned in_channels, |
| 43 | + const float* const mean, const float* const var, |
| 44 | + unsigned affine_config, const float* const gamma, const float* const beta, unsigned in_place, |
| 45 | + unsigned cnn_hidden, unsigned cnn_padding, unsigned cnn_kernel_size, |
| 46 | + const void* cnn_params, unsigned cnn_stride, unsigned cnn_activation); |
| 47 | + |
| 48 | +/** |
| 49 | + * @brief Model definition for the 1D Convolution block applied after the RNN |
| 50 | + * @brief sub-layers : custom nonlinearity(semi_sigmoid_tanh) -> batchnorm1d -> conv1d_depth -> conv1d_lr -> avgpool1d |
| 51 | + * @param[out] output_signal pointer to the final output signal, minimum size = out_time * in_channels. out_time has to be calculated based on the reduction from all the conv and pool layers |
| 52 | + * @param[in] input_signal pointer to the input signal. size = in_time * in_channels |
| 53 | + * @param[in] point_cnn function pointer for the point-wise CNN. (any of the conv layers can be passed with appropriate params) |
| 54 | + * @param[in] in_time number of time steps in the input |
| 55 | + * @param[in] in_channels number of input channels |
| 56 | + * @param[in] mean pointer to the mean for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2 |
| 57 | + * @param[in] var pointer to the variance for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2 |
| 58 | + * @param[in] affine_config whether the affine operations are applied |
| 59 | + * if affine_config = 0, then only mean and var are used |
| 60 | + * if affine_config = 1, then mean, var, gamma and beta are used for the final computation. |
| 61 | + * if affine_config = 2, then only the gamma and beta are used. gamma = original_gamma/sqrt(var), beta = original_beta - gamma * mean/sqrt(var) |
| 62 | + * Note: Use affine_config = 2 for faster calculations. The new gamma and beta would need to be pre-computed, stored and passed |
| 63 | + * @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0 |
| 64 | + * @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0 |
| 65 | + * @param[in] in_place in-place computation of the batchnorm. Storage efficient |
| 66 | + * @param[in] depth_cnn_padding padding for the depth CNN layer. Note: applied to both sides of the input to the depth CNN |
| 67 | + * @param[in] depth_cnn_kernel_size kernel size of the depth CNN |
| 68 | + * @param[in] depth_cnn_params weights, bias and other essential parameters used to describe the depth CNN |
| 69 | + * @param[in] depth_cnn_stride stride factor for the depth CNN |
| 70 | + * @param[in] depth_cnn_activation an integer to choose the type of activation function. |
| 71 | + * 0: none |
| 72 | + * 1: sigmoid |
| 73 | + * 2: tanh |
| 74 | + * 3: relu |
| 75 | + * @param[in] point_cnn_hidden hidden state/out_channels dimensions for the point CNN. The final channel size of this block |
| 76 | + * @param[in] point_cnn_padding padding for the point CNN layer. Note: applied to both sides of the input to the point CNN |
| 77 | + * @param[in] point_cnn_kernel_size kernel size of the point CNN |
| 78 | + * @param[in] point_cnn_params weights, bias and other essential parameters used to describe the point CNN |
| 79 | + * @param[in] point_cnn_stride stride factor for the point CNN |
| 80 | + * @param[in] point_cnn_activation an integer to choose the type of activation function. |
| 81 | + * 0: none |
| 82 | + * 1: sigmoid |
| 83 | + * 2: tanh |
| 84 | + * 3: relu |
| 85 | + * @param[in] pool_padding padding for the pool layer. Note: applied to both sides of the input to the pool |
| 86 | + * @param[in] pool_kernel_size kernel size of the pool |
| 87 | + * @param[in] pool_stride stride factor for the pool |
| 88 | + * @param[in] pool_activation an integer to choose the type of activation function. |
| 89 | + * 0: none |
| 90 | + * 1: sigmoid |
| 91 | + * 2: tanh |
| 92 | + * 3: relu |
| 93 | + */ |
| 94 | +int phon_pred_depth_point_lr_cnn(float* output_signal, float* input_signal, |
| 95 | + conv_layer point_cnn, unsigned in_time, unsigned in_channels, |
| 96 | + const float* const mean, const float* const var, |
| 97 | + unsigned affine_config, const float* const gamma, const float* const beta, unsigned in_place, |
| 98 | + unsigned depth_cnn_padding, unsigned depth_cnn_kernel_size, |
| 99 | + const void* depth_cnn_params, unsigned depth_cnn_stride, unsigned depth_cnn_activation, |
| 100 | + unsigned point_cnn_hidden, unsigned point_cnn_padding, unsigned point_cnn_kernel_size, |
| 101 | + const void* point_cnn_params, unsigned point_cnn_stride, unsigned point_cnn_activation, |
| 102 | + unsigned pool_padding, unsigned pool_kernel_size, unsigned pool_stride, unsigned pool_activation); |
| 103 | + |
| 104 | +#endif |
0 commit comments