Skip to content

Commit

Permalink
SDK release v1.61.30
Browse files Browse the repository at this point in the history
  • Loading branch information
mmajchrzycki committed Dec 2, 2024
1 parent a6f1a50 commit 446f260
Show file tree
Hide file tree
Showing 43 changed files with 907 additions and 434 deletions.
12 changes: 6 additions & 6 deletions EdgeImpulse.EI-SDK.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
<name>EI-SDK</name>
<license>LICENSE-apache-2.0.txt</license>
<description>Edge Impulse SDK</description>
<url>https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.23/</url>
<url>https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.30/</url>
<supportContact>[email protected]</supportContact>
<repository type="git">https://github.com/edgeimpulse/edge-impulse-sdk-pack.git</repository>
<releases>
<release version="1.61.23" tag="v1.61.23" date="2024-11-22" url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.23/EdgeImpulse.EI-SDK.1.61.23.pack">
<release version="1.61.30" tag="v1.61.30" date="2024-12-02" url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.30/EdgeImpulse.EI-SDK.1.61.30.pack">
EI-SDK
</release>
<release version="1.61.23" tag="v1.61.23" date="2024-11-22" url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.23/EdgeImpulse.EI-SDK.1.61.23.pack">
EI-SDK
</release>
<release version="1.61.12" tag="v1.61.12" date="2024-11-11" url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.12/EdgeImpulse.EI-SDK.1.61.12.pack">
EI-SDK
</release>
Expand Down Expand Up @@ -98,9 +101,6 @@
</release>
<release version="1.50.19" tag="v1.50.19" date="2024-06-05" url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.50.19/EdgeImpulse.EI-SDK.1.50.19.pack">
EI-SDK
</release>
<release version="1.50.17" tag="v1.50.17" date="2024-06-04" url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.50.17/EdgeImpulse.EI-SDK.1.50.17.pack">
EI-SDK
</release>
</releases>
<keywords>
Expand Down Expand Up @@ -146,7 +146,7 @@
</packages>
</requirements>
<components>
<component Cclass="EdgeImpulse" Cgroup="SDK" Cversion="1.61.23">
<component Cclass="EdgeImpulse" Cgroup="SDK" Cversion="1.61.30">
<description>Edge Impulse SDK</description>
<!-- short component description -->
<files>
Expand Down
4 changes: 2 additions & 2 deletions EdgeImpulse.pidx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<index schemaVersion="1.0.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<vendor>EdgeImpulse</vendor>
<url>https://raw.githubusercontent.com/edgeimpulse/edge-impulse-sdk-pack/main/</url>
<timestamp>2024-11-22 10:55:31</timestamp>
<timestamp>2024-12-02 12:34:28</timestamp>
<pindex>
<pdsc url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.23/" vendor="EdgeImpulse" name="EI-SDK" version="1.61.23"/>
<pdsc url="https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.61.30/" vendor="EdgeImpulse" name="EI-SDK" version="1.61.30"/>
</pindex>
</index>
1 change: 0 additions & 1 deletion edgeimpulse/edge-impulse-sdk/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Unless specifically indicated otherwise in a file, files are licensed under the
Folders containing third party code and libraries are listed below. Each folder contains its own license specified for its files.

* CMSIS - Apache 2.0
* dsp/dct - MIT
* dsp/kissfft - BSD-3-Clause
* porting/espressif/ESP-NN - Apache 2.0
* porting/ethos-core-driver - Apache 2.0
Expand Down
4 changes: 3 additions & 1 deletion edgeimpulse/edge-impulse-sdk/classifier/ei_model_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ typedef struct {
uint16_t implementation_version;
uint32_t keep_grace;
uint16_t max_observations;
float iou_threshold;
float threshold;
bool use_iou;
} ei_object_tracking_config_t;

