Skip to content

Commit 6411d15

Browse files
Conv1d, AveragePool1d and Batchnorm1d Layers
1 parent 094c593 commit 6411d15

40 files changed

+1488
-1098
lines changed

.gitattributes

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ c_reference/models/q_scut_head_b_face4_model/detection2.h filter=lfs diff=lfs me
6363
c_reference/tests/kws/keyword_spotting_io_1.h filter=lfs diff=lfs merge=lfs -text
6464
c_reference/tests/kws/keyword_spotting_io_2.h filter=lfs diff=lfs merge=lfs -text
6565
c_reference/tests/kws/keyword_spotting_io_3.h filter=lfs diff=lfs merge=lfs -text
66-
c_reference/tests/conv1d/avg_pool/avg_io.h filter=lfs diff=lfs merge=lfs -text
6766
c_reference/tests/conv1d/conv1d_regular/conv_param.h filter=lfs diff=lfs merge=lfs -text
6867
c_reference/tests/conv1d/conv1d_lr/conv_param_lr.h filter=lfs diff=lfs merge=lfs -text
6968
c_reference/tests/conv1d/conv1d_lr_depthwise/conv_param_lr_depth.h filter=lfs diff=lfs merge=lfs -text
7069
c_reference/tests/conv1d/conv1d_depthwise/conv_param_depth.h filter=lfs diff=lfs merge=lfs -text
7170
c_reference/tests/kws/precnn_params.h filter=lfs diff=lfs merge=lfs -text
7271
c_reference/tests/kws/postcnn_params.h filter=lfs diff=lfs merge=lfs -text
7372
c_reference/tests/kws/rnn_params.h filter=lfs diff=lfs merge=lfs -text
74-
c_reference/tests/dscnn/dscnn_param_lr.h filter=lfs diff=lfs merge=lfs -text
75-
c_reference/tests/dscnn/dscnn_param_lr_depth_point.h filter=lfs diff=lfs merge=lfs -text
73+
c_reference/tests/rnn_bricked/rnn_params.h filter=lfs diff=lfs merge=lfs -text
74+
c_reference/tests/rnn_bricked/rnn_bricked_io.h filter=lfs diff=lfs merge=lfs -text

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Algorithms that shine in this setting in terms of both model size and compute, n
1717
- **EMI-RNN**: Training routine to recover the critical signature from time series data for faster and accurate RNN predictions.
1818
- **Shallow RNN**: A meta-architecture for training RNNs that can be applied to streaming data.
1919
- **FastRNN & FastGRNN - FastCells**: **F**ast, **A**ccurate, **S**table and **T**iny (**G**ated) RNN cells.
20-
- **Conv1D**: 1-D regular and low-rank convolution architectures for time-series data.
2120
- **DROCC**: **D**eep **R**obust **O**ne-**C**lass **C**lassfiication for training robust anomaly detectors.
2221
- **RNNPool**: An efficient non-linear pooling operator for RAM constrained inference.
2322

c_reference/include/conv1d.h

Lines changed: 122 additions & 85 deletions
Large diffs are not rendered by default.

c_reference/include/conv_utils.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

c_reference/include/dscnn.h

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,102 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
#ifndef __DSCNN__
5-
#define __DSCNN__
4+
#ifndef __DSCNN_H__
5+
#define __DSCNN_H__
66

7-
#include"conv1d.h"
8-
#include"conv_utils.h"
9-
#include<stdlib.h>
10-
#include<math.h>
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);
1111

