Skip to content

Commit

Permalink
Add preloaded ML model for continious gesture detection
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Tomov <dimi@edgeimpulse.com>
  • Loading branch information
tomoveu committed Dec 15, 2022
1 parent 1021ef6 commit 7b9cd0a
Show file tree
Hide file tree
Showing 7 changed files with 948 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ei-model/model-parameters/anomaly_clusters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Generated by Edge Impulse
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _EI_CLASSIFIER_ANOMALY_CLUSTERS_H_
#define _EI_CLASSIFIER_ANOMALY_CLUSTERS_H_

#include "edge-impulse-sdk/anomaly/anomaly.h"

// (before - mean) / scale
const float ei_classifier_anom_scale[EI_CLASSIFIER_ANOM_AXIS_SIZE] = { 4.735934431428502, 2.6370697886685024, 1.752289641283062 };
const float ei_classifier_anom_mean[EI_CLASSIFIER_ANOM_AXIS_SIZE] = { 4.292335472136911, 2.1852703082689375, 1.6949875804138423 };

const ei_classifier_anom_cluster_t ei_classifier_anom_clusters[EI_CLASSIFIER_ANOM_CLUSTER_COUNT] = { { { 1.1627247333526611, -0.09127187728881836, 0.039932578802108765 }, 0.45766612185692546 }
, { { 1.0793125629425049, -0.35539326071739197, -0.25196555256843567 }, 0.393853330260634 }
, { { -0.6699717044830322, -0.025066491216421127, 1.8257455825805664 }, 0.4076753010490145 }
, { { -0.905547022819519, -0.8271730542182922, -0.9636279940605164 }, 0.07057358582419748 }
, { { -0.6083683967590332, 0.3378922939300537, -0.2750750780105591 }, 0.34529380833031026 }
, { { 1.8524712324142456, -0.011566506698727608, 0.8461854457855225 }, 0.432528610593013 }
, { { 1.3358670473098755, -0.05726705491542816, -0.43816810846328735 }, 0.5062860278160605 }
, { { -0.7409022450447083, -0.34725621342658997, -0.8029352426528931 }, 0.21884703625369306 }
, { { -0.503063440322876, -0.3759881258010864, 2.3207943439483643 }, 0.7885827511063271 }
, { { -0.6956930160522461, -0.3123343288898468, 1.5905060768127441 }, 0.39691538375970054 }
, { { 0.7493807077407837, 2.8090922832489014, 0.8038313388824463 }, 0.4756844734737089 }
, { { -0.6844053864479065, -0.14970919489860535, -0.8244701623916626 }, 0.26707199648543406 }
, { { 1.5486040115356445, 0.7133833765983582, 0.5105420351028442 }, 0.4487223169579444 }
, { { 1.7191046476364136, 0.2774096429347992, 0.3952651917934418 }, 0.4223370205546866 }
, { { -0.5709540247917175, 0.6095415353775024, 0.03743164613842964 }, 0.5761022260100517 }
, { { -0.7589687705039978, -0.5149730443954468, 1.1454917192459106 }, 0.41873647710696993 }
, { { -0.03281811252236366, 3.856318950653076, -0.06501699984073639 }, 0.4937528681009911 }
, { { 0.9676327705383301, 3.318385362625122, 1.194267749786377 }, 0.3862170996134061 }
, { { -0.31564873456954956, 1.6312458515167236, 0.08470914512872696 }, 0.5464022209211731 }
, { { -0.4383845925331116, 3.3809237480163574, -0.20014718174934387 }, 0.5178456874700895 }
, { { -0.7231196761131287, -0.3596212565898895, -0.5751107335090637 }, 0.2102935035976298 }
, { { -0.5922588109970093, 0.08036672323942184, 1.3690720796585083 }, 0.4210207540244469 }
, { { 1.2505220174789429, 0.2934052348136902, -0.31634294986724854 }, 0.4438873246997636 }
, { { -0.4361991286277771, -0.1800207793712616, 2.741694450378418 }, 0.7265706160475239 }
, { { 0.9043402075767517, -0.10142571479082108, 0.8351730704307556 }, 0.5526395773058033 }
, { { 0.945662260055542, -0.027204414829611778, -0.3570230305194855 }, 0.37494576737715907 }
, { { 1.8591350317001343, 0.09516841173171997, 1.431195616722107 }, 0.5613021315333133 }
, { { -0.14796173572540283, 3.592709541320801, -0.3852364122867584 }, 0.46899416758090073 }
, { { 1.414710521697998, 0.6246669888496399, -0.007774942554533482 }, 0.46243669139995136 }
, { { 1.2696725130081177, -0.39998090267181396, 0.6421909332275391 }, 0.3975097018500365 }
, { { -0.12758338451385498, 1.1125560998916626, 0.7232611775398254 }, 0.672883066503446 }
, { { -0.2525366246700287, 1.0297623872756958, 2.618793249130249 }, 0.8520370623106243 }
};

