Open KJlaccHoeUM9l opened 1 year ago
@KJlaccHoeUM9l
My steps to solve this task:
micro_features_model.cpp
changed g_model
from basic to our one and changed g_model_len
to 53936
. So, how to solve it:
micro_speech.ino
and del the code below:
static tflite::MicroMutableOpResolver<4> micro_op_resolver;
if (micro_op_resolver.AddDepthwiseConv2D() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddFullyConnected() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddSoftmax() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddReshape() != kTfLiteOk) {
return;
}
Use instead:
static tflite::MicroMutableOpResolver<6> micro_op_resolver;
if (micro_op_resolver.AddDepthwiseConv2D() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddFullyConnected() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddSoftmax() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddReshape() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddConv2D() != kTfLiteOk) {
return;
}
if (micro_op_resolver.AddAveragePool2D() != kTfLiteOk) {
return;
}
if (
(model_input->dims->size != 2)
|| (model_input->dims->data[0] != 1)
|| (model_input->dims->data[1] != (kFeatureSliceCount * kFeatureSliceSize))
|| (model_input->type != kTfLiteInt8)
) {
MicroPrintf("Bad input tensor parameters in model");
return;
}
Use instead:
if (
(model_input->dims->size != 4)
|| (model_input->dims->data[0] != 1)
|| (model_input->dims->data[1] != kFeatureSliceCount)
|| (model_input->dims->data[2] != kFeatureSliceSize)
|| (model_input->dims->data[3] != 1)
|| (model_input->type != kTfLiteInt8)
) {
MicroPrintf("Bad input tensor parameters in model");
return;
}
micro_features_micro_model_settings.h
and change constants to this:
constexpr int kFeatureSliceSize = 10;
constexpr int kFeatureSliceCount = 49;
constexpr int kSilenceIndex = 10; constexpr int kUnknownIndex = 11; constexpr int kCategoryCount = 12;
4. Go to `micro_features_micro_model_settings.cpp` and change the old array like this:
const char* kCategoryLabels[kCategoryCount] = { "down", "go", "left", "no", "off", "on", "right", "stop", "up", "yes", "silence", "unknown" };
After that you will have a working model, but it's not working properly.
It is my next issue, I will describe in the next comment.
First of all, I was got three topics to explore:
For myself I drew the next scheme:
Honestly, I can't answer fully on each question, but this is my assumptions:
PopulateFeatureData()
in feature_provider.cpp
we split audio on samples by time and transform it in proper way.ProcessLatestResults()
in recognize_commands.cpp
. It uses the output tensor 1x12. Here we count scores for each prediction and choose the best score. Also I found a test input data and tried to feed it to the model. And I think the problem is really in the input data @KJlaccHoeUM9l
I had a task to build boxplot for:
dat
(eval_quantized_model.py
)dat_q
(eval_quantized_model.py
)Here my notebook: https://github.com/Red-Caesar/data-analysis-for-project/blob/main/data_analysis.ipynb
@KJlaccHoeUM9l
I forgot to add snapshot about data preparing in Arduino example. Maybe it will be useful for comparison too:
Input with unprepared data:
frontend_input = data from file above input_size = 480 (duration_ms * (kAudioSampleFrequency / 1000), where duration_ms = kFeatureSliceDurationMs = 30, kAudioSampleFrequency = 16000 ) num_samples_read = 320 ( it's 66221 once in 12 times)
Raw signal preprocessing on MLPerf side (model_settings['feature_type'] == "mfcc"):
Important: points from 4 to 6 can be skipped due to output from point 3 can be used on 7 one without any processing. Notes: the reference https://kite.com/python/docs/tensorflow.contrib.slim.rev_block_lib.contrib_framework_ops.audio_ops.mfcc is given here with description of default parameters used for mfcc calculation See also pipeline for mfcc calculation here: https://www.tensorflow.org/api_docs/python/tf/signal/mfccs_from_log_mel_spectrograms
cc @Red-Caesar @FlexingJelly @KJlaccHoeUM9l
Scheme of preprocessing steps in frontend.c:
And the repo for any case: https://github.com/Red-Caesar/frontend-TensorFlow
Notes about tensorflow functions: https://quiver-brace-02a.notion.site/Tensorflow-18f6cf2d0c854254b7f89f822cf7bc4f
There are several categories in MLPerf where performance results can be submitted: https://github.com/mlcommons/tiny/tree/master/benchmark
For an initial dive into this submission for Microcontrollers, it is proposed to run a model for
Keyword Spotting
on Arduino: DC-CNN.It is necessary to run this model and document the steps that needed to be taken to run it.