extern "C" EI_IMPULSE_ERROR run_classifier_continuous(
signal_t *signal,
ei_impulse_result_t *result,
bool debug = false,
bool enable_maf = true);
Brief: Run preprocessing (DSP) on new slice of raw features. Add output features to rolling matrix and run inference on full sample.
Blocking: yes
Description: run_classifier_continuous() accepts a new slice of features give by the callback defined in the signal parameter. It performs preprocessing (DSP) on this new slice of features and appends the output to a sliding window of pre-processed features (stored in a static features matrix). The matrix stores the new slice and as many old slices as necessary to make up one full sample for performing inference.
run_classifier_init() should be called before making any calls to run_classifier_continuous().
For example, if you are doing keyword spotting on 1-second slices of audio and you want to perform inference 4 times per second (given by EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW), you would collect 0.25 seconds of audio and call run_classifier_continuous(). The function would compute the Mel-Frequency Cepstral Coefficients (MFCCs) for that 0.25 second slice of audio, drop the oldest 0.25 seconds' worth of MFCCs from its internal matrix, and append the newest slice of MFCCs. This process allows the library to keep track of the pre-processed features (e.g. MFCCs) in the window instead of the entire set of raw features (e.g. raw audio data), which can potentially save a lot of space in RAM. After updating the static matrix, inference is performed using the whole matrix, which acts as a sliding window of pre-processed features.
Additionally, a moving average filter (MAF) can be enabled for run_classifier_continuous(), which averages (arithmetic mean) the last n inference results for each class. n is EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW / 2. In our example above, if we enabled the MAF, the values in result would contain predictions averaged from the previous 2 inferences.
To learn more about run_classifier_continuous(), see this guide on continuous audio sampling. While the guide is written for audio signals, the concepts of continuous sampling and inference can be extrapolated to any time-series data.
  • signal - [input] Pointer to a signal_t struct that contains the number of elements in the slice of raw features (e.g. EI_CLASSIFIER_SLICE_SIZE) and a pointer to a callback that reads in the slice of raw features.
  • result - [output] Pointer to an ei_impulse_result_t struct that will contain the various output results from inference after run_classifier() returns.
  • debug - [input] Print internal preprocessing and inference debugging information via ei_printf().
  • enable_maf - [input] Set true to enable moving average filter. If MAF is enabled, result.classification[ix].value will contain the moving average value from the previous EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW / 2 windows.
Returns: Error code as defined by EI_IMPULSE_ERROR enum. Will be EI_IMPULSE_OK if inference completed successfully.