#endif // _EI_CLASSIFIER_ANOMALY_CLUSTERS_H_
36 changes: 36 additions & 0 deletions ei-model/model-parameters/anomaly_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Generated by Edge Impulse
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _EI_CLASSIFIER_ANOMALY_TYPES_HEADER_H_
#define _EI_CLASSIFIER_ANOMALY_TYPES_HEADER_H_

#define EI_CLASSIFIER_HAS_ANOMALY 1

const uint16_t EI_CLASSIFIER_ANOM_AXIS[] { 0, 11, 22 };
#define EI_CLASSIFIER_ANOM_AXIS_SIZE 3
#define EI_CLASSIFIER_ANOM_CLUSTER_COUNT 32

typedef struct {
float centroid[EI_CLASSIFIER_ANOM_AXIS_SIZE];
float max_error;
} ei_classifier_anom_cluster_t;

#endif // _EI_CLASSIFIER_ANOMALY_TYPES_HEADER_H_
41 changes: 41 additions & 0 deletions ei-model/model-parameters/dsp_blocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Generated by Edge Impulse
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#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"

const size_t ei_dsp_blocks_size = 1;
ei_model_dsp_t ei_dsp_blocks[ei_dsp_blocks_size] = {
{ // DSP block 3
33,
&extract_spectral_analysis_features,
(void*)&ei_dsp_config_3,
ei_dsp_config_3_axes,
ei_dsp_config_3_axes_size
}
};

