diff --git a/EdgeImpulse.EI-SDK.pdsc b/EdgeImpulse.EI-SDK.pdsc
index 24dc4a9..51d9ae9 100644
--- a/EdgeImpulse.EI-SDK.pdsc
+++ b/EdgeImpulse.EI-SDK.pdsc
@@ -5,13 +5,16 @@
EI-SDK
LICENSE-apache-2.0.txt
Edge Impulse SDK
- https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.49.21/
+ https://github.com/edgeimpulse/edge-impulse-sdk-pack/releases/download/v1.49.23/
hello@edgeimpulse.com
https://github.com/edgeimpulse/edge-impulse-sdk-pack.git
-
+
EI-SDK
+
+ EI-SDK
+
EI-SDK
@@ -128,7 +131,7 @@
-
+
Edge Impulse SDK
diff --git a/EdgeImpulse.pidx b/EdgeImpulse.pidx
index 74f0f02..97f498e 100644
--- a/EdgeImpulse.pidx
+++ b/EdgeImpulse.pidx
@@ -2,8 +2,8 @@
EdgeImpulse
https://raw.githubusercontent.com/edgeimpulse/edge-impulse-sdk-pack/main/
- 2024-05-03 10:40:48
+ 2024-05-09 08:51:12
-
+
diff --git a/edgeimpulse/edge-impulse-sdk/classifier/ei_model_types.h b/edgeimpulse/edge-impulse-sdk/classifier/ei_model_types.h
index c85e8d6..ddd5158 100644
--- a/edgeimpulse/edge-impulse-sdk/classifier/ei_model_types.h
+++ b/edgeimpulse/edge-impulse-sdk/classifier/ei_model_types.h
@@ -73,6 +73,7 @@
#define EI_CLASSIFIER_IMAGE_SCALING_TORCH 2
#define EI_CLASSIFIER_IMAGE_SCALING_MIN1_1 3
#define EI_CLASSIFIER_IMAGE_SCALING_MIN128_127 4
+#define EI_CLASSIFIER_IMAGE_SCALING_BGR_SUBTRACT_IMAGENET_MEAN 5
// maps back to ClassificationMode in keras-types.ts
#define EI_CLASSIFIER_CLASSIFICATION_MODE_CLASSIFICATION 1
diff --git a/edgeimpulse/edge-impulse-sdk/classifier/ei_run_classifier.h b/edgeimpulse/edge-impulse-sdk/classifier/ei_run_classifier.h
index 8a81038..c0a2022 100644
--- a/edgeimpulse/edge-impulse-sdk/classifier/ei_run_classifier.h
+++ b/edgeimpulse/edge-impulse-sdk/classifier/ei_run_classifier.h
@@ -620,6 +620,8 @@ to preserve backwards compatibility. */
#if EI_CLASSIFIER_LOAD_IMAGE_SCALING
static const float torch_mean[] = { 0.485, 0.456, 0.406 };
static const float torch_std[] = { 0.229, 0.224, 0.225 };
+// This is ordered BGR
+static const float tao_mean[] = { 103.939, 116.779, 123.68 };
EI_IMPULSE_ERROR ei_scale_fmatrix(ei_learning_block_t *block, ei::matrix_t *fmatrix) {
if (block->image_scaling == EI_CLASSIFIER_IMAGE_SCALING_TORCH) {
@@ -661,6 +663,20 @@ EI_IMPULSE_ERROR ei_scale_fmatrix(ei_learning_block_t *block, ei::matrix_t *fmat
return EI_IMPULSE_DSP_ERROR;
}
}
+ else if (block->image_scaling == EI_CLASSIFIER_IMAGE_SCALING_BGR_SUBTRACT_IMAGENET_MEAN) {
+ int scale_res = numpy::scale(fmatrix, 255.0f);
+ if (scale_res != EIDSP_OK) {
+ ei_printf("ERR: Failed to scale matrix (%d)\n", scale_res);
+ return EI_IMPULSE_DSP_ERROR;
+ }
+ // Transpose RGB to BGR and subtract mean
+ for (size_t ix = 0; ix < fmatrix->rows * fmatrix->cols; ix += 3) {
+ float r = fmatrix->buffer[ix + 0];
+ fmatrix->buffer[ix + 0] = fmatrix->buffer[ix + 2] - tao_mean[0];
+ fmatrix->buffer[ix + 1] -= tao_mean[1];
+ fmatrix->buffer[ix + 2] = r - tao_mean[2];
+ }
+ }
return EI_IMPULSE_OK;
}
@@ -705,6 +721,20 @@ EI_IMPULSE_ERROR ei_unscale_fmatrix(ei_learning_block_t *block, ei::matrix_t *fm
return EI_IMPULSE_DSP_ERROR;
}
}
+ else if (block->image_scaling == EI_CLASSIFIER_IMAGE_SCALING_BGR_SUBTRACT_IMAGENET_MEAN) {
+ // Transpose BGR to RGB and add mean
+ for (size_t ix = 0; ix < fmatrix->rows * fmatrix->cols; ix += 3) {
+ float b = fmatrix->buffer[ix + 0];
+ fmatrix->buffer[ix + 0] = fmatrix->buffer[ix + 2] + tao_mean[2];
+ fmatrix->buffer[ix + 1] += tao_mean[1];
+ fmatrix->buffer[ix + 2] = b + tao_mean[0];
+ }
+ int scale_res = numpy::scale(fmatrix, 1 / 255.0f);
+ if (scale_res != EIDSP_OK) {
+ ei_printf("ERR: Failed to scale matrix (%d)\n", scale_res);
+ return EI_IMPULSE_DSP_ERROR;
+ }
+ }
return EI_IMPULSE_OK;
}
#endif