Human detection is a subtask of object detection, which utilizes computer vision technology to identify the presence of pedestrians in images or videos and provide the specific location information for each pedestrian. This information is crucial for various applications such as intelligent video surveillance, human behavior analysis, autonomous driving, and intelligent robots.
| 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 | Human 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 evaluation set for the above accuracy metrics is CrowdHuman dataset mAP(0.5:0.95). GPU inference time is based on an NVIDIA Tesla T4 machine with FP32 precision. CPU inference speed is based on an Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz with 8 threads and FP32 precision.
❗ Before quick integration, please install the PaddleX wheel package. For detailed instructions, refer to PaddleX Local Installation Guide
After installing the wheel package, you can perform human detection with just a few lines of code. You can easily switch between models in this module and integrate the human detection model inference into your project. Before running the following code, please download the demo image to your local machine.
from paddlex import create_model
model_name = "PP-YOLOE-S_human"
model = create_model(model_name)
output = model.predict("human_detection.jpg", batch_size=1)
for res in output:
res.print(json_format=False)
res.save_to_img("./output/")
res.save_to_json("./output/res.json")
For more information on using PaddleX's single-model inference API, refer to PaddleX Single Model Python Script Usage Instructions.
If you aim for higher accuracy with existing models, you can leverage PaddleX's custom development capabilities to develop better human detection models. Before using PaddleX to develop human detection models, ensure you have installed the PaddleDetection plugin for PaddleX. The installation process can be found in the PaddleX Local Installation Guide.
Before model training, you need to prepare a dataset for the specific task module. PaddleX provides a data validation function for each module, and only data that passes validation can be used for model training. Additionally, PaddleX provides demo datasets for each module, which you can use to complete subsequent development. If you wish to use a private dataset for model training, refer to PaddleX Object Detection Task Module Data Annotation Tutorial.
You can download the demo dataset to a specified folder using the following commands:
cd /path/to/paddlex
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/widerperson_coco_examples.tar -P ./dataset
tar -xf ./dataset/widerperson_coco_examples.tar -C ./dataset/
You can complete data validation with a single command:
python main.py -c paddlex/configs/modules/human_detection/PP-YOLOE-S_human.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/widerperson_coco_examples
After executing the above command, PaddleX will validate the dataset and collect its basic information. Upon successful execution, the log will print the message Check dataset passed !. The validation result file will be saved in ./output/check_dataset_result.json, and related outputs will be saved in the ./output/check_dataset directory of the current directory. The output directory includes visualized example images and histograms of sample distributions.
The specific content of the validation result file is:
{
"done_flag": true,
"check_pass": true,
"attributes": {
"num_classes": 1,
"train_samples": 500,
"train_sample_paths": [
"check_dataset/demo_img/000041.jpg",
"check_dataset/demo_img/000042.jpg",
"check_dataset/demo_img/000044.jpg"
],
"val_samples": 100,
"val_sample_paths": [
"check_dataset/demo_img/001138.jpg",
"check_dataset/demo_img/001140.jpg",
"check_dataset/demo_img/001141.jpg"
]
},
"analysis": {
"histogram": "check_dataset/histogram.png"
},
"dataset_path": "./dataset/example_data/widerperson_coco_examples",
"show_type": "image",
"dataset_type": "COCODetDataset"
}
In the above validation results, check_pass being True indicates that the dataset format meets the requirements. The explanations for other indicators are as follows:
attributes.num_classes:The number of classes in this dataset is 1.attributes.train_samples:The number of samples in the training set of this dataset is 500.attributes.val_samples:The number of samples in the validation set of this dataset is 100.attributes.train_sample_paths:A list of relative paths to the visualized images of samples in the training set of this dataset.attributes.val_sample_paths: A list of relative paths to the visualized images of samples in the validation set of this dataset.The dataset validation also analyzes the distribution of sample counts across all classes in the dataset and generates a histogram (histogram.png) to visualize this distribution.
After completing the dataset verification, you can convert the dataset format or re-split the training/validation ratio by modifying the configuration file or appending hyperparameters.
(1) Dataset Format Conversion
Human detection does not support data format conversion.
(2) Dataset Splitting
Dataset splitting parameters can be set by modifying the CheckDataset section in the configuration file. Some example parameters in the configuration file are explained below:
CheckDataset:split:enable: Whether to re-split the dataset. Set to True to enable dataset splitting, default is False;train_percent: If re-splitting the dataset, set the percentage of the training set. The type is any integer between 0-100, ensuring the sum with val_percent is 100;For example, if you want to re-split the dataset with a 90% training set and a 10% validation set, modify the configuration file as follows:
......
CheckDataset:
......
split:
enable: True
train_percent: 90
val_percent: 10
......
Then execute the command:
python main.py -c paddlex/configs/modules/human_detection/PP-YOLOE-S_human.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/widerperson_coco_examples
After dataset splitting, the original annotation files will be renamed to xxx.bak in their original paths.
The above parameters can also be set by appending command-line arguments:
python main.py -c paddlex/configs/modules/human_detection/PP-YOLOE-S_human.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/widerperson_coco_examples \
-o CheckDataset.split.enable=True \
-o CheckDataset.split.train_percent=90 \
-o CheckDataset.split.val_percent=10
Model training can be completed with a single command, taking the training of PP-YOLOE-S_human as an example:
python main.py -c paddlex/configs/modules/human_detection/PP-YOLOE-S_human.yaml \
-o Global.mode=train \
-o Global.dataset_dir=./dataset/widerperson_coco_examples
The steps required are:
.yaml configuration file path for the model (here it is PP-YOLOE-S_human.yaml,When training other models, you need to specify the corresponding configuration files. The relationship between the model and configuration files can be found in the PaddleX Model List (CPU/GPU))-o Global.mode=train-o Global.dataset_dir
Other related parameters can be set by modifying the Global and Train fields in the .yaml configuration file, or adjusted by appending parameters in the command line. For example, to specify training on the first two GPUs: -o Global.device=gpu:0,1; to set the number of training epochs to 10: -o Train.epochs_iters=10. For more modifiable parameters and their detailed explanations, refer to the PaddleX Common Configuration Parameters for Model Tasks.output. To specify a save path, use the -o Global.output field in the configuration file.After completing the model training, all outputs are saved in the specified output directory (default is ./output/), typically including:
train_result.json: Training result record file, recording whether the training task was completed normally, as well as the output weight metrics, related file paths, etc.;
train.log: Training log file, recording changes in model metrics and loss during training;config.yaml: Training configuration file, recording the hyperparameter configuration for this training session;.pdparams, .pdema, .pdopt.pdstate, .pdiparams, .pdmodel: Model weight-related files, including network parameters, optimizer, EMA, static graph network parameters, static graph network structure, etc.;After completing model training, you can evaluate the specified model weight file on the validation set to verify the model's accuracy. Using PaddleX for model evaluation, you can complete the evaluation with a single command:
python main.py -c paddlex/configs/modules/human_detection/PP-YOLOE-S_human.yaml \
-o Global.mode=evaluate \
-o Global.dataset_dir=./dataset/widerperson_coco_examples
Similar to model training, the process involves the following steps:
.yaml configuration file for the model(here it's PP-YOLOE-S_human.yaml)-o Global.mode=evaluate-o Global.dataset_dir
Other related parameters can be configured by modifying the fields under Global and Evaluate in the .yaml configuration file. For detailed information, please refer toPaddleX Common Configuration Parameters for Models。When evaluating the model, you need to specify the model weights file path. Each configuration file has a default weight save path built-in. If you need to change it, simply set it by appending a command line parameter, such as -o Evaluate.weight_path=./output/best_model/best_model/model.pdparams.
After completing the model evaluation, an evaluate_result.json file will be generated, which records the evaluation results, specifically whether the evaluation task was completed successfully, and the model's evaluation metrics, including AP.
After completing model training and evaluation, you can use the trained model weights for inference prediction. In PaddleX, model inference prediction can be achieved through two methods: command line and wheel package.
To perform inference prediction through the command line, simply use the following command. Before running the following code, please download the demo image to your local machine.
python main.py -c paddlex/configs/modules/human_detection/PP-YOLOE-S_human.yaml \
-o Global.mode=predict \
-o Predict.model_dir="./output/best_model/inference" \
-o Predict.input="human_detection.jpg"
Similar to model training and evaluation, the following steps are required:
Specify the .yaml configuration file path of the model (here it is PP-YOLOE-S_human.yaml)
Set the mode to model inference prediction: -o Global.mode=predict
Specify the model weights path: -o Predict.model_dir="./output/best_model/inference"
Specify the input data path: -o Predict.input="..."
Other related parameters can be set by modifying the fields under Global and Predict in the .yaml configuration file. For details, please refer to PaddleX Common Model Configuration File Parameter Description.
The pedestrian detection module can be integrated into PaddleX pipelines such as Human Keypoint Detection. You can update the keypoint detection module in the production line simply by replacing the model path. In production line integration, you can deploy your models using high-performance deployment and service deployment methods.
The weights you produce can be directly integrated into the pedestrian detection module. You can refer to the Python example code in Quick Integration. Simply replace the model with the path to your trained model to complete the integration.