Skip to content

Update palm detection model from MediaPipe (2023feb) #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 14, 2023
Merged

Update palm detection model from MediaPipe (2023feb) #128

merged 8 commits into from
Feb 14, 2023

Conversation

WanliZhong
Copy link
Member

@WanliZhong WanliZhong commented Feb 7, 2023

This PR aims to change the palm detection model from tfjs model to mediapipe model. Model downloaded from https://google.github.io/mediapipe/solutions/models.html#hands

The main updates between the previous mdoel and the current model are as follows.

Model Information:

Previous Model Current Model
Model Size 6.78MB 3.72MB
Input Size 256*256 192*192

Inference Time:

Platform Previous Model Current Model
Intel-CPU 15.57ms 11.09ms
RPI-CPU 168.37ms 63.79ms
JETSON-GPU 50.64ms 83.20ms
KV3-NPU 62.45ms 33.81ms

Model Accuracy
Current model has better performance by running demo. Also fixed the bug that the aspect ratio was not kept when resizing images.

Previous Model Current Model

@WanliZhong WanliZhong added the update model request to update existing models label Feb 7, 2023
@ShiqiYu
Copy link
Member

ShiqiYu commented Feb 8, 2023

What's the main difference between this one and the previous one?

@WanliZhong
Copy link
Member Author

What's the main difference between this one and the previous one?

Thanks for reminding! I've updated the description of this PR.

@@ -34,7 +34,7 @@ Guidelines:
| [WeChatQRCode](./models/qrcode_wechatqrcode) | QR Code Detection and Parsing | 100x100 | 7.04 | 37.68 | --- | --- | --- |
| [DaSiamRPN](./models/object_tracking_dasiamrpn) | Object Tracking | 1280x720 | 36.15 | 705.48 | 76.82 | --- | --- |
| [YoutuReID](./models/person_reid_youtureid) | Person Re-Identification | 128x256 | 35.81 | 521.98 | 90.07 | 44.61 | --- |
| [MP-PalmDet](./models/palm_detection_mediapipe) | Palm Detection | 256x256 | 15.57 | 168.37 | 50.64 | 62.45 | --- |
| [MP-PalmDet](./models/palm_detection_mediapipe) | Palm Detection | 192x192 | 11.09 | 63.79 | 83.20 | 33.81 | --- |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slower on Jetson?

Copy link
Member Author

@WanliZhong WanliZhong Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After verification, this problem is caused by OpenCV version iteration. In version 4.6.0, time cost on cuda should change from 50ms to 30ms. But in version 4.7.0, time cost on cuda change from 200ms to 80ms.

This means that after the OpenCV version update, inference time of this palm detecion model is 4 times slower on cuda. Let's solved this problem firstly.
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave as-is and will be fixed in the next release.

Copy link
Member Author

@WanliZhong WanliZhong Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem is fixed by PR opencv/opencv#23243 and opencv/opencv#23255.

@ShiqiYu
Copy link
Member

ShiqiYu commented Feb 9, 2023

I tested the hand pose demo on Khadas VIM3. The FPS is the almost the same whatever I choose the TIMVX+NPU or Default+CPU. Could you check if everything is right?

@ShiqiYu
Copy link
Member

ShiqiYu commented Feb 9, 2023

The accuracy of the INT8 palm detector is obviously lower than that of the float model. Should we release the int8 model?

@WanliZhong
Copy link
Member Author

WanliZhong commented Feb 9, 2023

HandPose model still need to be updated after this PR.

I think we can add more images to quantized this model so that the accuracy may be higher.

I will try to improve this model.

@fengyuentau
Copy link
Member

I think we can include @zihaomu for discussion on the speed.

@zihaomu
Copy link
Member

zihaomu commented Feb 9, 2023

image

New palm detection model on Vim3 do have the same spped no matter if we use npu. I'm not sure why this happen.

I have compared the new and old model. And the new model has lot of PRelu layer. Because PeRelu is float32, it will cause the model to be cut into many small graph when NPU is executed. Every switch from float to int8 will be very time consuming, that's why you won't get NPU acceleration.

@WanliZhong
Copy link
Member Author

WanliZhong commented Feb 10, 2023

I re-quantified the model with 3900+ images and got a better model. The accuracy is obviously better. new model.zip

image

@@ -1,10 +1,11 @@
# Palm detector from MediaPipe Handpose

This model detects palm bounding boxes and palm landmarks, and is converted from Tensorflow-JS to ONNX using following tools:
This model detects palm bounding boxes and palm landmarks, and is converted from TFLite to ONNX using following tools:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, TFLite support in DNN has been merged. Dev branch can now load and run TFLite models.

Copy link
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fengyuentau fengyuentau self-assigned this Feb 14, 2023
@fengyuentau fengyuentau merged commit 6c68bc4 into opencv:master Feb 14, 2023
fengyuentau pushed a commit that referenced this pull request Jun 8, 2023
* update to the latest palm detection model

* quantize palm detection model

* make palm aligned to center when resize

* update benchmark for palm detection

* update benchmark data

* update readme

* update a new quantized model

* update readme
@WanliZhong WanliZhong added this to the 4.9.0 (first release) milestone Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
update model request to update existing models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants