From 45537c741d60370800e20d4205c3ac8ea9f021fd Mon Sep 17 00:00:00 2001 From: Wang Wang Wang Date: Thu, 8 Aug 2019 18:06:41 +0800 Subject: [PATCH] Update README && *.h of libs --- {main => lib}/Kconfig | 0 lib/include/dl_lib.h | 13 ++++++++ lib/include/dl_lib_coefgetter_if.h | 13 ++++++++ lib/include/dl_lib_conv_queue.h | 13 ++++++++ lib/include/dl_lib_convq_queue.h | 50 ++++++++++++++++------------ lib/include/dl_lib_matrix.h | 13 ++++++++ lib/include/dl_lib_matrixq.h | 13 ++++++++ main/multinet_test.c | 4 +-- main/wakenet_test.c | 1 - speech_command_recognition/README.md | 2 +- 10 files changed, 95 insertions(+), 27 deletions(-) rename {main => lib}/Kconfig (100%) diff --git a/main/Kconfig b/lib/Kconfig similarity index 100% rename from main/Kconfig rename to lib/Kconfig diff --git a/lib/include/dl_lib.h b/lib/include/dl_lib.h index d1c644b..f18beea 100644 --- a/lib/include/dl_lib.h +++ b/lib/include/dl_lib.h @@ -1,3 +1,16 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef DL_LIB_H #define DL_LIB_H diff --git a/lib/include/dl_lib_coefgetter_if.h b/lib/include/dl_lib_coefgetter_if.h index 7e1b04c..53210a5 100644 --- a/lib/include/dl_lib_coefgetter_if.h +++ b/lib/include/dl_lib_coefgetter_if.h @@ -1,3 +1,16 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef DL_LIB_COEFGETTER_IF_H #define DL_LIB_COEFGETTER_IF_H diff --git a/lib/include/dl_lib_conv_queue.h b/lib/include/dl_lib_conv_queue.h index 1e70824..e0ca0a1 100644 --- a/lib/include/dl_lib_conv_queue.h +++ b/lib/include/dl_lib_conv_queue.h @@ -1,3 +1,16 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef DL_LIB_CONV_QUEUE_H #define DL_LIB_CONV_QUEUE_H diff --git a/lib/include/dl_lib_convq_queue.h b/lib/include/dl_lib_convq_queue.h index 4c1b1f4..20fc667 100644 --- a/lib/include/dl_lib_convq_queue.h +++ b/lib/include/dl_lib_convq_queue.h @@ -1,3 +1,16 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef DL_LIB_CONVQ_QUEUE_H #define DL_LIB_CONVQ_QUEUE_H @@ -24,7 +37,7 @@ typedef struct { */ dl_convq_queue_t *dl_convq_queue_alloc(int n, int c); -void dl_convq_to_matrix2dq(dl_convq_queue_t *cq, dl_matrix2dq_t* out); +void dl_convq_to_matrix2dq(dl_convq_queue_t *cq, dl_matrix2dq_t* out, int row); /** * @brief Free a fixed-point convolution queue @@ -70,18 +83,6 @@ void dl_convq_queue_push_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, i */ qtp_t *dl_get_queue_itemq(dl_convq_queue_t *cq, int offset); -/** - * @brief Does a sigmoid operation on the one of element in the convolution queue. - * Gets the pointer of element in the convolution queue by offset, and does a - * sigmoid operation by this pointer, then return the pointer - * - * @param cq Input fixed-point convolution queue - * @param offset Offset from the front of the queue - * @return Pointer of the element - */ -qtp_t *dl_sigmoid_step_q(dl_convq_queue_t *cq, int offset); -void dl_tanh_convq(dl_convq_queue_t *cq, int last_num); - /** * @brief Does a tanh operation on the one of element in the convolution queue. * Gets the pointer of element in the convolution queue by offset, and does a @@ -91,8 +92,19 @@ void dl_tanh_convq(dl_convq_queue_t *cq, int last_num); * @param offset Offset from the front of the queue * @return Pointer of the element */ -qtp_t *dl_tanh_step_q(dl_convq_queue_t *cq, int offset); -qtp_t *dl_relu_step_q(dl_convq_queue_t *cq, fptp_t clip, int offset); +void dl_tanh_convq(dl_convq_queue_t *cq, int last_num); + +/** + * @brief Does a relu operation on the one of element in the convolution queue. + * Gets the pointer of element in the convolution queue by offset, and does a + * relu operation by this pointer, then return the pointer + * + * @param cq Input fixed-point convolution queue + * @param offset Offset from the front of the queue + * @return Pointer of the element + */ +void dl_relu_convq(dl_convq_queue_t *cq, fptp_t clip, int last_num); + /** * @brief Does a softmax operation on the one of element in the convolution queue. * Gets the pointer of element in the convolution queue by offset, input data @@ -121,8 +133,6 @@ fptp_t * dl_softmax_step_q(dl_convq_queue_t *cq, int offset, fptp_t *out); * @param shift Shift ratio used in dot operation between two 16-bit fixed point vector * @return The result of atrous convolution */ -qtp_t *dl_atrous_conv1dq_step(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, - dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int shift); qtp_t *dl_atrous_conv1dq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int shift); /** @@ -147,17 +157,13 @@ qtp_t *dl_atrous_conv1dq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, * @gate_shift Shift ratio used in gate operation between two 16-bit fixed point vector * @return The result of dilation layer */ -qtp_t *dl_dilation_layerq_step(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, - dl_matrix2dq_t* filter_kernel, dl_matrix2dq_t* filter_bias, - dl_matrix2dq_t* gate_kernel, dl_matrix2dq_t* gate_bias, - int filter_shift, int gate_shift); qtp_t *dl_dilation_layerq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size, dl_matrix2dq_t* filter_kernel, dl_matrix2dq_t* filter_bias, dl_matrix2dq_t* gate_kernel, dl_matrix2dq_t* gate_bias, int filter_shift, int gate_shift); dl_matrix2dq_t *dl_basic_lstm_layer1_q(const dl_convq_queue_t *in, dl_matrix2dq_t *state_c, dl_matrix2dq_t *state_h, - const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, int shift); + const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, int step, int shift); void test_atrous_convq(int size, int rate, int in_channel, int out_channel); #endif \ No newline at end of file diff --git a/lib/include/dl_lib_matrix.h b/lib/include/dl_lib_matrix.h index e08a13a..5cb4dcb 100644 --- a/lib/include/dl_lib_matrix.h +++ b/lib/include/dl_lib_matrix.h @@ -1,3 +1,16 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef DL_LIB_MATRIX_H #define DL_LIB_MATRIX_H diff --git a/lib/include/dl_lib_matrixq.h b/lib/include/dl_lib_matrixq.h index a2ff3e3..fcd449a 100644 --- a/lib/include/dl_lib_matrixq.h +++ b/lib/include/dl_lib_matrixq.h @@ -1,3 +1,16 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef DL_LIB_MATRIXQ_H #define DL_LIB_MATRIXQ_H diff --git a/main/multinet_test.c b/main/multinet_test.c index 470d0ca..46e5f18 100644 --- a/main/multinet_test.c +++ b/main/multinet_test.c @@ -14,7 +14,6 @@ static const esp_mn_iface_t *multinet = &MULTINET_MODEL; void multinetTask(void *arg) { model_iface_data_t *model_data = arg; - int frequency = multinet->get_samp_rate(model_data); int audio_chunksize = multinet->get_samp_chunksize(model_data); int chunk_num = multinet->get_samp_chunknum(model_data); int16_t *buffer = malloc(audio_chunksize * sizeof(int16_t)); @@ -50,9 +49,8 @@ void multinet_test() model_iface_data_t *model_data = multinet->create(&MULTINET_COEFF, 6000); //define_speech_commands(multinet, model_data); - int audio_chunksize = multinet->get_samp_chunksize(model_data); printf("multinet RAM size: %d\nRAM size after multinet init: %d\n", start_size - heap_caps_get_free_size(MALLOC_CAP_8BIT), heap_caps_get_free_size(MALLOC_CAP_8BIT)); - xTaskCreatePinnedToCore(&multinetTask, "multinet", 2 * 1024, (void*)model_data, 5, NULL, 0); + xTaskCreatePinnedToCore(&multinetTask, "multinet", 2 * 1024, (void*)model_data, 5, NULL, 1); } diff --git a/main/wakenet_test.c b/main/wakenet_test.c index af7f532..1a59434 100644 --- a/main/wakenet_test.c +++ b/main/wakenet_test.c @@ -52,7 +52,6 @@ void wakenet_test() //Initialize wakenet model model_iface_data_t *model_data = wakenet->create(model_coeff_getter, DET_MODE_90); - int audio_chunksize = wakenet->get_samp_chunksize(model_data); printf("WakeNet RAM size: %d\nRAM size after WakeNet init: %d\n", start_size - heap_caps_get_free_size(MALLOC_CAP_8BIT), heap_caps_get_free_size(MALLOC_CAP_8BIT)); diff --git a/speech_command_recognition/README.md b/speech_command_recognition/README.md index 2427c79..7194d57 100644 --- a/speech_command_recognition/README.md +++ b/speech_command_recognition/README.md @@ -9,7 +9,7 @@ MultiNet uses the **MFCC features** of an audio clip as input, and the **phoneme ## Commands Recognition Process 1. Add customized commands to the speech command queue. -2. Prepare an audio clip of 30 ms (16 KHz, 6 bit, mono). +2. Prepare an audio clip of 30 ms (16 KHz, 16 bit, mono). 3. Input this audio to the MFCC model and get its **MFCC features**. 4. Input the obtained **MFCC features** to MultiNet and get the output **phoneme**. 5. Input the obtained **phoneme** to the Language model and get the output.