Skip to content

Commit 073d1da

Browse files
Changed stddev to var and added affine params to BatchNorm
1 parent dd9be5e commit 073d1da

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

c_reference/include/conv1d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ int AvgPool1D(float *output_signal, unsigned out_T, const float *input_signal, u
5858
int padding, unsigned kernel_size, int activations);
5959

6060
int BatchNorm1d(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels,
61-
float* mean, float* stddev, unsigned in_place);
61+
float* mean, float* var, unsigned affine, float* gamma , float * beta, unsigned in_place);
6262
#endif

c_reference/src/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ include ../config.mk
66
INCLUDE_DIR=../include
77
IFLAGS = -I $(INCLUDE_DIR)
88

9-
all: conv1d.o conv_utils.o utils.o fastgrnn.o classifier.o rnnpool.o quantized_utils.o quantized_fastgrnn.o quantized_rnnpool.o quantized_mbconv.o
9+
all: dscnn.o conv1d.o conv_utils.o utils.o fastgrnn.o classifier.o rnnpool.o quantized_utils.o quantized_fastgrnn.o quantized_rnnpool.o quantized_mbconv.o
10+
11+
dscnn.o : dscnn.c
12+
$(CC) -o $@ $(IFLAGS) $(CFLAGS) -c $^
1013

1114
conv_utils.o : conv_utils.c
1215
$(CC) -o $@ $(IFLAGS) $(CFLAGS) -c $^

c_reference/src/conv1d.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,36 @@ int AvgPool1D(float *output_signal, unsigned out_T, const float *input_signal, u
211211
}
212212

213213
int BatchNorm1d(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels,
214-
float* mean, float* stddev, unsigned in_place){
215-
if(in_place){
216-
for(int t = 0; t < in_T ; t++){
217-
for(int d = 0 ; d < in_channels ; d++){
218-
input_signal[t * in_channels + d] = (input_signal[t * in_channels + d] - mean[d])/stddev[d];
214+
float* mean, float* var, unsigned affine, float* gamma , float * beta, unsigned in_place){
215+
if(affine){
216+
if(in_place){
217+
for(int t = 0; t < in_T ; t++){
218+
for(int d = 0 ; d < in_channels ; d++){
219+
input_signal[t * in_channels + d] = gamma[d]*((input_signal[t * in_channels + d] - mean[d])/sqrt(var[d])) + beta[d];
220+
}
221+
}
222+
}
223+
else{
224+
for(int t = 0; t < in_T ; t++){
225+
for(int d = 0 ; d < in_channels ; d++){
226+
output_signal[t * in_channels + d] = gamma[d]*((input_signal[t * in_channels + d] - mean[d])/sqrt(var[d])) + beta[d];
227+
}
219228
}
220229
}
221230
}
222231
else{
223-
for(int t = 0; t < in_T ; t++){
224-
for(int d = 0 ; d < in_channels ; d++){
225-
output_signal[t * in_channels + d] = (input_signal[t * in_channels + d] - mean[d])/stddev[d];
232+
if(in_place){
233+
for(int t = 0; t < in_T ; t++){
234+
for(int d = 0 ; d < in_channels ; d++){
235+
input_signal[t * in_channels + d] = ((input_signal[t * in_channels + d] - mean[d])/sqrt(var[d]));
236+
}
237+
}
238+
}
239+
else{
240+
for(int t = 0; t < in_T ; t++){
241+
for(int d = 0 ; d < in_channels ; d++){
242+
output_signal[t * in_channels + d] = ((input_signal[t * in_channels + d] - mean[d])/sqrt(var[d]));
243+
}
226244
}
227245
}
228246
}

c_reference/tests/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ INCLUDE_DIR=../include
77
SRC_DIR=../src
88
IFLAGS = -I $(INCLUDE_DIR)
99

10-
all: test_avg_pool test_conv1d test_conv1d_depth test_conv1d_lr test_conv1d_lr_depth test_fastgrnn_lr test_rnnpool test_quantized_utils test_quantized_fastgrnn test_quantized_rnnpool test_quantized_mbconv
10+
all: test_avg_pool test_conv1d test_conv1d_depth test_conv1d_lr test_conv1d_lr_depth test_dscnn_lr test_fastgrnn_lr test_rnnpool test_quantized_utils test_quantized_fastgrnn test_quantized_rnnpool test_quantized_mbconv
11+
12+
DSCNN_DIR=dscnn
13+
test_dscnn_lr: $(DSCNN_DIR)/test_dscnn_lr.c $(SRC_DIR)/conv_utils.o $(SRC_DIR)/conv1d.o $(SRC_DIR)/dscnn.o
14+
$(CC) -o $@ $^ $(IFLAGS) $(CFLAGS) -lm
1115

1216
CONV1D_DIR=conv1d
1317
test_conv1d: $(CONV1D_DIR)/conv1d_regular/test_conv1d.c $(SRC_DIR)/conv_utils.o $(SRC_DIR)/conv1d.o
@@ -44,7 +48,7 @@ test_quantized_mbconv: $(MBCONV_DIR)/test_quantized_mbconv.c $(SRC_DIR)/quantize
4448
.PHONY: clean cleanest
4549

4650
clean:
47-
rm -f *.o *.gch test_avg_pool test_conv1d test_conv1d_depth test_conv1d_lr test_conv1d_lr_depth test_fastgrnn_lr test_rnnpool test_quantized_utils test_quantized_fastgrnn test_quantized_rnnpool test_quantized_mbconv
51+
rm -f *.o *.gch test_avg_pool test_conv1d test_conv1d_depth test_conv1d_lr test_conv1d_lr_depth test_dscnn_lr test_fastgrnn_lr test_rnnpool test_quantized_utils test_quantized_fastgrnn test_quantized_rnnpool test_quantized_mbconv
4852

4953
cleanest: clean
5054
rm *~

0 commit comments

Comments
 (0)