typedef struct {
Expand Down Expand Up @@ -149,6 +150,7 @@ typedef struct {
EI_IMPULSE_ERROR (*init_fn)(ei_impulse_handle_t *handle, void **state, void *config);
EI_IMPULSE_ERROR (*deinit_fn)(void *state, void *config);
EI_IMPULSE_ERROR (*postprocess_fn)(ei_impulse_handle_t *handle, ei_impulse_result_t *result, void *config, void* state);
EI_IMPULSE_ERROR (*display_fn)(ei_impulse_result_t *result, void *config);
void *config;
} ei_postprocessing_block_t;

Expand Down
9 changes: 5 additions & 4 deletions edgeimpulse/edge-impulse-sdk/classifier/ei_run_classifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ therefore changes are allowed. */
*
* @param result The result
*/
__attribute__((unused)) void display_results(ei_impulse_result_t* result)
__attribute__((unused)) void display_results(ei_impulse_handle_t *handle, ei_impulse_result_t* result)
{
// print the predictions
ei_printf("Predictions (DSP: %d ms., Classification: %d ms., Anomaly: %d ms.): \n",
Expand Down Expand Up @@ -154,6 +154,7 @@ __attribute__((unused)) void display_results(ei_impulse_result_t* result)
ei_printf_float(result->anomaly);
ei_printf("\r\n");
#endif
display_postprocessing(handle, result);
}

/**
Expand Down Expand Up @@ -237,7 +238,7 @@ extern "C" EI_IMPULSE_ERROR process_impulse(ei_impulse_handle_t *handle,
if (res != EI_IMPULSE_OK) {
return res;
}
res = run_postprocessing(handle, result, debug);
res = run_postprocessing(handle, result);
return res;
}
#endif
Expand Down Expand Up @@ -361,7 +362,7 @@ extern "C" EI_IMPULSE_ERROR process_impulse(ei_impulse_handle_t *handle,
if (res != EI_IMPULSE_OK) {
return res;
} else {
return run_postprocessing(handle, result, debug);
return run_postprocessing(handle, result);
}
#endif
}
Expand Down Expand Up @@ -526,7 +527,7 @@ extern "C" EI_IMPULSE_ERROR process_impulse_continuous(ei_impulse_handle_t *hand

ei_impulse_error = run_inference(handle, features, result, debug);
delete[] matrix_ptrs;
ei_impulse_error = run_postprocessing(handle, result, debug);
ei_impulse_error = run_postprocessing(handle, result);
}

return ei_impulse_error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ float intersection_over_union(const ei_impulse_result_bounding_box_t bbox1, cons
return static_cast<float>(intersection_area) / static_cast<float>(bbox1_area + bbox2_area - intersection_area);
}

float centroid_euclidean_distance(const ei_impulse_result_bounding_box_t bbox1, const ei_impulse_result_bounding_box_t bbox2) {
float x1 = bbox1.x + bbox1.width / 2.0f;
float y1 = bbox1.y + bbox1.height / 2.0f;
float x2 = bbox2.x + bbox2.width / 2.0f;
float y2 = bbox2.y + bbox2.height / 2.0f;
float distance = std::sqrt(std::pow(x1 - x2, 2) + std::pow(y1 - y2, 2));
EI_LOGD("centroid_euclidean_distance: x1=%f y1=%f x2=%f y2=%f distance=%f\n", x1, y1, x2, y2, distance);
return distance;
}

class JonkerVolgenantAlignment {
public:
JonkerVolgenantAlignment(float iou_threshold) : iou_threshold(iou_threshold) {
JonkerVolgenantAlignment(float threshold, bool use_iou = true) : threshold(threshold), use_iou(use_iou) {
}

std::vector<std::tuple<int, int, float>> align(const std::vector<ei_impulse_result_bounding_box_t> traces,
Expand All @@ -47,8 +57,13 @@ class JonkerVolgenantAlignment {
std::vector<double> cost_mtx(traces.size() * detections.size());
for (size_t trace_idx = 0; trace_idx < traces.size(); ++trace_idx) {
for (size_t detection_idx = 0; detection_idx < detections.size(); ++detection_idx) {
float iou = intersection_over_union(traces[trace_idx], detections[detection_idx]);
float cost = 1 - iou;
float cost = 0.0;
if (use_iou) {
float iou = intersection_over_union(traces[trace_idx], detections[detection_idx]);
cost = 1 - iou;
} else {
cost = centroid_euclidean_distance(traces[trace_idx], detections[detection_idx]);
}
EI_LOGD("t_idx=%zu d_idx=%zu cost=%.6f\n", trace_idx, detection_idx, cost);
cost_mtx[trace_idx * detections.size() + detection_idx] = cost;
}
Expand All @@ -74,22 +89,30 @@ class JonkerVolgenantAlignment {
for (size_t i = 0; i < traces.size(); i++) {
size_t trace_idx = i;
size_t detection_idx = alignments_b[alignments_a[i]];
float iou = 1 - cost_mtx[trace_idx * detections.size() + detection_idx];
if (iou > iou_threshold) {
matches.emplace_back(trace_idx, detection_idx, iou);
if (use_iou) {
float iou = 1 - cost_mtx[trace_idx * detections.size() + detection_idx];
if (iou > threshold) {
matches.emplace_back(trace_idx, detection_idx, iou);
}
} else {
float cost = cost_mtx[trace_idx * detections.size() + detection_idx];
if (cost < threshold) {
matches.emplace_back(trace_idx, detection_idx, cost);
}
}
}
delete[] alignments_a;
delete[] alignments_b;
return matches;
}

float iou_threshold;
float threshold;
bool use_iou;
};

class GreedyAlignment {
public:
GreedyAlignment(float iou_threshold) : iou_threshold(iou_threshold) {
GreedyAlignment(float threshold, bool use_iou = true) : threshold(threshold), use_iou(use_iou) {
}
std::vector<std::tuple<int, int, float>> align(const std::vector<ei_impulse_result_bounding_box_t> traces,
const std::vector<ei_impulse_result_bounding_box_t> detections) {
Expand All @@ -101,11 +124,16 @@ class GreedyAlignment {
std::vector<std::tuple<int, int, float>> alignments;
for (size_t trace_idx = 0; trace_idx < traces.size(); ++trace_idx) {
for (size_t detection_idx = 0; detection_idx < detections.size(); ++detection_idx) {
float iou = intersection_over_union(traces[trace_idx], detections[detection_idx]);
float cost = 1 - iou;
EI_LOGD("t_idx=%zu d_idx=%zu cost=%.6f\n", trace_idx, detection_idx, cost);
if (iou > iou_threshold) {
alignments.emplace_back(trace_idx, detection_idx, cost);
if (use_iou) {
float iou = intersection_over_union(traces[trace_idx], detections[detection_idx]);
if (iou > threshold) {
alignments.emplace_back(trace_idx, detection_idx, 1 - iou);
}
} else {
float cost = centroid_euclidean_distance(traces[trace_idx], detections[detection_idx]);
if (cost < threshold) {
alignments.emplace_back(trace_idx, detection_idx, cost);
}
}
}
}
Expand All @@ -123,7 +151,7 @@ class GreedyAlignment {

if (trace_idxs_matched.find(trace_idx) == trace_idxs_matched.end() && detection_idxs_matched.find(detection_idx) == detection_idxs_matched.end()) {
// (1 - cost) to get iou
matches.emplace_back(trace_idx, detection_idx, 1 - cost);
matches.emplace_back(trace_idx, detection_idx, use_iou ? 1 - cost : cost);
trace_idxs_matched.insert(trace_idx);
if (trace_idxs_matched.size() == traces.size()) return matches;
detection_idxs_matched.insert(detection_idx);
Expand All @@ -134,5 +162,6 @@ class GreedyAlignment {
return matches;
}

float iou_threshold;
float threshold;
bool use_iou;
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ EI_IMPULSE_ERROR process_object_counting(ei_impulse_handle_t *handle,
return EI_IMPULSE_OK;
}

EI_IMPULSE_ERROR display_object_counting(ei_impulse_result_t *result,
void *config)
{
// print the counts
ei_printf("Counts:\r\n");
for (uint32_t i = 0; i < result->postprocessed_output.object_counting_output.counter_num; i++) {
ei_printf(" Counter %d: %d\r\n", i, result->postprocessed_output.object_counting_output.counts[i]);
}

return EI_IMPULSE_OK;
}

EI_IMPULSE_ERROR set_post_process_params(ei_impulse_handle_t* handle, ei_object_counting_config_t* params) {
int16_t block_number = get_block_number(handle, (void*)init_object_counting);
if (block_number == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ class Trace {

class Tracker {
public:
Tracker (uint32_t keep_grace = 5, uint16_t max_observations = 5, float iou_threshold = 0.5)
Tracker (uint32_t keep_grace = 5, uint16_t max_observations = 5, float threshold = 0.5, bool use_iou = true)
: keep_grace(keep_grace),
max_observations(max_observations),
alignment(iou_threshold) {
alignment(threshold, use_iou) {
trace_seq_id = 0;
t = 0;
}
Expand Down Expand Up @@ -354,13 +354,12 @@ class Tracker {
t += 1;
}

bool set_iou_threshold(float iou_threshold) {
alignment.iou_threshold = iou_threshold;
return true;
void set_threshold(float threshold) {
alignment.threshold = threshold;
}

float get_iou_threshold() {
return alignment.iou_threshold;
float get_threshold() {
return alignment.threshold;
}

uint32_t keep_grace;
Expand All @@ -379,7 +378,8 @@ EI_IMPULSE_ERROR init_object_tracking(ei_impulse_handle_t *handle, void** state,
// Allocate the object counter
Tracker *object_tracker = new Tracker(ei_object_tracking_config->keep_grace,
ei_object_tracking_config->max_observations,
ei_object_tracking_config->iou_threshold);
ei_object_tracking_config->threshold,
ei_object_tracking_config->use_iou);
if (!object_tracker) {
return EI_IMPULSE_OUT_OF_MEMORY;
}
Expand Down Expand Up @@ -425,6 +425,25 @@ EI_IMPULSE_ERROR process_object_tracking(ei_impulse_handle_t *handle,
return EI_IMPULSE_OK;
}

EI_IMPULSE_ERROR display_object_tracking(ei_impulse_result_t *result,
void *config)
{
// print the open traces
ei_printf("Open traces:\r\n");
for (uint32_t i = 0; i < result->postprocessed_output.object_tracking_output.open_traces_count; i++) {
ei_object_tracking_trace_t trace = result->postprocessed_output.object_tracking_output.open_traces[i];
ei_printf(" Trace %d: %s [ x: %u, y: %u, width: %u, height: %u ]\r\n",
trace.id,
trace.label,
trace.x,
trace.y,
trace.width,
trace.height);
}

return EI_IMPULSE_OK;
}

EI_IMPULSE_ERROR set_post_process_params(ei_impulse_handle_t* handle, ei_object_tracking_config_t* params) {
int16_t block_number = get_block_number(handle, (void*)init_object_tracking);
if (block_number == -1) {
Expand All @@ -434,7 +453,7 @@ EI_IMPULSE_ERROR set_post_process_params(ei_impulse_handle_t* handle, ei_object_

object_tracker->keep_grace = params->keep_grace;
object_tracker->max_observations = params->max_observations;
object_tracker->set_iou_threshold(params->iou_threshold);
object_tracker->set_threshold(params->threshold);
return EI_IMPULSE_OK;
}

Expand All @@ -447,7 +466,7 @@ EI_IMPULSE_ERROR get_post_process_params(ei_impulse_handle_t* handle, ei_object_

params->keep_grace = object_tracker->keep_grace;
params->max_observations = object_tracker->max_observations;
params->iou_threshold = object_tracker->get_iou_threshold();
params->threshold = object_tracker->get_threshold();
return EI_IMPULSE_OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ EI_IMPULSE_ERROR process_perfcal(ei_impulse_handle_t *handle,
return EI_IMPULSE_OK;
}

EI_IMPULSE_ERROR display_perfcal(ei_impulse_result_t *result,
void *config)
{
// print the detected label
ei_printf("Detected label: %s\r\n", result->postprocessed_output.perf_cal_output.detected_label);

return EI_IMPULSE_OK;
}

EI_IMPULSE_ERROR set_post_process_params(ei_impulse_handle_t* handle, ei_perf_cal_params_t* params) {
int16_t block_number = get_block_number(handle, (void*)init_perfcal);
if (block_number == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ extern "C" EI_IMPULSE_ERROR deinit_postprocessing(ei_impulse_handle_t *handle) {
}

extern "C" EI_IMPULSE_ERROR run_postprocessing(ei_impulse_handle_t *handle,
ei_impulse_result_t *result,
bool debug) {
ei_impulse_result_t *result) {
if (!handle) {
return EI_IMPULSE_OUT_OF_MEMORY;
}
Expand All @@ -100,4 +99,26 @@ extern "C" EI_IMPULSE_ERROR run_postprocessing(ei_impulse_handle_t *handle,
return EI_IMPULSE_OK;
}

extern "C" EI_IMPULSE_ERROR display_postprocessing(ei_impulse_handle_t *handle,
ei_impulse_result_t *result) {
if (!handle) {
return EI_IMPULSE_OUT_OF_MEMORY;
}
auto impulse = handle->impulse;

for (size_t i = 0; i < impulse->postprocessing_blocks_size; i++) {

if (impulse->postprocessing_blocks[i].display_fn == nullptr) {
continue;
}

EI_IMPULSE_ERROR res = impulse->postprocessing_blocks[i].display_fn(result, impulse->postprocessing_blocks[i].config);
if (res != EI_IMPULSE_OK) {
return res;
}
}

return EI_IMPULSE_OK;
}

#endif
Loading

0 comments on commit 446f260

Please sign in to comment.