Accelerating the MediaPipe models with Hailo

Hello RPI5 Hailo AI Kit community :slight_smile:

I would to share a project where I accelerated the MediaPipe models for Hailo-8:
Accelerating the MediaPipe models with Hailo-8

I am waiting for my RPI5 + Hailo-8L kit to test this out on the RPI5.

In the meantime, if anyone would like to try this out on their RPI5 Hailo AI Kit, please let me know …

I will only be supporting the “official” version of DFC supported by Raspberry Pi, which I believe is v3.27.0.

Enjoy !

2 Likes

Fantastic work! Your article is incredibly detailed and well-explained.

About the effort to reduce the number of contexts, another way to address this is by enabling performance mode. This can be done with:

performance_param(compiler_optimization_level=max)

This will activate an algorithm that optimizes the utilization of the device’s various resources to their maximum potential.

1 Like

Thank you very much for those kind works, and for this valuable information.
I will definitely give this a try.

Regarding my “incredibly detailed and well-explained” article, there is still so much information missing …

I have a question related to the hand_landmark_lite model in the Hailo model zoo.

HAILO8_hand_landmark_detection.rst at master · hailo-ai/hailo_model_zoo · GitHub

It is the same model that I also target in my article, which I call version 0.10 lite of the hand landmarks model.

Do you know which dataset was used to quantize/compile this model (how did Hailo solve this issue of) ?
How is Hailo measuring the accuracy for the hand_landmark_lite model in the Hailo model zoo ?

My compiled model benchmarks at 3132 FPS (probably because of the 60% 4-bit setting, but possibly at the cost of lower accuracy), compared to the Hailo model zoo version which benchmarks at 2164 FPS.

Cheers !

Mario.

You can find the link for downloading the dataset here. That same script can be used for creating the tfrecord needed for the evaluation.

For measuring accuracy, you can use the hailomz eval tool.

1 Like

Thank you so much for this valuable feedback.

I also tried the “performance_param(compiler_optimization_level=max)” setting, and it works as expected, thank you :smile:

Every time I scratch deeper or try something new with the Hailo collateral, I am pleasantly impressed :sunglasses: :+1:

Very impressed with the Hailo solution, just WOW !

Mario (another happy user)

2 Likes

Hi, can you tell me how to run the MediaPipe Pose Estimation model on Hailo? What FPS can I achieve? Do you have a link to any relevant resources or documentation?

1 Like

Simone,

The pose_detection.hef is not provided in my Hailo exploration, as compilation fails.

This is a known issue, and mentioned in the “Known Issues” of the following write-up:

Since then, I also ran into the same problem with another vendor, as described in the following write-up:

In the case of MemryX, the solution was reverting TensorFlow 2.17 down to version 2.16.3.

If you find the solution to successfully compile pose_detection with Hailo, please share your results.

Cheers !

Mario.

I have tested the latest DFC based on your code and ensured that Hailo8L can also be used. Do you mind if I modify your code and publish it on GitHub? Of course, I will reference your GitHub repository.

1 Like

Hi, have you managed to implement pose detection with MediaPipe on Hailo?

Did you manage to convert BlazePose or any other MediaPipe-based pose detection model into Hailo format (.hef)? Or did you take a different approach?

Yes, absolutely :smiling_face_with_sunglasses: :+1:

I am not trying do this, maybe I will try in a few weeks.