1212
/**
13-
* @brief Model definition for the 1D Convolution sub-block applied before the RNN
14-
* @brief sub-layers : BatchNorm1d -> Conv1D_LR
15-
*
16-
* @param[out] output_signal pointer to the final output signal, minimum size = out_T * in_channels. out_T has to be calculated based on the reduction from all the conv and pool layers
17-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
18-
* @param[in] in_T number of time steps in the input
19-
* @param[in] in_channels number of input channels. The output will have the same number of channels
20-
21-
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels
22-
* @param[in] var pointer to the variance for the batch normalization, size = in_channels
23-
* @param[in] affine whether the affine operations are applied
24-
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels
25-
* @param[in] beta pointer to the scalar offsets for the post-norm affine operation, size = in_channels
26-
* @param[in] in_place in place computation of the batchnorm. Storage efficient
27-
*
28-
* @param[in] cnn_hidden hidden state/out_channels dimensions for the CNN
29-
* @param[in] cnn_padding padding for the CNN layer. Note: applied to both sides of the input
30-
* @param[in] cnn_kernel_size kernel size of the CNN
31-
* @param[in] cnn_params weights, bias and other essential parameters used to describe the CNN
32-
* @param[in] cnn_activations an integer to choose the type of activation function.
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] in_time number of time steps in the input_signal
18+
* @param[in] in_channels number of input channels
19+
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2
20+
* @param[in] var pointer to the variance for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2
21+
* @param[in] affine_config whether the affine operations are applied
22+
* if affine_config = 0, then only mean and var are used
23+
* if affine_config = 1, then mean, var, gamma and beta are used for the final computation.
24+
* if affine_config = 2, then only the gamma and beta are used. gamma = original_gamma/sqrt(var), beta = original_beta - gamma * mean/sqrt(var)
25+
* Note: Use affine_config = 2 for faster calculations. The new gamma and beta would need to be pre-computed, stored and passed
26+
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0
27+
* @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0
28+
* @param[in] in_place in-place computation check for the batchnorm. Storage efficient
29+
* @param[in] cnn_hidden hidden state/out_channels dimensions for the low-rank CNN. The final channel size of this block
30+
* @param[in] cnn_padding padding for the low-rank CNN layer. Note: applied to both sides of the input
31+
* @param[in] cnn_kernel_size kernel size of the low-rank CNN
32+
* @param[in] cnn_params weights, bias and other essential parameters for the low-rank CNN
33+
* @param[in] cnn_stride stride factor for the low-rank CNN
34+
* @param[in] cnn_activation an integer to choose the type of activation function.
3335
* 0: none
3436
* 1: sigmoid
3537
* 2: tanh
3638
* 3: relu
3739
*/
38-
int DSCNN_LR(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels, float* mean, float* var,
39-
unsigned affine, float* gamma, float* beta, unsigned in_place, unsigned cnn_hidden, int cnn_padding, unsigned cnn_kernel_size,
40-
const void* cnn_params, int cnn_activations);
40+
int phon_pred_lr_cnn(float* output_signal, float* input_signal,
41+
unsigned in_time, unsigned in_channels,
42+
const float* const mean, const float* const var,
43+
unsigned affine_config, const float* const gamma, const float* const beta, unsigned in_place,
44+
unsigned cnn_hidden, unsigned cnn_padding, unsigned cnn_kernel_size,
45+
const void* cnn_params, unsigned cnn_stride, unsigned cnn_activation);
4146

