--- comments: true --- # Human Keypoint Detection Pipeline User Guide ## 1. Introduction to Human Keypoint Detection Pipeline Human keypoint detection aims to analyze human posture and movements by identifying and locating specific joints and parts of the human body. This task requires not only detecting humans in images but also accurately obtaining the positions of keypoints such as shoulders, elbows, knees, etc., for pose estimation and behavior recognition. Human keypoint detection is widely used in sports analysis, health monitoring, animation production, and human-computer interaction. PaddleX's Human Keypoint Detection Pipeline is a Top-Down solution consisting of pedestrian detection and keypoint detection modules, optimized for mobile devices. It can accurately and smoothly perform multi-person pose estimation tasks on mobile devices. The Human Keypoint Detection Pipeline includes pedestrian detection and human keypoint detection modules, with several models available. You can choose the model based on the benchmark data below. If you prioritize model accuracy, choose a model with higher accuracy; if you prioritize inference speed, choose a model with faster inference speed; if you prioritize storage size, choose a model with a smaller storage size. 👉Model List Details Pedestrian Detection Module:
Model mAP(0.5:0.95) mAP(0.5) CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M) Description
PP-YOLOE-L_human 48.0 81.9 33.27 / 9.19 173.72 / 173.72 196.02 Pedestrian detection model based on PP-YOLOE
PP-YOLOE-S_human 42.5 77.9 9.94 / 3.42 54.48 / 46.52 28.79
Note: The above accuracy metrics are based on the CrowdHuman dataset mAP(0.5:0.95). All model GPU inference times are based on NVIDIA Tesla T4 machines with FP32 precision, and CPU inference speeds are based on Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz with 8 threads and FP32 precision. Human Keypoint Detection Module:
Model Solution Input Size AP(0.5:0.95) CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M) Description
PP-TinyPose_128x96 Top-Down 128*96 58.4 4.9 PP-TinyPose is a real-time keypoint detection model developed by Baidu PaddlePaddle Vision Team, optimized for mobile devices, capable of smoothly performing multi-person pose estimation tasks on mobile devices
PP-TinyPose_256x192 Top-Down 256*192 68.3 4.9
Note: The above accuracy metrics are based on the COCO dataset AP(0.5:0.95), with detection boxes obtained from ground truth annotations. All model GPU inference times are based on NVIDIA Tesla T4 machines with FP32 precision, and CPU inference speeds are based on Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz with 8 threads and FP32 precision. ## 2. Quick Start The pre-trained model pipelines provided by PaddleX can be quickly experienced. You can use Python locally to experience the effects of the general image recognition pipeline. ### 2.1 Online Experience Not supported for online experience. ### 2.2 Local Experience > ❗ Before using the Human Keypoint Detection Pipeline locally, please ensure that you have completed the installation of the PaddleX wheel package according to the [PaddleX Installation Guide](../../../installation/installation.en.md). #### 2.2.1 Command Line Experience You can quickly experience the Human Keypoint Detection Pipeline with a single command. Use the [test file](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/keypoint_detection_001.jpg) and replace `--input` with your local path for prediction. Due to network issues, the above web page parsing was not successful. If you need the content of the web page, please check the validity of the web page link and try again. If you do not need the parsing of this link, you can proceed with other questions. ```bash paddlex --pipeline human_keypoint_detection \ --input keypoint_detection_001.jpg \ --det_threshold 0.5 \ --save_path ./output/ \ --device gpu:0 ``` The relevant parameter descriptions and results explanations can be referred to in the parameter explanations and results explanations of [2.2.2 Integration via Python Script](#222-integration-via-python-script). The visualization results are saved to `save_path`, as shown below: #### 2.2.2 Integration via Python Script The above command line method allows you to quickly experience and view the results. In a project, code integration is often required. You can complete the quick inference of the pipeline with the following lines of code: ```python from paddlex import create_pipeline pipeline = create_pipeline(pipeline="human_keypoint_detection") output = pipeline.predict("keypoint_detection_001.jpg", det_threshold=0.5) for res in output: res.print() res.save_to_img("./output/") res.save_to_json("./output/") ``` In the above Python script, the following steps are executed: (1) Call the `create_pipeline` function to instantiate a pipeline object. The specific parameter descriptions are as follows:
Parameter Description Type Default Value
pipeline The name of the pipeline or the path to the pipeline configuration file. If it is a pipeline name, it must be supported by PaddleX. str None
config Specific configuration information for the pipeline (if set simultaneously with the pipeline, it takes precedence over the pipeline, and the pipeline name must match the pipeline). dict[str, Any] None
device The device used for pipeline inference. It supports specifying the specific card number of GPU, such as "gpu:0", other hardware card numbers, such as "npu:0", or CPU, such as "cpu". str gpu:0
use_hpip Whether to enable high-performance inference. This is only available if the pipeline supports high-performance inference. bool False
(2) Call the `predict()` method of the human keypoint detection pipeline object for inference prediction. This method returns a `generator`. Below are the parameters and their descriptions for the `predict()` method:
Parameter Description Type Options Default Value
input Data to be predicted. It supports multiple input types and is a required parameter. Python Var|str|list
  • Python Var: Image data represented by numpy.ndarray.
  • str: Local path of an image file, such as /root/data/img.jpg; URL link, such as a network URL of an image file: example; Local directory, which should contain images to be predicted, such as /root/data/.
  • List: Elements of the list must be of the above types, such as [numpy.ndarray, numpy.ndarray], [\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"], or [\"/root/data1\", \"/root/data2\"].
None
threshold Threshold for the human detection model. float|None
  • float: For example, 0.5 means filtering out all bounding boxes with a score lower than 0.5.
  • None: If set to None, the default value initialized by the pipeline will be used, which is 0.5.
None
(3) Process the prediction results. The prediction result for each sample is of type `dict`, and supports operations such as printing, saving as an image, and saving as a `json` file:
Method Description Parameter Type Parameter Description Default Value
print() Print the result to the terminal format_json bool Whether to format the output content using JSON indentation True
indent int Specify the indentation level to beautify the output JSON data, making it more readable. This is only effective when format_json is True 4
ensure_ascii bool Control whether non-ASCII characters are escaped to Unicode. When set to True, all non-ASCII characters will be escaped; False retains the original characters. This is only effective when format_json is True False
save_to_json() Save the result as a JSON file save_path str The file path for saving. When it is a directory, the saved file name will match the input file name N/A
indent int Specify the indentation level to beautify the output JSON data, making it more readable. This is only effective when format_json is True 4
ensure_ascii bool Control whether non-ASCII characters are escaped to Unicode. When set to True, all non-ASCII characters will be escaped; False retains the original characters. This is only effective when format_json is True False
save_to_img() Save the result as an image file save_path str The file path for saving, supporting both directory and file paths N/A
- The output result parameters are as follows: - `input_path`: Indicates the path of the input image - `boxes`: Detected human body information, a list of dictionaries, each dictionary contains the following information: - `coordinate`: Coordinates of the human body target box, in the format [xmin, ymin, xmax, ymax] - `det_score`: Confidence score of the human body target box - `keypoints`: Keypoint coordinate information, a numpy array with shape [num_keypoints, 3], where each keypoint consists of [x, y, score], and score is the confidence score of the keypoint - `kpt_score`: Overall confidence score of the keypoints, which is the average confidence score of the keypoints - Calling the `save_to_json()` method will save the above content to the specified `save_path`. If specified as a directory, the saved path will be `save_path/{your_img_basename}_res.json`; if specified as a file, it will be saved directly to that file. Since JSON files do not support saving numpy arrays, the `numpy.array` types will be converted to lists. - Calling the `save_to_img()` method will save the visualization results to the specified `save_path`. If specified as a directory, the saved path will be `save_path/{your_img_basename}_res.{your_img_extension}`; if specified as a file, it will be saved directly to that file. (The production line usually contains many result images, it is not recommended to specify a specific file path directly, otherwise multiple images will be overwritten, leaving only the last image) * Additionally, it also supports obtaining visualized images and prediction results through attributes, as follows:
Attribute Attribute Description
json Get the predicted json format result
img Get the visualized image in dict format
- The prediction result obtained by the `json` attribute is a dict type of data, with content consistent with the content saved by calling the `save_to_json()` method. - The prediction result returned by the `img` attribute is a dictionary type of data. The key is `res`, and the corresponding value is an `Image.Image` object used for visualizing the human keypoint detection results. The above Python script integration method uses the parameter settings from the PaddleX official configuration file by default. If you need to customize the configuration file, you can execute the following command to obtain the official configuration file and save it in `my_path`: ```bash paddlex --get_pipeline_config human_keypoint_detection --save_path ./my_path ``` If you have obtained the configuration file, you can customize the settings for the human keypoint detection pipeline. Simply modify the value of the `pipeline` parameter in the `create_pipeline` method to the path of your custom pipeline configuration file. For example, if your custom configuration file is saved at `./my_path/human_keypoint_detection.yaml`, you just need to execute: ```python from paddlex import create_pipeline pipeline = create_pipeline(pipeline="./my_path/human_keypoint_detection.yaml") output = pipeline.predict("keypoint_detection_001.jpg") for res in output: res.print() res.save_to_img("./output/") res.save_to_json("./output/") ``` ## 3. Development Integration/Deployment If the human keypoint detection pipeline meets your requirements for inference speed and accuracy, you can proceed directly with development integration/deployment. If you need to apply the general image recognition pipeline directly to your Python project, you can refer to the example code in [2.2.2 Python Script Integration](#222-python-script-integration). Additionally, PaddleX provides three other deployment methods, detailed as follows: 🚀 High-Performance Inference: In actual production environments, many applications have stringent standards for the performance metrics of deployment strategies (especially response speed) to ensure efficient system operation and smooth user experience. For this purpose, PaddleX provides a high-performance inference plugin, aimed at deeply optimizing the performance of model inference and pre/post-processing, significantly accelerating the end-to-end process. For detailed high-performance inference procedures, please refer to [PaddleX High-Performance Inference Guide](../../../pipeline_deploy/high_performance_inference.en.md). ☁️ Service Deployment: Service deployment is a common form of deployment in actual production environments. By encapsulating the inference function as a service, clients can access these services via network requests to obtain inference results. PaddleX supports multiple pipeline service deployment solutions. For detailed pipeline service deployment procedures, please refer to [PaddleX Service Deployment Guide](../../../pipeline_deploy/serving.en.md). Below are the API references and multi-language service invocation examples for basic service deployment:
API Reference
Multi-language Service Invocation Examples
Python
import base64
import requests

API_URL = "http://localhost:8080/ocr" # Service URL
image_path = "./demo.jpg"
output_image_path = "./out.jpg"

# Base64 encode the local image
with open(image_path, "rb") as file:
    image_bytes = file.read()
    image_data = base64.b64encode(image_bytes).decode("ascii")

payload = {"image": image_data}  # Base64 encoded file content or image URL

# Call the API
response = requests.post(API_URL, json=payload)

# Process the API response
assert response.status_code == 200
result = response.json()["result"]
with open(output_image_path, "wb") as file:
    file.write(base64.b64decode(result["image"]))
print(f"Output image saved at {output_image_path}")
print("\nDetected texts:")
print(result["texts"])
📱 Edge Deployment: Edge deployment is a method where computation and data processing functions are placed on the user's device itself, allowing the device to process data directly without relying on remote servers. PaddleX supports deploying models on edge devices such as Android. For detailed edge deployment procedures, please refer to [PaddleX Edge Deployment Guide](../../../pipeline_deploy/edge_deploy.en.md). You can choose the appropriate deployment method based on your needs to integrate the AI application subsequently. ## 4. Secondary Development If the default model weights provided by the human keypoint detection pipeline do not meet your accuracy or speed requirements in your scenario, you can try further fine-tuning the existing model using your own specific domain or application data to improve the recognition performance of the pipeline in your scenario. ### 4.1 Model Fine-Tuning Since the human keypoint detection pipeline consists of two modules (pedestrian detection module and human keypoint detection module), the suboptimal performance of the model pipeline may stem from either module. You can analyze the images with poor recognition performance. If you find that many pedestrian targets are not detected during the analysis, it may indicate a deficiency in the pedestrian detection model. You need to refer to the [Pedestrian Detection Module Development Tutorial](../../../module_usage/tutorials/cv_modules/human_detection.en.md) in the [Secondary Development](../../../module_usage/tutorials/cv_modules/human_detection.en.md) section to fine-tune the pedestrian detection model using your private dataset. If keypoint detection errors occur in detected pedestrians, it indicates that the keypoint detection model needs further improvement. You need to refer to the [Keypoint Detection Module Development Tutorial](../../../module_usage/tutorials/cv_modules/human_keypoint_detection.en.md) in the [Secondary Development](../../../module_usage/tutorials/cv_modules/human_keypoint_detection.en.md#secondary-development) section to fine-tune the keypoint detection model. ### 4.2 Model Application After completing the fine-tuning training with your private dataset, you will obtain a local model weight file. If you need to use the fine-tuned model weights, simply modify the pipeline configuration file by replacing the local path of the fine-tuned model weights in the corresponding position of the pipeline configuration file: ```yaml pipeline_name: human_keypoint_detection SubModules: ObjectDetection: module_name: object_detection model_name: PP-YOLOE-S_human model_dir: null #可修改为微调后行人检测模型的本地路径 batch_size: 1 threshold: null img_size: null KeypointDetection: module_name: keypoint_detection model_name: PP-TinyPose_128x96 model_dir: #可修改为微调后关键点检测模型的本地路径 batch_size: 1 flip: False use_udp: null ``` Then, refer to the command-line method or Python script method in [2.2 Local Experience](#22-Local-Experience) to load the modified production configuration file. ## 5. Multi-Hardware Support PaddleX supports a variety of mainstream hardware devices, including NVIDIA GPU, Kunlunxin XPU, Ascend NPU, and Cambricon MLU. Simply modify the `--device` parameter to seamlessly switch between different hardware. For example, using Ascend NPU for fast inference of human keypoint detection in production: ```bash paddlex --pipeline human_keypoint_detection \ --input keypoint_detection_001.jpg \ --det_threshold 0.5 \ --save_path ./output/ \ --device npu:0 ``` If you want to use the general image recognition production line on more types of hardware, please refer to the PaddleX Multi-Hardware Usage Guide.