#endif // _EI_CLASSIFIER_DSP_BLOCKS_H_
207 changes: 207 additions & 0 deletions ei-model/model-parameters/model_metadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/* Generated by Edge Impulse
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _EI_CLASSIFIER_MODEL_METADATA_H_
#define _EI_CLASSIFIER_MODEL_METADATA_H_

#include <stdint.h>

#define EI_CLASSIFIER_NONE 255
#define EI_CLASSIFIER_UTENSOR 1
#define EI_CLASSIFIER_TFLITE 2
#define EI_CLASSIFIER_CUBEAI 3
#define EI_CLASSIFIER_TFLITE_FULL 4
#define EI_CLASSIFIER_TENSAIFLOW 5
#define EI_CLASSIFIER_TENSORRT 6

#define EI_CLASSIFIER_SENSOR_UNKNOWN -1
#define EI_CLASSIFIER_SENSOR_MICROPHONE 1
#define EI_CLASSIFIER_SENSOR_ACCELEROMETER 2
#define EI_CLASSIFIER_SENSOR_CAMERA 3
#define EI_CLASSIFIER_SENSOR_9DOF 4
#define EI_CLASSIFIER_SENSOR_ENVIRONMENTAL 5
#define EI_CLASSIFIER_SENSOR_FUSION 6

// These must match the enum values in TensorFlow Lite's "TfLiteType"
#define EI_CLASSIFIER_DATATYPE_FLOAT32 1
#define EI_CLASSIFIER_DATATYPE_INT8 9

#define EI_CLASSIFIER_PROJECT_ID 110877
#define EI_CLASSIFIER_PROJECT_OWNER "EdgeImpulse Inc."
#define EI_CLASSIFIER_PROJECT_NAME "Tutorial: Continuous motion recognition"
#define EI_CLASSIFIER_PROJECT_DEPLOY_VERSION 53
#define EI_CLASSIFIER_NN_INPUT_FRAME_SIZE 33
#define EI_CLASSIFIER_RAW_SAMPLE_COUNT 125
#define EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME 3
#define EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE (EI_CLASSIFIER_RAW_SAMPLE_COUNT * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME)
#define EI_CLASSIFIER_INPUT_WIDTH 0
#define EI_CLASSIFIER_INPUT_HEIGHT 0
#define EI_CLASSIFIER_INPUT_FRAMES 0
#define EI_CLASSIFIER_INTERVAL_MS 16
#define EI_CLASSIFIER_LABEL_COUNT 4
#define EI_CLASSIFIER_HAS_ANOMALY 1
#define EI_CLASSIFIER_FREQUENCY 62.5
#define EI_CLASSIFIER_USE_QUANTIZED_DSP_BLOCK 0
#define EI_CLASSIFIER_HAS_MODEL_VARIABLES 1


#define EI_CLASSIFIER_OBJECT_DETECTION 0
#define EI_CLASSIFIER_TFLITE_OUTPUT_DATA_TENSOR 0


#define EI_CLASSIFIER_TFLITE_INPUT_DATATYPE EI_CLASSIFIER_DATATYPE_INT8
#define EI_CLASSIFIER_TFLITE_INPUT_QUANTIZED 1
#define EI_CLASSIFIER_TFLITE_INPUT_SCALE 0.11322642862796783
#define EI_CLASSIFIER_TFLITE_INPUT_ZEROPOINT -128
#define EI_CLASSIFIER_TFLITE_OUTPUT_DATATYPE EI_CLASSIFIER_DATATYPE_INT8
#define EI_CLASSIFIER_TFLITE_OUTPUT_QUANTIZED 1
#define EI_CLASSIFIER_TFLITE_OUTPUT_SCALE 0.00390625
#define EI_CLASSIFIER_TFLITE_OUTPUT_ZEROPOINT -128



#define EI_CLASSIFIER_INFERENCING_ENGINE EI_CLASSIFIER_TFLITE


#define EI_CLASSIFIER_COMPILED 1
#define EI_CLASSIFIER_HAS_TFLITE_OPS_RESOLVER 1


#define EI_CLASSIFIER_HAS_FFT_INFO 0

#define EI_CLASSIFIER_SENSOR EI_CLASSIFIER_SENSOR_ACCELEROMETER
#define EI_CLASSIFIER_FUSION_AXES_STRING "accX + accY + accZ"

#ifndef EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW
#define EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW 4
#endif // EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW
#define EI_CLASSIFIER_SLICE_SIZE (EI_CLASSIFIER_RAW_SAMPLE_COUNT / EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW)

#if EI_CLASSIFIER_INFERENCING_ENGINE == EI_CLASSIFIER_TFLITE && EI_CLASSIFIER_USE_FULL_TFLITE == 1
#undef EI_CLASSIFIER_INFERENCING_ENGINE
#undef EI_CLASSIFIER_HAS_TFLITE_OPS_RESOLVER
#define EI_CLASSIFIER_INFERENCING_ENGINE EI_CLASSIFIER_TFLITE_FULL
#define EI_CLASSIFIER_HAS_TFLITE_OPS_RESOLVER 0
#if EI_CLASSIFIER_COMPILED == 1
#error "Cannot use full TensorFlow Lite with EON"
#endif
#endif // EI_CLASSIFIER_INFERENCING_ENGINE == EI_CLASSIFIER_TFLITE && EI_CLASSIFIER_USE_FULL_TFLITE == 1

typedef struct {
uint16_t implementation_version;
int axes;
float scale_axes;
bool average;
bool minimum;
bool maximum;
bool rms;
bool stdev;
bool skewness;
bool kurtosis;
} ei_dsp_config_flatten_t;

typedef struct {
uint16_t implementation_version;
int axes;
const char * channels;
} ei_dsp_config_image_t;

typedef struct {
uint16_t implementation_version;
int axes;
int num_cepstral;
float frame_length;
float frame_stride;
int num_filters;
int fft_length;
int win_size;
int low_frequency;
int high_frequency;
float pre_cof;
int pre_shift;
} ei_dsp_config_mfcc_t;

typedef struct {
uint16_t implementation_version;
int axes;
float frame_length;
float frame_stride;
int num_filters;
int fft_length;
int low_frequency;
int high_frequency;
int win_size;
int noise_floor_db;
} ei_dsp_config_mfe_t;

typedef struct {
uint16_t implementation_version;
int axes;
float scale_axes;
} ei_dsp_config_raw_t;

typedef struct {
uint16_t implementation_version;
int axes;
float scale_axes;
const char * filter_type;
float filter_cutoff;
int filter_order;
const char * analysis_type;
int fft_length;
int spectral_peaks_count;
float spectral_peaks_threshold;
const char * spectral_power_edges;
bool do_log;
bool do_fft_overlap;
int wavelet_level;
const char * wavelet;
} ei_dsp_config_spectral_analysis_t;

typedef struct {
uint16_t implementation_version;
int axes;
float frame_length;
float frame_stride;
int fft_length;
int noise_floor_db;
bool show_axes;
} ei_dsp_config_spectrogram_t;

typedef struct {
uint16_t implementation_version;
int axes;
float frame_length;
float frame_stride;
int num_filters;
int fft_length;
int low_frequency;
int high_frequency;
float pre_cof;
} ei_dsp_config_audio_syntiant_t;

typedef struct {
uint16_t implementation_version;
int axes;
bool scaling;
} ei_dsp_config_imu_syntiant_t;

#endif // _EI_CLASSIFIER_MODEL_METADATA_H_
Loading

0 comments on commit 7b9cd0a

Please sign in to comment.