4247
/**
43-
* @brief Model definition for the 1D Convolution sub-block applied after the RNN
44-
* @brief sub-layers : TanhGate(custom) nonlinearity -> BatchNorm1d -> Conv1D_Depth -> Conv1d_LR -> AvgPool
45-
*
46-
* @param[out] output_signal pointer to the final output signal, minimum size = out_T * in_channels. out_T has to be calculated based on the reduction from all the conv and pool layers
47-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
48-
* @param[in] in_T number of time steps in the input
49-
* @param[in] in_channels number of input channels. The output will have the same number of channels
50-
51-
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels
52-
* @param[in] var pointer to the variance for the batch normalization, size = in_channels
53-
* @param[in] affine whether the affine operations are applied
54-
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels
55-
* @param[in] beta pointer to the scalar offsets for the post-norm affine operation, size = in_channels
56-
* @param[in] in_place in place computation of the batchnorm. Storage efficient
57-
*
58-
* @param[in] depth_cnn_hidden hidden state/out_channels dimensions for the depth CNN
59-
* @param[in] depth_cnn_padding padding for the depth CNN layer. Note: applied to both sides of the input
48+
* @brief Model definition for the 1D Convolution block applied after the RNN
49+
* @brief sub-layers : custom nonlinearity(semi_sigmoid_tanh) -> batchnorm1d -> conv1d_depth -> conv1d_lr -> avgpool1d
50+
* @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
51+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
52+
* @param[in] in_time number of time steps in the input
53+
* @param[in] in_channels number of input channels
54+
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2
55+
* @param[in] var pointer to the variance for the batch normalization, size = in_channels. Pass NULL/0 for affine_config = 2
56+
* @param[in] affine_config whether the affine operations are applied
57+
* if affine_config = 0, then only mean and var are used
58+
* if affine_config = 1, then mean, var, gamma and beta are used for the final computation.
59+
* if affine_config = 2, then only the gamma and beta are used. gamma = original_gamma/sqrt(var), beta = original_beta - gamma * mean/sqrt(var)
60+
* Note: Use affine_config = 2 for faster calculations. The new gamma and beta would need to be pre-computed, stored and passed
61+
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0
62+
* @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels. Pass NULL/0 for affine_config = 0
63+
* @param[in] in_place in-place computation of the batchnorm. Storage efficient
64+
* @param[in] depth_cnn_padding padding for the depth CNN layer. Note: applied to both sides of the input to the depth CNN
6065
* @param[in] depth_cnn_kernel_size kernel size of the depth CNN
6166
* @param[in] depth_cnn_params weights, bias and other essential parameters used to describe the depth CNN
62-
* @param[in] depth_cnn_activations an integer to choose the type of activation function.
67+
* @param[in] depth_cnn_stride stride factor for the depth CNN
68+
* @param[in] depth_cnn_activation an integer to choose the type of activation function.
6369
* 0: none
6470
* 1: sigmoid
6571
* 2: tanh
6672
* 3: relu
67-
*
68-
* @param[in] point_cnn_hidden hidden state/out_channels dimensions for the point CNN
69-
* @param[in] point_cnn_padding padding for the point CNN layer. Note: applied to both sides of the input
73+
* @param[in] point_cnn_hidden hidden state/out_channels dimensions for the point CNN. The final channel size of this block
74+
* @param[in] point_cnn_padding padding for the point CNN layer. Note: applied to both sides of the input to the point CNN
7075
* @param[in] point_cnn_kernel_size kernel size of the point CNN
7176
* @param[in] point_cnn_params weights, bias and other essential parameters used to describe the point CNN
72-
* @param[in] point_cnn_activations an integer to choose the type of activation function.
77+
* @param[in] point_cnn_stride stride factor for the point CNN
78+
* @param[in] point_cnn_activation an integer to choose the type of activation function.
7379
* 0: none
7480
* 1: sigmoid
7581
* 2: tanh
7682
* 3: relu
77-
*
78-
* @param[in] pool_padding padding for the pool layer. Note: applied to both sides of the input
83+
* @param[in] pool_padding padding for the pool layer. Note: applied to both sides of the input to the pool
7984
* @param[in] pool_kernel_size kernel size of the pool
80-
* @param[in] pool_activations an integer to choose the type of activation function.
85+
* @param[in] pool_stride stride factor for the pool
86+
* @param[in] pool_activation an integer to choose the type of activation function.
8187
* 0: none
8288
* 1: sigmoid
8389
* 2: tanh
8490
* 3: relu
8591
*/
86-
int DSCNN_LR_Point_Depth(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels, float* mean, float* var,
87-
unsigned affine, float* gamma, float* beta, unsigned in_place, unsigned depth_cnn_hidden, int depth_cnn_padding,
88-
unsigned depth_cnn_kernel_size, const void* depth_cnn_params, int depth_cnn_activations, unsigned point_cnn_hidden,
89-
int point_cnn_padding, unsigned point_cnn_kernel_size, const void* point_cnn_params, int point_cnn_activations,
90-
int pool_padding, unsigned pool_kernel_size, int pool_activation);
92+
int phon_pred_depth_point_lr_cnn(float* output_signal, float* input_signal,
93+
conv_layer point_cnn, unsigned in_time, unsigned in_channels,
94+
const float* const mean, const float* const var,
95+
unsigned affine_config, const float* const gamma, const float* const beta, unsigned in_place,
96+
unsigned depth_cnn_padding, unsigned depth_cnn_kernel_size,
97+
const void* depth_cnn_params, unsigned depth_cnn_stride, unsigned depth_cnn_activation,
98+
unsigned point_cnn_hidden, unsigned point_cnn_padding, unsigned point_cnn_kernel_size,
99+
const void* point_cnn_params, unsigned point_cnn_stride, unsigned point_cnn_activation,
100+
unsigned pool_padding, unsigned pool_kernel_size, unsigned pool_stride, unsigned pool_activation);
91101

92-
#endif
102+
#endif

0 commit comments

Comments
 (0)