Hi, I try to convert mediapipe pose-detection model to hef format, but I get error like below, could you give me some suggestion
(.env) jiahao@PC:~/hailo8_mediapipe$ python3 hailo_flow.py --arch hailo8 --name pose_detection --model ./pose_detection.tflite --resolution 224 --process all --calib_dataset ./numpys/merged.np Command line options: --arch : hailo8 --blaze : hand --name : pose_detection --model : ./pose_detection.tflite --resolution : 224 --process : all --calib_dataset: ./numpys/merged.np [INFO] start_node_names : ['input_1'] [INFO] end_node_names : ['model_1/model/classifier_person_32_NO_PRUNING/BiasAdd;model_1/model/classifier_person_32_NO_PRUNING/Conv2D;model_1/model/classifier_person_32_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/classifier_person_16_NO_PRUNING/BiasAdd;model_1/model/classifier_person_16_NO_PRUNING/Conv2D;model_1/model/classifier_person_16_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/classifier_person_8_NO_PRUNING/BiasAdd;model_1/model/classifier_person_16_NO_PRUNING/Conv2D;model_1/model/classifier_person_8_NO_PRUNING/Conv2D;model_1/model/classifier_person_8_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/regressor_person_32_NO_PRUNING/BiasAdd;model_1/model/regressor_person_32_NO_PRUNING/Conv2D1', 'model_1/model/regressor_person_16_NO_PRUNING/BiasAdd;model_1/model/regressor_person_16_NO_PRUNING/Conv2D;model_1/model/regressor_person_16_NO_PRUNING/Conv2D;model_1/model/regressor_person_16_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/regressor_person_8_NO_PRUNING/BiasAdd;model_1/model/regressor_person_16_NO_PRUNING/Conv2D;model_1/model/regressor_person_8_NO_PRUNING/Conv2D;model_1/model/regressor_person_8_NO_PRUNING/BiasAdd/ReadVariableOp/resource1'] [info] Translation started on Tensorflow model pose_detection b'model_1/model/zero_padding2d/Pad/paddings' [4 2] (8,) 8 b'model_1/model/batch_normalization/FusedBatchNormV3' [24] (24,) 24 b'model_1/model/conv2d/Conv2D' [24 3 3 3] (648,) 648 b'model_1/model/batch_normalization_1/FusedBatchNormV3' [24] (24,) 24 b'model_1/model/batch_normalization_1/FusedBatchNormV3;model_1/model/depthwise_conv2d/depthwise;model_1/model/regressor_person_16_NO_PRUNING/Conv2D' [ 1 3 3 24] (216,) 216 b'model_1/model/batch_normalization_2/FusedBatchNormV3;model_1/model/conv2d_1/Conv2D' [16] (16,) 16 b'model_1/model/conv2d_1/Conv2D_dequantize' [16 1 1 24] (96,) 96 Traceback (most recent call last): File "/home/jiahao/hailo8_mediapipe/hailo_flow.py", line 117, in <module> hn, npz = runner.translate_tf_model( File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func return func(self, *args, **kwargs) File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 1240, in translate_tf_model parser.translate_tf_model( File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_model_optimization/tools/subprocess_wrapper.py", line 124, in parent_wrapper func(self, *args, **kwargs) File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py", line 78, in translate_tf_model nn_framework, graph, values, node_names = detect_tf_nn_framework(model_path, valid_net_name) File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_client/tools/tf_proto_helper.py", line 124, in detect_tf_nn_framework values[key] = np.reshape(value, tensor.ShapeAsNumpy()) File "<__array_function__ internals>", line 180, in reshape File "/home/jiahao/.env/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 298, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/home/jiahao/.env/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc return bound(*args, **kwds) ValueError: cannot reshape array of size 96 into shape (16,1,1,24)

It does not work, I get error like below:

(.env) jiahao@PC:~/hailo8_mediapipe$ python3 hailo_flow.py --arch hailo8 --name pose_detection --model ./pose_detection.tflite --resolution 224 --process all --calib_dataset ./numpys/merged.np Command line options: --arch : hailo8 --blaze : hand --name : pose_detection --model : ./pose_detection.tflite --resolution : 224 --process : all --calib_dataset: ./numpys/merged.np [INFO] start_node_names : ['input_1'] [INFO] end_node_names : ['model_1/model/classifier_person_32_NO_PRUNING/BiasAdd;model_1/model/classifier_person_32_NO_PRUNING/Conv2D;model_1/model/classifier_person_32_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/classifier_person_16_NO_PRUNING/BiasAdd;model_1/model/classifier_person_16_NO_PRUNING/Conv2D;model_1/model/classifier_person_16_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/classifier_person_8_NO_PRUNING/BiasAdd;model_1/model/classifier_person_16_NO_PRUNING/Conv2D;model_1/model/classifier_person_8_NO_PRUNING/Conv2D;model_1/model/classifier_person_8_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/regressor_person_32_NO_PRUNING/BiasAdd;model_1/model/regressor_person_32_NO_PRUNING/Conv2D1', 'model_1/model/regressor_person_16_NO_PRUNING/BiasAdd;model_1/model/regressor_person_16_NO_PRUNING/Conv2D;model_1/model/regressor_person_16_NO_PRUNING/Conv2D;model_1/model/regressor_person_16_NO_PRUNING/BiasAdd/ReadVariableOp/resource1', 'model_1/model/regressor_person_8_NO_PRUNING/BiasAdd;model_1/model/regressor_person_16_NO_PRUNING/Conv2D;model_1/model/regressor_person_8_NO_PRUNING/Conv2D;model_1/model/regressor_person_8_NO_PRUNING/BiasAdd/ReadVariableOp/resource1'] [info] Translation started on Tensorflow model pose_detection b'model_1/model/zero_padding2d/Pad/paddings' [4 2] (8,) 8 b'model_1/model/batch_normalization/FusedBatchNormV3' [24] (24,) 24 b'model_1/model/conv2d/Conv2D' [24 3 3 3] (648,) 648 b'model_1/model/batch_normalization_1/FusedBatchNormV3' [24] (24,) 24 b'model_1/model/batch_normalization_1/FusedBatchNormV3;model_1/model/depthwise_conv2d/depthwise;model_1/model/regressor_person_16_NO_PRUNING/Conv2D' [ 1 3 3 24] (216,) 216 b'model_1/model/batch_normalization_2/FusedBatchNormV3;model_1/model/conv2d_1/Conv2D' [16] (16,) 16 b'model_1/model/conv2d_1/Conv2D_dequantize' [16 1 1 24] (96,) 96 Traceback (most recent call last): File "/home/jiahao/hailo8_mediapipe/hailo_flow.py", line 117, in <module> hn, npz = runner.translate_tf_model( File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func return func(self, *args, **kwargs) File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 1240, in translate_tf_model parser.translate_tf_model( File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_model_optimization/tools/subprocess_wrapper.py", line 124, in parent_wrapper func(self, *args, **kwargs) File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py", line 78, in translate_tf_model nn_framework, graph, values, node_names = detect_tf_nn_framework(model_path, valid_net_name) File "/home/jiahao/.env/lib/python3.10/site-packages/hailo_sdk_client/tools/tf_proto_helper.py", line 124, in detect_tf_nn_framework values[key] = np.reshape(value, tensor.ShapeAsNumpy()) File "<__array_function__ internals>", line 180, in reshape File "/home/jiahao/.env/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 298, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/home/jiahao/.env/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc return bound(*args, **kwds) ValueError: cannot reshape array of size 96 into shape (16,1,1,24)

jiahao.li,

The pose_detection.hef is not provided in my Hailo exploration, as compilation fails.

This is a known issue, and mentioned in the “Known Issues” of the following write-up:

This would be a question for Hailo.

Cheers !

Mario.

Thank you for your explanation.