This model detects palm bounding boxes and palm landmarks, and is converted from Tensorflow-JS to ONNX using following tools:
- tfjs to tf_saved_model: https://github.com/patlevin/tfjs-to-tf/
- tf_saved_model to ONNX: https://github.com/onnx/tensorflow-onnx
- simplified by [onnx-simplifier](https://github.com/daquexian/onnx-simplifier)
Also note that the model is quantized in per-channel mode with [Intel's neural compressor](https://github.com/intel/neural-compressor), which gives better accuracy but may lose some speed.
## Demo
Run the following commands to try the demo:
```bash
# detect on camera input
python demo.py
# detect on an image
python demo.py -i /path/to/image
```
NOTE: For the quantized model, you will need to install OpenCV 4.6.0 to have asymmetric paddings support for quantized convolution layer in OpenCV. Score threshold needs to be adjusted as well for the quantized model, which is empirically 0.49.
## License
All files in this directory are licensed under [Apache 2.0 License](./LICENSE).
help_msg_backends="Choose one of the computation backends: {:d}: OpenCV implementation (default); {:d}: CUDA"
help_msg_targets="Chose one of the target computation devices: {:d}: CPU (default); {:d}: CUDA; {:d}: CUDA fp16"
try:
backends+=[cv.dnn.DNN_BACKEND_TIMVX]
targets+=[cv.dnn.DNN_TARGET_NPU]
help_msg_backends+="; {:d}: TIMVX"
help_msg_targets+="; {:d}: NPU"
except:
print('This version of OpenCV does not support TIM-VX and NPU. Visit https://gist.github.com/fengyuentau/5a7a5ba36328f2b763aea026c43fa45f for more information.')
parser=argparse.ArgumentParser(description='Hand Detector from MediaPipe')
parser.add_argument('--input','-i',type=str,help='Path to the input image. Omit for using default camera.')
parser.add_argument('--model','-m',type=str,default='./palm_detection_mediapipe_2022may.onnx',help='Path to the model.')
parser.add_argument('--score_threshold',type=float,default=0.99,help='Filter out faces of confidence < conf_threshold. An empirical score threshold for the quantized model is 0.49.')
parser.add_argument('--nms_threshold',type=float,default=0.3,help='Suppress bounding boxes of iou >= nms_threshold.')
parser.add_argument('--save','-s',type=str,default=False,help='Set true to save results. This flag is invalid when using camera.')
parser.add_argument('--vis','-v',type=str2bool,default=True,help='Set true to open a window for result visualization. This flag is invalid when using camera.')