---
comments: true
---
# Pedestrian Attribute Recognition Pipeline Tutorial
## 1. Introduction to Pedestrian Attribute Recognition Pipeline
Pedestrian attribute recognition is a key function in computer vision systems, used to locate and label specific characteristics of pedestrians in images or videos, such as gender, age, clothing color, and style. This task not only requires accurately detecting pedestrians but also identifying detailed attribute information for each pedestrian. The pedestrian attribute recognition pipeline is an end-to-end serial system for locating and recognizing pedestrian attributes, widely used in smart cities, security surveillance, and other fields, significantly enhancing the system's intelligence level and management efficiency.
The pedestrian attribute recognition pipeline includes a pedestrian detection module and a pedestrian attribute recognition module, with several models in each module. Which models to use specifically can be selected based on the benchmark data below. If you prioritize model accuracy, choose models with higher accuracy; if you prioritize inference speed, choose models with faster inference; if you prioritize model storage size, choose models with smaller storage.
Pedestrian Detection Module:
| Model | Model Download Link | mAP(0.5:0.95) | mAP(0.5) | GPU Inference Time (ms) | CPU Inference Time (ms) | Model Size (M) | Description |
|---|---|---|---|---|---|---|---|
| PP-YOLOE-L_human | Inference Model/Trained Model | 48.0 | 81.9 | 32.8 | 777.7 | 196.02 | Pedestrian detection model based on PP-YOLOE |
| PP-YOLOE-S_human | Inference Model/Trained Model | 42.5 | 77.9 | 15.0 | 179.3 | 28.79 |
Note: The above accuracy metrics are mAP(0.5:0.95) on the CrowdHuman dataset. All model GPU inference times are based on an NVIDIA Tesla T4 machine with FP32 precision. CPU inference speeds are based on an Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz with 8 threads and FP32 precision.
Pedestrian Attribute Recognition Module:
| Model | Model Download Link | mAP (%) | GPU Inference Time (ms) | CPU Inference Time (ms) | Model Size (M) | Description |
|---|---|---|---|---|---|---|
| PP-LCNet_x1_0_pedestrian_attribute | Inference Model/Trained Model | 92.2 | 3.84845 | 9.23735 | 6.7 M | PP-LCNet_x1_0_pedestrian_attribute is a lightweight pedestrian attribute recognition model based on PP-LCNet, covering 26 categories. |
Note: The above accuracy metrics are mA on PaddleX's internally built dataset. GPU inference times are based on an NVIDIA Tesla T4 machine with FP32 precision. CPU inference speeds are based on an 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 quickly demonstrate their effectiveness. You can experience the pedestrian attribute recognition pipeline online or locally using command line or Python. ### 2.1 Online Experience Not supported yet. ### 2.2 Local Experience Before using the pedestrian attribute recognition pipeline locally, ensure you have completed the installation of the PaddleX wheel package following the [PaddleX Local Installation Tutorial](../../../installation/installation.en.md). #### 2.2.1 Command Line Experience You can quickly experience the pedestrian attribute recognition pipeline with a single command. Use the [test file](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/pedestrian_attribute_002.jpg) and replace `--input` with the local path for prediction. ```bash paddlex --pipeline pedestrian_attribute_recognition --input pedestrian_attribute_002.jpg --device gpu:0 ``` Parameter Description: ``` --pipeline: The name of the pipeline, here it is the pedestrian attribute recognition pipeline. --input: The local path or URL of the input image to be processed. --device: The GPU index to use (e.g., gpu:0 means using the first GPU, gpu:1,2 means using the second and third GPUs), or you can choose to use CPU (--device cpu). ``` When executing the above Python script, the default pedestrian attribute recognition pipeline configuration file is loaded. If you need a custom configuration file, you can run the following command to obtain it:paddlex --get_pipeline_config pedestrian_attribute_recognition
After execution, the pedestrian attribute recognition pipeline configuration file will be saved in the current path. If you wish to specify a custom save location, you can run the following command (assuming the custom save location is ./my_path):
paddlex --get_pipeline_config pedestrian_attribute_recognition --save_path ./my_path
After obtaining the pipeline configuration file, you can replace --pipeline with the saved path of the configuration file to make it effective. For example, if the configuration file is saved at ./pedestrian_attribute_recognition.yaml, simply execute:
paddlex --pipeline ./pedestrian_attribute_recognition.yaml --input pedestrian_attribute_002.jpg --device gpu:0
Among them, parameters such as --model and --device do not need to be specified, and the parameters in the configuration file will be used. If parameters are still specified, the specified parameters will take precedence.
| Parameter | Description | Parameter Type | Default Value |
|---|---|---|---|
pipeline |
The name of the pipeline or the path to the pipeline configuration file. If it is the name of the pipeline, it must be a pipeline supported by PaddleX. | str |
None |
device |
The device for pipeline model inference. Supports: "gpu", "cpu". | str |
"gpu" |
use_hpip |
Whether to enable high-performance inference, only available when the pipeline supports high-performance inference. | bool |
False |
| Parameter Type | Description |
|---|---|
| Python Var | Supports directly passing in Python variables, such as image data represented by numpy.ndarray. |
str |
Supports passing in the file path of the data to be predicted, such as the local path of an image file: /root/data/img.jpg. |
str |
Supports passing in the URL of the data file to be predicted, such as the network URL of an image file: Example. |
str |
Supports passing in a local directory, which should contain the data files to be predicted, such as the local path: /root/data/. |
dict |
Supports passing in a dictionary type, where the key needs to correspond to the specific task, such as "img" for the pedestrian attribute recognition task, and the value of the dictionary supports the above data types, for example: {"img": "/root/data1"}. |
list |
Supports passing in a list, where the elements of the list need to be the above data types, such as [numpy.ndarray, numpy.ndarray], ["/root/data/img1.jpg", "/root/data/img2.jpg"], ["/root/data1", "/root/data2"], [{"img": "/root/data1"}, {"img": "/root/data2/img.jpg"}]. |
| Method | Description | Method Parameters |
|---|---|---|
print |
Print the results to the terminal | - format_json: bool, whether to format the output content with json indentation, default is True;- indent: int, json formatting setting, only effective when format_json is True, default is 4;- ensure_ascii: bool, json formatting setting, only effective when format_json is True, default is False; |
save_to_json |
Save the results as a json-formatted file | - save_path: str, the path to save the file, when it is a directory, the saved file name is consistent with the input file name;- indent: int, json formatting setting, default is 4;- ensure_ascii: bool, json formatting setting, default is False; |
save_to_img |
Save the results as an image file |
For primary operations provided by the service:
200, and the response body properties are as follows:| Name | Type | Description |
|---|---|---|
logId |
string |
UUID for the request. |
errorCode |
integer |
Error code. Fixed as 0. |
errorMsg |
string |
Error description. Fixed as "Success". |
result |
object |
Operation result. |
| Name | Type | Description |
|---|---|---|
logId |
string |
UUID for the request. |
errorCode |
integer |
Error code. Same as the response status code. |
errorMsg |
string |
Error description. |
Primary operations provided by the service are as follows:
inferGet pedestrian attribute recognition results.
POST /pedestrian-attribute-recognition
| Name | Type | Description | Required |
|---|---|---|---|
image |
string |
The URL of an image file accessible by the server or the Base64 encoded result of the image file content. | Yes |
result of the response body has the following properties:| Name | Type | Description |
|---|---|---|
pedestrians |
array |
Information about the pedestrian's location and attributes. |
image |
string |
The pedestrian attribute recognition result image. The image is in JPEG format and encoded using Base64. |
Each element in pedestrians is an object with the following properties:
| Name | Type | Description |
|---|---|---|
bbox |
array |
The location of the pedestrian. The elements in the array are the x-coordinate of the top-left corner, the y-coordinate of the top-left corner, the x-coordinate of the bottom-right corner, and the y-coordinate of the bottom-right corner of the bounding box, respectively. |
attributes |
array |
The pedestrian attributes. |
score |
number |
The detection score. |
Each element in attributes is an object with the following properties:
| Name | Type | Description |
|---|---|---|
label |
string |
The label of the attribute. |
score |
number |
The classification score. |
import base64
import requests
API_URL = "http://localhost:8080/pedestrian-attribute-recognition"
image_path = "./demo.jpg"
output_image_path = "./out.jpg"
with open(image_path, "rb") as file:
image_bytes = file.read()
image_data = base64.b64encode(image_bytes).decode("ascii")
payload = {"image": image_data}
response = requests.post(API_URL, json=payload)
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 pedestrians:")
print(result["pedestrians"])