From 1cc604395342ca0a6160faacf2699a69fe646457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5ns=20Nilsson?= Date: Tue, 23 Feb 2021 11:45:24 +0100 Subject: [PATCH] CMSIS-NN: Change relu to relu6 in pooling unit test * Changing to relu6 to cover both out activation min/max other that the default. * Removing input/output offsets from pooling test data. --- .../TestData/avgpooling/config_data.h | 2 - .../TestData/avgpooling_1/config_data.h | 2 - .../TestData/avgpooling_2/config_data.h | 2 - .../TestData/avgpooling_3/config_data.h | 2 - .../TestData/avgpooling_4/config_data.h | 2 - .../TestCases/TestData/basic/config_data.h | 4 +- .../TestData/conv_1_x_n_1/config_data.h | 4 +- .../TestData/conv_1_x_n_2/config_data.h | 4 +- .../TestData/conv_1_x_n_3/config_data.h | 4 +- .../TestCases/TestData/conv_2/config_data.h | 4 +- .../TestCases/TestData/conv_3/config_data.h | 4 +- .../TestCases/TestData/conv_4/config_data.h | 4 +- .../TestData/depthwise_2/config_data.h | 4 +- .../depthwise_eq_in_out_ch/config_data.h | 4 +- .../depthwise_kernel_3x3/config_data.h | 4 +- .../TestData/fully_connected/config_data.h | 4 +- .../fully_connected_mve_0/config_data.h | 4 +- .../fully_connected_mve_1/config_data.h | 4 +- .../fully_connected_null_bias_0/config_data.h | 4 +- .../TestData/kernel1x1/config_data.h | 4 +- .../TestData/maxpooling/config_data.h | 2 - .../TestData/maxpooling_1/config_data.h | 2 - .../TestData/maxpooling_2/config_data.h | 2 - .../TestData/maxpooling_3/config_data.h | 2 - .../TestData/maxpooling_4/config_data.h | 2 - .../TestData/maxpooling_5/config_data.h | 2 - .../TestData/maxpooling_6/config_data.h | 2 - .../TestData/maxpooling_7/config_data.h | 4 +- .../TestData/maxpooling_7/output_ref_data.h | 2 +- .../TestData/stride2pad1/config_data.h | 4 +- CMSIS/NN/Tests/UnitTest/generate_test_data.py | 40 +++++++++++-------- 31 files changed, 57 insertions(+), 77 deletions(-) diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling/config_data.h index be6c30762a..96be8a63b4 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling/config_data.h @@ -24,8 +24,6 @@ #define AVGPOOLING_INPUT_H 12 #define AVGPOOLING_DST_SIZE 72 #define AVGPOOLING_INPUT_SIZE 2112 -#define AVGPOOLING_INPUT_OFFSET 0 -#define AVGPOOLING_OUTPUT_OFFSET 0 #define AVGPOOLING_OUT_ACTIVATION_MIN -128 #define AVGPOOLING_OUT_ACTIVATION_MAX 127 #define AVGPOOLING_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_1/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_1/config_data.h index a8178ca911..de89287e0d 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_1/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_1/config_data.h @@ -24,8 +24,6 @@ #define AVGPOOLING_1_INPUT_H 5 #define AVGPOOLING_1_DST_SIZE 3 #define AVGPOOLING_1_INPUT_SIZE 135 -#define AVGPOOLING_1_INPUT_OFFSET 0 -#define AVGPOOLING_1_OUTPUT_OFFSET 0 #define AVGPOOLING_1_OUT_ACTIVATION_MIN -128 #define AVGPOOLING_1_OUT_ACTIVATION_MAX 127 #define AVGPOOLING_1_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_2/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_2/config_data.h index 7e9b4f6151..b901dd4311 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_2/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_2/config_data.h @@ -24,8 +24,6 @@ #define AVGPOOLING_2_INPUT_H 1 #define AVGPOOLING_2_DST_SIZE 60 #define AVGPOOLING_2_INPUT_SIZE 60 -#define AVGPOOLING_2_INPUT_OFFSET 0 -#define AVGPOOLING_2_OUTPUT_OFFSET 0 #define AVGPOOLING_2_OUT_ACTIVATION_MIN -128 #define AVGPOOLING_2_OUT_ACTIVATION_MAX 127 #define AVGPOOLING_2_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_3/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_3/config_data.h index 24e8663192..094fc038ba 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_3/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_3/config_data.h @@ -24,8 +24,6 @@ #define AVGPOOLING_3_INPUT_H 1 #define AVGPOOLING_3_DST_SIZE 10 #define AVGPOOLING_3_INPUT_SIZE 18 -#define AVGPOOLING_3_INPUT_OFFSET 0 -#define AVGPOOLING_3_OUTPUT_OFFSET 0 #define AVGPOOLING_3_OUT_ACTIVATION_MIN -128 #define AVGPOOLING_3_OUT_ACTIVATION_MAX 127 #define AVGPOOLING_3_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_4/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_4/config_data.h index f1ae61cfb5..46dfce71cd 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_4/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/avgpooling_4/config_data.h @@ -24,8 +24,6 @@ #define AVGPOOLING_4_INPUT_H 20 #define AVGPOOLING_4_DST_SIZE 14 #define AVGPOOLING_4_INPUT_SIZE 40 -#define AVGPOOLING_4_INPUT_OFFSET 0 -#define AVGPOOLING_4_OUTPUT_OFFSET 0 #define AVGPOOLING_4_OUT_ACTIVATION_MIN -128 #define AVGPOOLING_4_OUT_ACTIVATION_MAX 127 #define AVGPOOLING_4_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/basic/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/basic/config_data.h index 77badcd3fa..53d002b9b8 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/basic/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/basic/config_data.h @@ -24,11 +24,11 @@ #define BASIC_INPUT_H 8 #define BASIC_DST_SIZE 20 #define BASIC_INPUT_SIZE 40 -#define BASIC_INPUT_OFFSET 128 -#define BASIC_OUTPUT_OFFSET 0 #define BASIC_OUT_ACTIVATION_MIN -128 #define BASIC_OUT_ACTIVATION_MAX 127 #define BASIC_INPUT_BATCHES 1 +#define BASIC_INPUT_OFFSET 128 +#define BASIC_OUTPUT_OFFSET 0 #define BASIC_FILTER_X 2 #define BASIC_FILTER_Y 4 #define BASIC_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_1/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_1/config_data.h index e3451cb37b..d91f7f197c 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_1/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_1/config_data.h @@ -24,11 +24,11 @@ #define CONV_1_X_N_1_INPUT_H 5 #define CONV_1_X_N_1_DST_SIZE 60 #define CONV_1_X_N_1_INPUT_SIZE 75 -#define CONV_1_X_N_1_INPUT_OFFSET 0 -#define CONV_1_X_N_1_OUTPUT_OFFSET 0 #define CONV_1_X_N_1_OUT_ACTIVATION_MIN -128 #define CONV_1_X_N_1_OUT_ACTIVATION_MAX 127 #define CONV_1_X_N_1_INPUT_BATCHES 2 +#define CONV_1_X_N_1_INPUT_OFFSET 0 +#define CONV_1_X_N_1_OUTPUT_OFFSET 0 #define CONV_1_X_N_1_FILTER_X 2 #define CONV_1_X_N_1_FILTER_Y 1 #define CONV_1_X_N_1_STRIDE_X 2 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_2/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_2/config_data.h index e7fd086c5e..247d09ef59 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_2/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_2/config_data.h @@ -24,11 +24,11 @@ #define CONV_1_X_N_2_INPUT_H 11 #define CONV_1_X_N_2_DST_SIZE 121 #define CONV_1_X_N_2_INPUT_SIZE 363 -#define CONV_1_X_N_2_INPUT_OFFSET 0 -#define CONV_1_X_N_2_OUTPUT_OFFSET 0 #define CONV_1_X_N_2_OUT_ACTIVATION_MIN -128 #define CONV_1_X_N_2_OUT_ACTIVATION_MAX 127 #define CONV_1_X_N_2_INPUT_BATCHES 1 +#define CONV_1_X_N_2_INPUT_OFFSET 0 +#define CONV_1_X_N_2_OUTPUT_OFFSET 0 #define CONV_1_X_N_2_FILTER_X 11 #define CONV_1_X_N_2_FILTER_Y 1 #define CONV_1_X_N_2_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_3/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_3/config_data.h index 7e134eb927..121598841b 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_3/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_1_x_n_3/config_data.h @@ -24,11 +24,11 @@ #define CONV_1_X_N_3_INPUT_H 11 #define CONV_1_X_N_3_DST_SIZE 363 #define CONV_1_X_N_3_INPUT_SIZE 121 -#define CONV_1_X_N_3_INPUT_OFFSET 0 -#define CONV_1_X_N_3_OUTPUT_OFFSET 0 #define CONV_1_X_N_3_OUT_ACTIVATION_MIN -128 #define CONV_1_X_N_3_OUT_ACTIVATION_MAX 127 #define CONV_1_X_N_3_INPUT_BATCHES 1 +#define CONV_1_X_N_3_INPUT_OFFSET 0 +#define CONV_1_X_N_3_OUTPUT_OFFSET 0 #define CONV_1_X_N_3_FILTER_X 1 #define CONV_1_X_N_3_FILTER_Y 11 #define CONV_1_X_N_3_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_2/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_2/config_data.h index 6b23d708b7..d87244c5fb 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_2/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_2/config_data.h @@ -24,11 +24,11 @@ #define CONV_2_INPUT_H 3 #define CONV_2_DST_SIZE 72 #define CONV_2_INPUT_SIZE 36 -#define CONV_2_INPUT_OFFSET 128 -#define CONV_2_OUTPUT_OFFSET -1 #define CONV_2_OUT_ACTIVATION_MIN -128 #define CONV_2_OUT_ACTIVATION_MAX 127 #define CONV_2_INPUT_BATCHES 1 +#define CONV_2_INPUT_OFFSET 128 +#define CONV_2_OUTPUT_OFFSET -1 #define CONV_2_FILTER_X 3 #define CONV_2_FILTER_Y 3 #define CONV_2_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_3/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_3/config_data.h index 4a37457000..44fb4b3d50 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_3/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_3/config_data.h @@ -24,11 +24,11 @@ #define CONV_3_INPUT_H 49 #define CONV_3_DST_SIZE 250 #define CONV_3_INPUT_SIZE 1470 -#define CONV_3_INPUT_OFFSET 0 -#define CONV_3_OUTPUT_OFFSET 0 #define CONV_3_OUT_ACTIVATION_MIN -128 #define CONV_3_OUT_ACTIVATION_MAX 127 #define CONV_3_INPUT_BATCHES 1 +#define CONV_3_INPUT_OFFSET 0 +#define CONV_3_OUTPUT_OFFSET 0 #define CONV_3_FILTER_X 4 #define CONV_3_FILTER_Y 10 #define CONV_3_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_4/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_4/config_data.h index d21379ce0d..c92270ffc3 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_4/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/conv_4/config_data.h @@ -24,11 +24,11 @@ #define CONV_4_INPUT_H 5 #define CONV_4_DST_SIZE 36 #define CONV_4_INPUT_SIZE 75 -#define CONV_4_INPUT_OFFSET 0 -#define CONV_4_OUTPUT_OFFSET 0 #define CONV_4_OUT_ACTIVATION_MIN -128 #define CONV_4_OUT_ACTIVATION_MAX 127 #define CONV_4_INPUT_BATCHES 3 +#define CONV_4_INPUT_OFFSET 0 +#define CONV_4_OUTPUT_OFFSET 0 #define CONV_4_FILTER_X 2 #define CONV_4_FILTER_Y 3 #define CONV_4_STRIDE_X 2 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_2/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_2/config_data.h index 6a9016155d..14c191b88e 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_2/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_2/config_data.h @@ -24,11 +24,11 @@ #define DEPTHWISE_2_INPUT_H 5 #define DEPTHWISE_2_DST_SIZE 81 #define DEPTHWISE_2_INPUT_SIZE 90 -#define DEPTHWISE_2_INPUT_OFFSET 0 -#define DEPTHWISE_2_OUTPUT_OFFSET -1 #define DEPTHWISE_2_OUT_ACTIVATION_MIN -128 #define DEPTHWISE_2_OUT_ACTIVATION_MAX 127 #define DEPTHWISE_2_INPUT_BATCHES 1 +#define DEPTHWISE_2_INPUT_OFFSET 0 +#define DEPTHWISE_2_OUTPUT_OFFSET -1 #define DEPTHWISE_2_FILTER_X 3 #define DEPTHWISE_2_FILTER_Y 4 #define DEPTHWISE_2_STRIDE_X 2 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_eq_in_out_ch/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_eq_in_out_ch/config_data.h index ba20158e6a..1aa019c179 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_eq_in_out_ch/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_eq_in_out_ch/config_data.h @@ -24,11 +24,11 @@ #define DEPTHWISE_EQ_IN_OUT_CH_INPUT_H 5 #define DEPTHWISE_EQ_IN_OUT_CH_DST_SIZE 120 #define DEPTHWISE_EQ_IN_OUT_CH_INPUT_SIZE 120 -#define DEPTHWISE_EQ_IN_OUT_CH_INPUT_OFFSET 0 -#define DEPTHWISE_EQ_IN_OUT_CH_OUTPUT_OFFSET -1 #define DEPTHWISE_EQ_IN_OUT_CH_OUT_ACTIVATION_MIN -128 #define DEPTHWISE_EQ_IN_OUT_CH_OUT_ACTIVATION_MAX 127 #define DEPTHWISE_EQ_IN_OUT_CH_INPUT_BATCHES 1 +#define DEPTHWISE_EQ_IN_OUT_CH_INPUT_OFFSET 0 +#define DEPTHWISE_EQ_IN_OUT_CH_OUTPUT_OFFSET -1 #define DEPTHWISE_EQ_IN_OUT_CH_FILTER_X 2 #define DEPTHWISE_EQ_IN_OUT_CH_FILTER_Y 3 #define DEPTHWISE_EQ_IN_OUT_CH_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_kernel_3x3/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_kernel_3x3/config_data.h index 9499d1ec5c..e7d6fc0a04 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_kernel_3x3/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/depthwise_kernel_3x3/config_data.h @@ -24,11 +24,11 @@ #define DEPTHWISE_KERNEL_3X3_INPUT_H 5 #define DEPTHWISE_KERNEL_3X3_DST_SIZE 30 #define DEPTHWISE_KERNEL_3X3_INPUT_SIZE 100 -#define DEPTHWISE_KERNEL_3X3_INPUT_OFFSET 0 -#define DEPTHWISE_KERNEL_3X3_OUTPUT_OFFSET -1 #define DEPTHWISE_KERNEL_3X3_OUT_ACTIVATION_MIN -128 #define DEPTHWISE_KERNEL_3X3_OUT_ACTIVATION_MAX 127 #define DEPTHWISE_KERNEL_3X3_INPUT_BATCHES 1 +#define DEPTHWISE_KERNEL_3X3_INPUT_OFFSET 0 +#define DEPTHWISE_KERNEL_3X3_OUTPUT_OFFSET -1 #define DEPTHWISE_KERNEL_3X3_FILTER_X 3 #define DEPTHWISE_KERNEL_3X3_FILTER_Y 3 #define DEPTHWISE_KERNEL_3X3_STRIDE_X 2 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected/config_data.h index 984383ffeb..c655b1db8e 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected/config_data.h @@ -24,11 +24,11 @@ #define FULLY_CONNECTED_INPUT_H 1 #define FULLY_CONNECTED_DST_SIZE 18 #define FULLY_CONNECTED_INPUT_SIZE 20 -#define FULLY_CONNECTED_INPUT_OFFSET 50 -#define FULLY_CONNECTED_OUTPUT_OFFSET -2 #define FULLY_CONNECTED_OUT_ACTIVATION_MIN -128 #define FULLY_CONNECTED_OUT_ACTIVATION_MAX 127 #define FULLY_CONNECTED_INPUT_BATCHES 3 +#define FULLY_CONNECTED_INPUT_OFFSET 50 +#define FULLY_CONNECTED_OUTPUT_OFFSET -2 #define FULLY_CONNECTED_WEIGHTS_OFFSET 22 #define FULLY_CONNECTED_OUTPUT_MULTIPLIER 1073741824 #define FULLY_CONNECTED_OUTPUT_SHIFT 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_0/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_0/config_data.h index a55a114145..ca905cf849 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_0/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_0/config_data.h @@ -24,11 +24,11 @@ #define FULLY_CONNECTED_MVE_0_INPUT_H 1 #define FULLY_CONNECTED_MVE_0_DST_SIZE 9 #define FULLY_CONNECTED_MVE_0_INPUT_SIZE 16 -#define FULLY_CONNECTED_MVE_0_INPUT_OFFSET 3 -#define FULLY_CONNECTED_MVE_0_OUTPUT_OFFSET -2 #define FULLY_CONNECTED_MVE_0_OUT_ACTIVATION_MIN -128 #define FULLY_CONNECTED_MVE_0_OUT_ACTIVATION_MAX 127 #define FULLY_CONNECTED_MVE_0_INPUT_BATCHES 1 +#define FULLY_CONNECTED_MVE_0_INPUT_OFFSET 3 +#define FULLY_CONNECTED_MVE_0_OUTPUT_OFFSET -2 #define FULLY_CONNECTED_MVE_0_WEIGHTS_OFFSET 0 #define FULLY_CONNECTED_MVE_0_OUTPUT_MULTIPLIER 1073741824 #define FULLY_CONNECTED_MVE_0_OUTPUT_SHIFT 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_1/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_1/config_data.h index e70f48075d..273161886b 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_1/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_mve_1/config_data.h @@ -24,11 +24,11 @@ #define FULLY_CONNECTED_MVE_1_INPUT_H 1 #define FULLY_CONNECTED_MVE_1_DST_SIZE 4 #define FULLY_CONNECTED_MVE_1_INPUT_SIZE 20 -#define FULLY_CONNECTED_MVE_1_INPUT_OFFSET 1 -#define FULLY_CONNECTED_MVE_1_OUTPUT_OFFSET 3 #define FULLY_CONNECTED_MVE_1_OUT_ACTIVATION_MIN -128 #define FULLY_CONNECTED_MVE_1_OUT_ACTIVATION_MAX 127 #define FULLY_CONNECTED_MVE_1_INPUT_BATCHES 1 +#define FULLY_CONNECTED_MVE_1_INPUT_OFFSET 1 +#define FULLY_CONNECTED_MVE_1_OUTPUT_OFFSET 3 #define FULLY_CONNECTED_MVE_1_WEIGHTS_OFFSET -3 #define FULLY_CONNECTED_MVE_1_OUTPUT_MULTIPLIER 1073741824 #define FULLY_CONNECTED_MVE_1_OUTPUT_SHIFT 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_null_bias_0/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_null_bias_0/config_data.h index 0c3ef68051..68b3c18a76 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_null_bias_0/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/fully_connected_null_bias_0/config_data.h @@ -24,11 +24,11 @@ #define FULLY_CONNECTED_NULL_BIAS_0_INPUT_H 1 #define FULLY_CONNECTED_NULL_BIAS_0_DST_SIZE 10 #define FULLY_CONNECTED_NULL_BIAS_0_INPUT_SIZE 33 -#define FULLY_CONNECTED_NULL_BIAS_0_INPUT_OFFSET 1 -#define FULLY_CONNECTED_NULL_BIAS_0_OUTPUT_OFFSET 0 #define FULLY_CONNECTED_NULL_BIAS_0_OUT_ACTIVATION_MIN -128 #define FULLY_CONNECTED_NULL_BIAS_0_OUT_ACTIVATION_MAX 127 #define FULLY_CONNECTED_NULL_BIAS_0_INPUT_BATCHES 2 +#define FULLY_CONNECTED_NULL_BIAS_0_INPUT_OFFSET 1 +#define FULLY_CONNECTED_NULL_BIAS_0_OUTPUT_OFFSET 0 #define FULLY_CONNECTED_NULL_BIAS_0_WEIGHTS_OFFSET -3 #define FULLY_CONNECTED_NULL_BIAS_0_OUTPUT_MULTIPLIER 1073741824 #define FULLY_CONNECTED_NULL_BIAS_0_OUTPUT_SHIFT 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/kernel1x1/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/kernel1x1/config_data.h index 5591f27653..c26d64ce6c 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/kernel1x1/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/kernel1x1/config_data.h @@ -24,11 +24,11 @@ #define KERNEL1X1_INPUT_H 15 #define KERNEL1X1_DST_SIZE 3825 #define KERNEL1X1_INPUT_SIZE 900 -#define KERNEL1X1_INPUT_OFFSET 128 -#define KERNEL1X1_OUTPUT_OFFSET -1 #define KERNEL1X1_OUT_ACTIVATION_MIN -128 #define KERNEL1X1_OUT_ACTIVATION_MAX 127 #define KERNEL1X1_INPUT_BATCHES 1 +#define KERNEL1X1_INPUT_OFFSET 128 +#define KERNEL1X1_OUTPUT_OFFSET -1 #define KERNEL1X1_FILTER_X 1 #define KERNEL1X1_FILTER_Y 1 #define KERNEL1X1_STRIDE_X 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling/config_data.h index 82e03292c3..6b4bd64074 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_INPUT_H 12 #define MAXPOOLING_DST_SIZE 72 #define MAXPOOLING_INPUT_SIZE 2112 -#define MAXPOOLING_INPUT_OFFSET 0 -#define MAXPOOLING_OUTPUT_OFFSET 0 #define MAXPOOLING_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_1/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_1/config_data.h index b538076ddb..88d1f92f1b 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_1/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_1/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_1_INPUT_H 5 #define MAXPOOLING_1_DST_SIZE 3 #define MAXPOOLING_1_INPUT_SIZE 135 -#define MAXPOOLING_1_INPUT_OFFSET 0 -#define MAXPOOLING_1_OUTPUT_OFFSET 0 #define MAXPOOLING_1_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_1_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_1_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_2/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_2/config_data.h index f22d6f10d1..f0f26005a5 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_2/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_2/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_2_INPUT_H 1 #define MAXPOOLING_2_DST_SIZE 60 #define MAXPOOLING_2_INPUT_SIZE 60 -#define MAXPOOLING_2_INPUT_OFFSET 0 -#define MAXPOOLING_2_OUTPUT_OFFSET 0 #define MAXPOOLING_2_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_2_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_2_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_3/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_3/config_data.h index 4e0e391b1c..4bf5b8393f 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_3/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_3/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_3_INPUT_H 1 #define MAXPOOLING_3_DST_SIZE 10 #define MAXPOOLING_3_INPUT_SIZE 18 -#define MAXPOOLING_3_INPUT_OFFSET 0 -#define MAXPOOLING_3_OUTPUT_OFFSET 0 #define MAXPOOLING_3_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_3_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_3_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_4/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_4/config_data.h index 4afc3857ca..4f94d88bcd 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_4/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_4/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_4_INPUT_H 20 #define MAXPOOLING_4_DST_SIZE 14 #define MAXPOOLING_4_INPUT_SIZE 40 -#define MAXPOOLING_4_INPUT_OFFSET 0 -#define MAXPOOLING_4_OUTPUT_OFFSET 0 #define MAXPOOLING_4_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_4_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_4_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_5/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_5/config_data.h index 3f68c4962d..763f162fef 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_5/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_5/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_5_INPUT_H 1 #define MAXPOOLING_5_DST_SIZE 20 #define MAXPOOLING_5_INPUT_SIZE 20 -#define MAXPOOLING_5_INPUT_OFFSET 0 -#define MAXPOOLING_5_OUTPUT_OFFSET 0 #define MAXPOOLING_5_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_5_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_5_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_6/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_6/config_data.h index e1017dce43..4e3c147040 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_6/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_6/config_data.h @@ -24,8 +24,6 @@ #define MAXPOOLING_6_INPUT_H 5 #define MAXPOOLING_6_DST_SIZE 34 #define MAXPOOLING_6_INPUT_SIZE 85 -#define MAXPOOLING_6_INPUT_OFFSET 0 -#define MAXPOOLING_6_OUTPUT_OFFSET 0 #define MAXPOOLING_6_OUT_ACTIVATION_MIN -128 #define MAXPOOLING_6_OUT_ACTIVATION_MAX 127 #define MAXPOOLING_6_INPUT_BATCHES 1 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/config_data.h index 4e592b87fc..83341d0cb5 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/config_data.h @@ -24,10 +24,8 @@ #define MAXPOOLING_7_INPUT_H 2 #define MAXPOOLING_7_DST_SIZE 2 #define MAXPOOLING_7_INPUT_SIZE 8 -#define MAXPOOLING_7_INPUT_OFFSET -128 -#define MAXPOOLING_7_OUTPUT_OFFSET 0 #define MAXPOOLING_7_OUT_ACTIVATION_MIN 0 -#define MAXPOOLING_7_OUT_ACTIVATION_MAX 127 +#define MAXPOOLING_7_OUT_ACTIVATION_MAX 6 #define MAXPOOLING_7_INPUT_BATCHES 1 #define MAXPOOLING_7_FILTER_X 2 #define MAXPOOLING_7_FILTER_Y 2 diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/output_ref_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/output_ref_data.h index 0a17603d24..bd34bc945a 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/output_ref_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/maxpooling_7/output_ref_data.h @@ -20,4 +20,4 @@ #pragma once #include -const int8_t maxpooling_7_output_ref[2] = {0, 23}; +const int8_t maxpooling_7_output_ref[2] = {0, 6}; diff --git a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/stride2pad1/config_data.h b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/stride2pad1/config_data.h index dfdef15813..4f24c34fa2 100644 --- a/CMSIS/NN/Tests/UnitTest/TestCases/TestData/stride2pad1/config_data.h +++ b/CMSIS/NN/Tests/UnitTest/TestCases/TestData/stride2pad1/config_data.h @@ -24,11 +24,11 @@ #define STRIDE2PAD1_INPUT_H 7 #define STRIDE2PAD1_DST_SIZE 16 #define STRIDE2PAD1_INPUT_SIZE 49 -#define STRIDE2PAD1_INPUT_OFFSET 128 -#define STRIDE2PAD1_OUTPUT_OFFSET 0 #define STRIDE2PAD1_OUT_ACTIVATION_MIN -128 #define STRIDE2PAD1_OUT_ACTIVATION_MAX 127 #define STRIDE2PAD1_INPUT_BATCHES 1 +#define STRIDE2PAD1_INPUT_OFFSET 128 +#define STRIDE2PAD1_OUTPUT_OFFSET 0 #define STRIDE2PAD1_FILTER_X 3 #define STRIDE2PAD1_FILTER_Y 3 #define STRIDE2PAD1_STRIDE_X 2 diff --git a/CMSIS/NN/Tests/UnitTest/generate_test_data.py b/CMSIS/NN/Tests/UnitTest/generate_test_data.py index 9f2c934657..819c4347d1 100755 --- a/CMSIS/NN/Tests/UnitTest/generate_test_data.py +++ b/CMSIS/NN/Tests/UnitTest/generate_test_data.py @@ -97,7 +97,7 @@ class TestSettings(ABC): UINT8_MIN = 0 def __init__(self, dataset, testtype, args, in_ch, out_ch, x_in, y_in, w_x, w_y, stride_x, stride_y, pad, randmin, - randmax, outminrange=-128, outmaxrange=127, batches=1, generate_bias=True, relu=False): + randmax, outminrange=-128, outmaxrange=127, batches=1, generate_bias=True, relu6=False): self.tensor_flow_reference_version = ("// Generated by {} using TFL version {} as reference.\n". format(os.path.basename(__file__), tf.__version__)) @@ -106,7 +106,7 @@ def __init__(self, dataset, testtype, args, in_ch, out_ch, x_in, y_in, w_x, w_y, self.mins = randmin self.maxs = randmax - self.relu = relu + self.relu6 = relu6 self.input_ch = in_ch self.output_ch = out_ch self.x_input = x_in @@ -317,6 +317,15 @@ def write_common_config(self, f, prefix): f.write("#define {}_OUTPUT_W {}\n".format(prefix, self.x_output)) f.write("#define {}_OUTPUT_H {}\n".format(prefix, self.y_output)) + def write_c_common_header(self, f): + f.write("{}\n\n".format(LICENSE)) + f.write(self.tensor_flow_reference_version) + f.write("#pragma once\n") + + def write_c_header_offsets(self, f, prefix): + f.write("#define {}_INPUT_OFFSET {}\n".format(prefix, -self.input_zero_point)) + f.write("#define {}_OUTPUT_OFFSET {}\n".format(prefix, self.output_zero_point)) + def write_c_config_header(self): filename = self.config_data @@ -327,9 +336,7 @@ def write_c_config_header(self): print("Writing C header with config data {}...".format(filepath)) with open(filepath, "w+") as f: - f.write("{}\n\n".format(LICENSE)) - f.write(self.tensor_flow_reference_version) - f.write("#pragma once\n") + self.write_c_common_header(f) f.write("#define {}_OUT_CH {}\n".format(prefix, self.output_ch)) f.write("#define {}_IN_CH {}\n".format(prefix, self.input_ch)) f.write("#define {}_INPUT_W {}\n".format(prefix, self.x_input)) @@ -337,13 +344,12 @@ def write_c_config_header(self): f.write("#define {}_DST_SIZE {}\n".format(prefix, self.x_output * self.y_output * self.output_ch * self.batches)) f.write("#define {}_INPUT_SIZE {}\n".format(prefix, self.x_input * self.y_input * self.input_ch)) - f.write("#define {}_INPUT_OFFSET {}\n".format(prefix, -self.input_zero_point)) - f.write("#define {}_OUTPUT_OFFSET {}\n".format(prefix, self.output_zero_point)) - if self.relu: + if self.relu6: f.write("#define {}_OUT_ACTIVATION_MIN {}\n".format(prefix, 0)) + f.write("#define {}_OUT_ACTIVATION_MAX {}\n".format(prefix, 6)) else: f.write("#define {}_OUT_ACTIVATION_MIN {}\n".format(prefix, self.INT8_MIN)) - f.write("#define {}_OUT_ACTIVATION_MAX {}\n".format(prefix, self.INT8_MAX)) + f.write("#define {}_OUT_ACTIVATION_MAX {}\n".format(prefix, self.INT8_MAX)) f.write("#define {}_INPUT_BATCHES {}\n".format(prefix, self.batches)) self.format_output_file(filepath) @@ -366,9 +372,7 @@ def generate_c_array(self, name, array, datatype="q7_t"): print("Generating C header {}...".format(filepath)) with open(filepath, "w+") as f: - f.write("{}\n\n".format(LICENSE)) - f.write(self.tensor_flow_reference_version) - f.write("#pragma once\n") + self.write_c_common_header(f) f.write("#include \n\n") f.write("const " + datatype + " " + self.testdataset + '_' + name + "[%d] =\n{\n" % size) for i in range(size - 1): @@ -477,6 +481,7 @@ def write_c_config_header(self): prefix = self.testdataset.upper() with open(filepath, "a") as f: + self.write_c_header_offsets(f, prefix) self.write_common_config(f, prefix) if self.test_type == 'depthwise_conv': f.write("#define {}_CH_MULT {}\n".format(prefix, self.channel_multiplier)) @@ -625,9 +630,9 @@ def generate_data(self, input_data=None, weights=None, biases=None): class PoolingSettings(TestSettings): def __init__(self, dataset, testtype, args, randmin=-7, randmax=7, channels=8, x_in=4, y_in=4, w_x=4, w_y=4, - stride_x=1, stride_y=1, batches=1, pad=False, relu=False): + stride_x=1, stride_y=1, batches=1, pad=False, relu6=False): super().__init__(dataset, testtype, args, channels, channels, x_in, y_in, w_x, w_y, stride_x, stride_y, pad, - randmin, randmax, relu=relu) + randmin, randmax, relu6=relu6) def generate_data(self, input_data=None): input_data = self.get_randomized_input_data(input_data) @@ -672,8 +677,8 @@ def max_pooling(self, x): ksize=[1, self.filter_y, self.filter_x, 1], strides=[1, self.stride_y, self.stride_x, 1], padding=self.padding) - if self.relu: - return tf.nn.relu(maxpool) + if self.relu6: + return tf.nn.relu6(maxpool) else: return maxpool @@ -708,6 +713,7 @@ def write_c_config_header(self): prefix = self.testdataset.upper() with open(filepath, "a") as f: + self.write_c_header_offsets(f, prefix) f.write("#define {}_WEIGHTS_OFFSET {}\n".format(prefix, -self.weights_zero_point)) f.write("#define {}_OUTPUT_MULTIPLIER {}\n".format(prefix, self.quantized_multiplier)) f.write("#define {}_OUTPUT_SHIFT {}\n".format(prefix, self.quantized_shift)) @@ -874,7 +880,7 @@ def load_all_testdatasets(): dataset = 'maxpooling_7' ALL_TESTDATA_SETS[dataset] = PoolingSettings(dataset, type_of_test, args, channels=1, x_in=4, y_in=2, stride_x=2, stride_y=2, w_x=2, w_y=2, pad=False, randmin=-20, randmax=-5, - relu=True) + relu6=True) if __name__ == '__main__':