Doubt about the custom preprocessing block

Question/Issue:
Hi I have some doubts with the custom preprocessing block.
Is it possible to upload as a custom block some hardware preprocessing or does it need to be all code?
Project ID:

Context/Use case:

Hello @JosuGaztelu,

When you create a custom DSP block, you can give a name to your corresponding cpp implementation in the parameter.json file under cppType.

For example, imagine you want to create an Edge Detection custom DSP block for images, your parameter.json file will look like this:

{
    "version": 1,
    "info": {
        "title": "Edge Detection",
        "author": "Louis Moreau",
        "description": "Edge Detection for images",
        "name": "Edge Detection",
        "cppType": "canny_filters_edge_detection",
        "preferConvolution": false,
        "visualization": "dimensionalityReduction",
        "experimental": false,
        "latestImplementationVersion": 1
    },
    "parameters": [
        {
            "group": "Edge Detection",
            "items": [
                {
                    "name": "High threshold",
                    "value": 100,
                    "help": "High threshold value of intensity gradient",
                    "type": "int",
                    "param": "high_threshold"
                },
                {
                    "name": "Low threshold",
                    "value": 200,
                    "help": "Low threshold value of intensity gradient",
                    "type": "int",
                    "param": "low_threshold"
                },
                {
                    "name": "Gaussian blur",
                    "value": 3,
                    "help": "Amount of blur",
                    "type": "int",
                    "param": "gaussian_blur"
                }
            ]
        }
    ]
}

Then in the C++ library that you download from the studio, you will find a file model-parameters/dsp_blocks.h that will contain:

#ifndef _EI_CLASSIFIER_DSP_BLOCKS_H_
#define _EI_CLASSIFIER_DSP_BLOCKS_H_

#include "model-parameters/model_metadata.h"
#include "model-parameters/model_variables.h"
#include "edge-impulse-sdk/classifier/ei_run_dsp.h"
#include "edge-impulse-sdk/classifier/ei_model_types.h"

int extract_canny_filters_edge_detection_features(signal_t *signal, matrix_t *output_matrix, void *config_ptr, const float frequency);

const size_t ei_dsp_blocks_size = 1;
ei_model_dsp_t ei_dsp_blocks[ei_dsp_blocks_size] = {
    { // DSP block 14
        9216,
        &extract_canny_filters_edge_detection_features,
        (void*)&ei_dsp_config_14,
        ei_dsp_config_14_axes,
        ei_dsp_config_14_axes_size
    }
};

#endif // _EI_CLASSIFIER_DSP_BLOCKS_H_

And in edge-impulse-sdk/classifier/ei_run_dsp.h you can write your own implementation of your custom dsp function that will be called extract_canny_filters_edge_detection_features.

Let me know if you need more information.

Regards,

Louis

Hi @louis ,
I think I get what you mean but still not clear about the relation between a preprocessing block and a real hardware processing while training/testing in Edge Impulse, I get that I can upload my parameters in a .json file. But if I have an already configured Digital Signal Processor and I must use it in my application, how can I make it know to the project? How can I upload the information of what preprocessing is running on my hardware board? Or must it use my specific hardware to train/test?

@JosuGaztelu,

We just published that video that was recorded some time ago by @janjongboom: Advanced Anomaly Detection with Edge Impulse (Custom DSP Blocks, Feature Importance) - YouTube

If you look at around minute 25, Jan explains how to implement your custom DSP block in with your C++ library that you can download from the studio.

Regards,

Louis

1 Like

And this is the associated Github repository: https://github.com/edgeimpulse/example-custom-spectral-dsp-block

1 Like

Hi again @louis,
I’m sorry for replying to you so late to ask again about the same stuff.
My doubt was more about, once I’ve uploaded which preprocessing my specific hardware will perform, and I have a NN trained, when deploying, will the DSP be performed on my boards hardware or will it be processed by the code generated from my specifications?, because if it is so, the latency will be much higher than it could be.
Josu

Hello @JosuGaztelu,

Your DSP code will be executed on your hardware, you will need to implement the cpp code yourself.

On the parameters.json from your dsp block, you will have something like the following:

{
"version": 1,
    "info": {
        "title": "Custom DSP Name",
        "author": "Your Name",
        "description": "quick explanation of the pre-processing",
        "name": "Custom DSP",
        "cppType": "cpp_block_name",
        "preferConvolution": false,
        "visualization": "dimensionalityReduction",
        "experimental": false,
        "latestImplementationVersion": 1
    },
...
} 

If you have a look at:

"cppType": "cpp_block_name",

Then when you will download the generated c++ library from the studio, a new function will be created:

int extract_cpp_block_name_features(signal_t *signal, matrix_t *output_matrix, void *config_ptr, const float frequency){}

It takes your {cppType} and generates the following function extract_{cppType}_features.

Implement your code here in c++ and copy paste that function into your main.cpp file (or somewhere else, just make sure it is referenced).

I will make sure I add that to our documentation as you were not the only one to ask about this recently.

In any cases, yes the DSP code will be executed on your device.

Regards,

Louis

2 Likes