diff --git a/boards/ARDUINO_GIGA/romfs.json b/boards/ARDUINO_GIGA/romfs.json index 825230658..0ff11776c 100644 --- a/boards/ARDUINO_GIGA/romfs.json +++ b/boards/ARDUINO_GIGA/romfs.json @@ -38,6 +38,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/boards/ARDUINO_NICLA_VISION/romfs.json b/boards/ARDUINO_NICLA_VISION/romfs.json index 16e40bb2e..8a1c4876d 100644 --- a/boards/ARDUINO_NICLA_VISION/romfs.json +++ b/boards/ARDUINO_NICLA_VISION/romfs.json @@ -32,6 +32,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/boards/ARDUINO_PORTENTA_H7/romfs.json b/boards/ARDUINO_PORTENTA_H7/romfs.json index 825230658..0ff11776c 100644 --- a/boards/ARDUINO_PORTENTA_H7/romfs.json +++ b/boards/ARDUINO_PORTENTA_H7/romfs.json @@ -38,6 +38,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/boards/OPENMV4P/romfs.json b/boards/OPENMV4P/romfs.json index 26ef3eae3..63cc583fa 100644 --- a/boards/OPENMV4P/romfs.json +++ b/boards/OPENMV4P/romfs.json @@ -38,6 +38,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/boards/OPENMVPT/romfs.json b/boards/OPENMVPT/romfs.json index 26ef3eae3..63cc583fa 100644 --- a/boards/OPENMVPT/romfs.json +++ b/boards/OPENMVPT/romfs.json @@ -38,6 +38,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/boards/OPENMV_AE3/romfs.json b/boards/OPENMV_AE3/romfs.json index baf70a0df..84d621d8a 100644 --- a/boards/OPENMV_AE3/romfs.json +++ b/boards/OPENMV_AE3/romfs.json @@ -32,6 +32,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/boards/OPENMV_N6/romfs.json b/boards/OPENMV_N6/romfs.json index 7ab29a3a8..77cc22f75 100644 --- a/boards/OPENMV_N6/romfs.json +++ b/boards/OPENMV_N6/romfs.json @@ -19,6 +19,12 @@ "path": "{TOP}/lib/models/yolo_v5_224_nano.tflite", "alignment": 32, "profile": "default" + }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 32, + "profile": "default" } ] } diff --git a/boards/OPENMV_RT1060/romfs.json b/boards/OPENMV_RT1060/romfs.json index 26ef3eae3..63cc583fa 100644 --- a/boards/OPENMV_RT1060/romfs.json +++ b/boards/OPENMV_RT1060/romfs.json @@ -38,6 +38,12 @@ "alignment": 16, "optimize": "Performance" }, + { + "type": "tflite", + "path": "{TOP}/lib/models/blazeface_front_128.tflite", + "alignment": 16, + "optimize": "Performance" + }, { "type": "haar", "path": "{TOP}/lib/haar/haarcascade_eye.xml", diff --git a/lib/models/blazeface_front_128.tflite b/lib/models/blazeface_front_128.tflite new file mode 100644 index 000000000..a511dbc83 Binary files /dev/null and b/lib/models/blazeface_front_128.tflite differ diff --git a/scripts/libraries/ml/ml/postprocessing.py b/scripts/libraries/ml/ml/postprocessing.py index ece188568..0aa0938ec 100644 --- a/scripts/libraries/ml/ml/postprocessing.py +++ b/scripts/libraries/ml/ml/postprocessing.py @@ -344,7 +344,7 @@ class mediapipe_face_detection_postprocess: def __init__(self, threshold=0.6, anchors=None, nms_threshold=0.1, nms_sigma=0.1): self.threshold = threshold self.anchors = anchors - + if self.anchors is None: self.anchors = np.empty((896, 2)) idx = 0 @@ -364,6 +364,20 @@ class mediapipe_face_detection_postprocess: self.nms_threshold = nms_threshold self.nms_sigma = nms_sigma + def __call__(self, model, inputs, outputs): + ib, ih, iw, ic = model.input_shape[0] + nms = NMS(iw, ih, inputs[0].roi) + output_len = outputs[0].shape[1] + + self.blazeface_post_process(ih, iw, nms, model, inputs, outputs, 1, 0, + self.threshold, self.anchors[:output_len]) + + if output_len < len(self.anchors): + self.blazeface_post_process(ih, iw, nms, model, inputs, outputs, 2, 3, + self.threshold, self.anchors[output_len:]) + + return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma) + def blazeface_post_process(self, ih, iw, nms, model, inputs, outputs, score_idx, cords_idx, t, anchors): s_oh, s_ow, s_oc = model.output_shape[score_idx] scale = model.output_scale[score_idx] @@ -409,17 +423,3 @@ class mediapipe_face_detection_postprocess: for i in range(bb.shape[0]): nms.add_bounding_box(xmin[i], ymin[i], xmax[i], ymax[i], bb_scores[i], 0, keypoints=keypoints[i]) - - def __call__(self, model, inputs, outputs): - ib, ih, iw, ic = model.input_shape[0] - nms = NMS(iw, ih, inputs[0].roi) - output_len = outputs[0].shape[1] - - self.blazeface_post_process(ih, iw, nms, model, inputs, outputs, 1, 0, - self.threshold, self.anchors[:output_len]) - - if output_len < len(self.anchors): - self.blazeface_post_process(ih, iw, nms, model, inputs, outputs, 2, 3, - self.threshold, self.anchors[output_len:]) - - return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)