Skip to content

Commit 380fe7a

Browse files
committed
SDK release 14 Mar 2024
1 parent 29ca890 commit 380fe7a

File tree

63 files changed

+2719
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2719
-721
lines changed

classifier/ei_classifier_smooth.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const char* ei_classifier_smooth_update(ei_classifier_smooth_t *smooth, ei_impul
7979
reading = (int)ix;
8080
}
8181
}
82-
#if EI_CLASSIFIER_HAS_ANOMALY == 1
82+
#if EI_CLASSIFIER_HAS_ANOMALY
8383
if (result->anomaly >= smooth->anomaly_confidence) {
8484
reading = -2; // anomaly
8585
}

classifier/ei_classifier_types.h

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ typedef struct {
3535
float value;
3636
} ei_impulse_result_classification_t;
3737

38+
typedef struct {
39+
float mean_value;
40+
float max_value;
41+
} ei_impulse_visual_ad_result_t;
42+
3843
typedef struct {
3944
const char *label;
4045
uint32_t x;
@@ -60,6 +65,12 @@ typedef struct {
6065
ei_impulse_result_classification_t classification[EI_CLASSIFIER_MAX_LABELS_COUNT];
6166
float anomaly;
6267
ei_impulse_result_timing_t timing;
68+
bool copy_output;
69+
#if EI_CLASSIFIER_HAS_VISUAL_ANOMALY
70+
ei_impulse_result_bounding_box_t *visual_ad_grid_cells;
71+
uint32_t visual_ad_count;
72+
ei_impulse_visual_ad_result_t visual_ad_result;
73+
#endif // EI_CLASSIFIER_HAS_VISUAL_ANOMALY
6374
} ei_impulse_result_t;
6475

6576
#endif // _EDGE_IMPULSE_RUN_CLASSIFIER_TYPES_H_

classifier/ei_fill_result_struct.h

+570-6
Large diffs are not rendered by default.

classifier/ei_model_types.h

+106-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdint.h>
2222

2323
#include "edge-impulse-sdk/classifier/ei_classifier_types.h"
24+
#include "edge-impulse-sdk/dsp/ei_dsp_handle.h"
2425
#include "edge-impulse-sdk/dsp/numpy.hpp"
2526
#if EI_CLASSIFIER_USE_FULL_TFLITE || (EI_CLASSIFIER_INFERENCING_ENGINE == EI_CLASSIFIER_AKIDA) || (EI_CLASSIFIER_INFERENCING_ENGINE == EI_CLASSIFIER_MEMRYX)
2627
#include "tensorflow-lite/tensorflow/lite/c/common.h"
@@ -61,14 +62,33 @@
6162
#define EI_CLASSIFIER_LAST_LAYER_YOLOX 4
6263
#define EI_CLASSIFIER_LAST_LAYER_YOLOV5_V5_DRPAI 5
6364
#define EI_CLASSIFIER_LAST_LAYER_YOLOV7 6
65+
#define EI_CLASSIFIER_LAST_LAYER_TAO_RETINANET 7
66+
#define EI_CLASSIFIER_LAST_LAYER_TAO_SSD 8
67+
#define EI_CLASSIFIER_LAST_LAYER_TAO_YOLOV3 9
68+
#define EI_CLASSIFIER_LAST_LAYER_TAO_YOLOV4 10
6469

6570
#define EI_CLASSIFIER_IMAGE_SCALING_NONE 0
6671
#define EI_CLASSIFIER_IMAGE_SCALING_0_255 1
6772
#define EI_CLASSIFIER_IMAGE_SCALING_TORCH 2
6873
#define EI_CLASSIFIER_IMAGE_SCALING_MIN1_1 3
74+
#define EI_CLASSIFIER_IMAGE_SCALING_MIN128_127 4
75+
76+
// maps back to ClassificationMode in keras-types.ts
77+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_CLASSIFICATION 1
78+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_REGRESSION 2
79+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_OBJECT_DETECTION 3
80+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_ANOMALY_GMM 4
81+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_VISUAL_ANOMALY 5
82+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_ANOMALY_KMEANS 6
83+
#define EI_CLASSIFIER_CLASSIFICATION_MODE_DSP 7
6984

7085
struct ei_impulse;
7186

87+
typedef struct {
88+
ei::matrix_t* matrix;
89+
uint32_t blockId;
90+
} ei_feature_t;
91+
7292
typedef struct {
7393
uint16_t implementation_version;
7494
bool is_configured;
@@ -79,11 +99,15 @@ typedef struct {
7999
} ei_model_performance_calibration_t;
80100

81101
typedef struct {
102+
uint32_t blockId;
82103
size_t n_output_features;
83104
int (*extract_fn)(ei::signal_t *signal, ei::matrix_t *output_matrix, void *config, const float frequency);
84105
void *config;
85106
uint8_t *axes;
86107
size_t axes_size;
108+
int version; // future proof, can easily add to this struct now
109+
DspHandle* (*factory)(void* config); // nullptr means no state
110+
// v1 ends here
87111
} ei_model_dsp_t;
88112

89113
typedef struct {
@@ -92,9 +116,14 @@ typedef struct {
92116
} ei_classifier_anom_cluster_t;
93117

94118
typedef struct {
95-
EI_IMPULSE_ERROR (*infer_fn)(const ei_impulse *impulse, ei::matrix_t *fmatrix, ei_impulse_result_t *result, void *config, bool debug);
119+
uint32_t blockId;
120+
bool keep_output;
121+
EI_IMPULSE_ERROR (*infer_fn)(const ei_impulse *impulse, ei_feature_t *fmatrix, uint32_t learn_block_index, uint32_t* input_block_ids, uint32_t input_block_ids_size, ei_impulse_result_t *result, void *config, bool debug);
96122
void *config;
97123
int image_scaling;
124+
const uint32_t* input_block_ids;
125+
const uint32_t input_block_ids_size;
126+
uint32_t output_features_count;
98127
} ei_learning_block_t;
99128

100129
typedef struct {
@@ -127,6 +156,7 @@ typedef struct {
127156

128157
typedef struct {
129158
uint16_t implementation_version;
159+
uint8_t classification_mode;
130160
uint32_t block_id;
131161
/* object detection */
132162
bool object_detection;
@@ -143,6 +173,7 @@ typedef struct {
143173

144174
typedef struct {
145175
uint16_t implementation_version;
176+
uint8_t classification_mode;
146177
const uint16_t *anom_axis;
147178
uint16_t anom_axes_size;
148179
const ei_classifier_anom_cluster_t *anom_clusters;
@@ -153,11 +184,19 @@ typedef struct {
153184

154185
typedef struct {
155186
uint16_t implementation_version;
187+
uint8_t classification_mode;
156188
const uint16_t *anom_axis;
157189
uint16_t anom_axes_size;
190+
float anomaly_threshold;
191+
bool visual;
158192
void* graph_config;
159193
} ei_learning_block_config_anomaly_gmm_t;
160194

195+
typedef struct {
196+
float confidence_threshold;
197+
float iou_threshold;
198+
} ei_object_detection_nms_config_t;
199+
161200
typedef struct ei_impulse {
162201
/* project details */
163202
uint32_t project_id;
@@ -200,12 +239,77 @@ typedef struct ei_impulse {
200239
uint32_t slices_per_model_window;
201240

202241
/* output details */
203-
bool has_anomaly;
242+
uint16_t has_anomaly;
204243
uint16_t label_count;
205244
const ei_model_performance_calibration_t calibration;
206245
const char **categories;
246+
ei_object_detection_nms_config_t object_detection_nms;
207247
} ei_impulse_t;
208248

249+
class ei_impulse_state_t {
250+
typedef DspHandle* _dsp_handle_ptr_t;
251+
public:
252+
const ei_impulse_t *impulse; // keep a pointer to the impulse
253+
_dsp_handle_ptr_t *dsp_handles;
254+
bool is_temp_handle = false; // to know if we're using the old (stateless) API
255+
ei_impulse_state_t(const ei_impulse_t *impulse)
256+
: impulse(impulse)
257+
{
258+
const auto num_dsp_blocks = impulse->dsp_blocks_size;
259+
dsp_handles = (_dsp_handle_ptr_t*)ei_malloc(sizeof(_dsp_handle_ptr_t)*num_dsp_blocks);
260+
for(size_t ix = 0; ix < num_dsp_blocks; ix++) {
261+
dsp_handles[ix] = nullptr;
262+
}
263+
}
264+
265+
DspHandle* get_dsp_handle(size_t ix) {
266+
if (dsp_handles[ix] == nullptr) {
267+
dsp_handles[ix] = impulse->dsp_blocks[ix].factory(impulse->dsp_blocks[ix].config);
268+
}
269+
return dsp_handles[ix];
270+
}
271+
272+
void reset()
273+
{
274+
for (size_t ix = 0; ix < impulse->dsp_blocks_size; ix++) {
275+
if (dsp_handles[ix] != nullptr) {
276+
delete dsp_handles[ix];
277+
dsp_handles[ix] = nullptr;
278+
}
279+
}
280+
}
281+
282+
void* operator new(size_t size) {
283+
return ei_malloc(size);
284+
}
285+
286+
void operator delete(void* ptr) {
287+
ei_free(ptr);
288+
}
289+
290+
void* operator new[](size_t size) {
291+
return ei_malloc(size);
292+
}
293+
294+
void operator delete[](void* ptr) {
295+
ei_free(ptr);
296+
}
297+
298+
~ei_impulse_state_t()
299+
{
300+
reset();
301+
ei_free(dsp_handles);
302+
}
303+
};
304+
305+
class ei_impulse_handle_t {
306+
public:
307+
ei_impulse_handle_t(const ei_impulse_t *impulse)
308+
: state(impulse), impulse(impulse) {};
309+
ei_impulse_state_t state;
310+
const ei_impulse_t *impulse;
311+
};
312+
209313
typedef struct {
210314
uint32_t block_id;
211315
uint16_t implementation_version;

0 commit comments

Comments
 (0)