Face detection is a fundamental task in object detection, aiming to automatically identify and locate the position and size of faces in input images. It serves as the prerequisite and foundation for subsequent tasks such as face recognition and face analysis. Face detection accomplishes this by constructing deep neural network models that learn the feature representations of faces, enabling efficient and accurate face detection.
| Model | Model Download Link | AP (%) Easy/Medium/Hard |
GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Size (M) | Description |
|---|---|---|---|---|---|---|
| BlazeFace | Inference Model/Training Model | 77.7/73.4/49.5 | 50.90 / 45.74 | 71.92 / 71.92 | 0.447 | A lightweight and efficient face detection model |
| BlazeFace-FPN-SSH | Inference Model/Training Model | 83.2/80.5/60.5 | 58.99 / 51.75 | 87.39 / 87.39 | 0.606 | An improved model of BlazeFace, incorporating FPN and SSH structures |
| PicoDet_LCNet_x2_5_face | Inference Model/Training Model | 93.7/90.7/68.1 | 33.91 / 26.53 | 153.56 / 79.21 | 28.9 | Face Detection model based on PicoDet_LCNet_x2_5 |
| PP-YOLOE_plus-S_face | Inference Model/Training Model | 93.9/91.8/79.8 | 21.28 / 11.09 | 137.26 / 72.09 | 26.5 | Face Detection model based on PP-YOLOE_plus-S |
Test Environment Description:
<li><b>Performance Test Environment</b>
<ul>
<li><strong>Test Dataset:</strong>The above accuracy metrics are evaluated on the WIDER-FACE validation set with an input size of 640*640.</li>
<li><strong>Hardware Configuration:</strong>
<ul>
<li>GPU: NVIDIA Tesla T4</li>
<li>CPU: Intel Xeon Gold 6271C @ 2.60GHz</li>
</ul>
</li>
<li><strong>Software Environment:</strong>
<ul>
<li>Ubuntu 20.04 / CUDA 11.8 / cuDNN 8.9 / TensorRT 8.6.1.6</li>
<li>paddlepaddle 3.0.0 / paddlex 3.0.3</li>
</ul>
</li>
</li>
</ul>
</li>
<li><b>Inference Mode Description</b></li>
| Mode | GPU Configuration | CPU Configuration | Acceleration Technology Combination |
|---|---|---|---|
| Normal Mode | FP32 Precision / No TRT Acceleration | FP32 Precision / 8 Threads | PaddleInference |
| High-Performance Mode | Optimal combination of pre-selected precision types and acceleration strategies | FP32 Precision / 8 Threads | Pre-selected optimal backend (Paddle/OpenVINO/TRT, etc.) |
❗ Before quick integration, please install the PaddleX wheel package first. For details, please refer to the PaddleX Local Installation Guide
After completing the installation of the wheel package, you can perform inference for the face detection module with just a few lines of code. You can switch models under this module at will, and you can also integrate the model inference of the face detection module into your project. Before running the following code, please download the example image to your local machine.
from paddlex import create_model
model_name = "PicoDet_LCNet_x2_5_face"
model = create_model(model_name)
output = model.predict("face_detection.png", batch_size=1)
for res in output:
res.print(json_format=False)
res.save_to_img("./output/")
res.save_to_json("./output/res.json")
The visualization image is as follows:

The explanations for the methods, parameters, etc., are as follows:
create_model instantiates a face detection model (here, PicoDet_LCNet_x2_5_face is used as an example), and the specific explanations are as follows:
| Parameter | Parameter Description | Parameter Type | Options | Default Value |
|---|---|---|---|---|
model_name |
Name of the model | str |
None | None |
model_dir |
Path to store the model | str |
None | None |
device |
The device used for model inference | str |
It supports specifying specific GPU card numbers, such as "gpu:0", other hardware card numbers, such as "npu:0", or CPU, such as "cpu". | gpu:0 |
img_size |
Size of the input image; if not specified, the default configuration of the PaddleX official model will be used | int/list |
|
None |
threshold |
Threshold for filtering out low-confidence prediction results; if not specified, the default configuration of the PaddleX official model will be used | float |
None | None |
use_hpip |
Whether to enable the high-performance inference plugin | bool |
None | False |
hpi_config |
High-performance inference configuration | dict | None |
None | None |
The model_name must be specified. After specifying model_name, the default model parameters built into PaddleX are used. If model_dir is specified, the user-defined model is used.
The predict() method of the face detection model is called for inference prediction. The predict() method has parameters input, batch_size, and threshold, which are explained as follows:
| Parameter | Parameter Description | Parameter Type | Options | Default Value |
|---|---|---|---|---|
input |
Data to be predicted, supporting multiple input types | Python Var/str/list |
|
None |
batch_size |
Batch size | int |
Any integer | 1 |
threshold |
Threshold for filtering out low-confidence prediction results; if not specified, the threshold parameter specified in create_model will be used. If create_model also does not specify it, the default configuration of the PaddleX official model will be used |
float |
None | None |
dict. It supports operations such as printing, saving as an image, and saving as a json file:| Method | Method Description | Parameter | Parameter Type | Parameter Description | Default Value |
|---|---|---|---|---|---|
print() |
Print the results 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, only effective when format_json is True |
4 | ||
ensure_ascii |
bool |
Control whether to escape non-ASCII characters to Unicode. If set to True, all non-ASCII characters will be escaped; False retains the original characters, only effective when format_json is True |
False |
||
save_to_json() |
Save the results as a JSON file | save_path |
str |
The path to save the file. If it is a directory, the saved file name will be consistent with the input file name | None |
indent |
int |
Specify the indentation level to beautify the output JSON data, making it more readable, only effective when format_json is True |
4 | ||
ensure_ascii |
bool |
Control whether to escape non-ASCII characters to Unicode. If set to True, all non-ASCII characters will be escaped; False retains the original characters, only effective when format_json is True |
False |
||
save_to_img() |
Save the results as an image file | save_path |
str |
The path to save the file. If it is a directory, the saved file name will be consistent with the input file name | None |
| Attribute | Attribute Description |
|---|---|
json |
Get the prediction result in json format |
img |
Get the visualization image in dict format |
For more information on the usage of PaddleX's single-model inference API, please refer to the PaddleX Single Model Python Script Usage Instructions.
If you seek higher accuracy from existing models, you can leverage PaddleX's custom development capabilities to develop better face detection models. Before using PaddleX to develop face detection models, ensure you have installed the PaddleDetection plugin for PaddleX. The installation process can be found in the PaddleX Local Installation Tutorial.
Before model training, you need to prepare the corresponding dataset for the task module. PaddleX provides a data validation function for each module, and only data that passes the validation can be used for model training. Additionally, PaddleX provides demo datasets for each module, which you can use to complete subsequent development based on the official demos. If you wish to use private datasets for subsequent model training, refer to the PaddleX Object Detection Task Module Data Annotation Tutorial.
You can use the following commands to download the demo dataset to a specified folder:
cd /path/to/paddlex
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/widerface_coco_examples.tar -P ./dataset
tar -xf ./dataset/widerface_coco_examples.tar -C ./dataset/
A single command can complete data validation:
python main.py -c paddlex/configs/modules/face_detection/PicoDet_LCNet_x2_5_face.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/widerface_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/0--Parade/0_Parade_marchingband_1_849.jpg",
"check_dataset/demo_img/0--Parade/0_Parade_Parade_0_904.jpg",
"check_dataset/demo_img/0--Parade/0_Parade_marchingband_1_799.jpg"
],
"val_samples": 100,
"val_sample_paths": [
"check_dataset/demo_img/1--Handshaking/1_Handshaking_Handshaking_1_384.jpg",
"check_dataset/demo_img/1--Handshaking/1_Handshaking_Handshaking_1_538.jpg",
"check_dataset/demo_img/1--Handshaking/1_Handshaking_Handshaking_1_429.jpg"
]
},
"analysis": {
"histogram": "check_dataset/histogram.png"
},
"dataset_path": "./dataset/example_data/widerface_coco_examples",
"show_type": "image",
"dataset_type": "COCODetDataset"
}
The verification results mentioned above indicate that check_pass being True means the dataset format meets the requirements. Details of other indicators are as follows:
attributes.num_classes: The number of classes in this dataset is 1;attributes.train_samples: The number of training samples in this dataset is 500;attributes.val_samples: The number of validation samples in this dataset is 100;attributes.train_sample_paths: The list of relative paths to the visualization images of training samples in this dataset;attributes.val_sample_paths: The list of relative paths to the visualization images of validation samples in this dataset;The dataset verification also analyzes the distribution of sample numbers across all classes and generates a histogram (histogram.png):

After completing 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
Face detection does not support data format conversion.
(2) Dataset Splitting
Parameters for dataset splitting can be set by modifying the CheckDataset section in the configuration file. Examples of some parameters in the configuration file are as follows:
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/face_detection/PicoDet_LCNet_x2_5_face.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/widerface_coco_examples
After dataset splitting, the original annotation files will be renamed to xxx.bak in the original path.
The above parameters can also be set by appending command-line arguments:
python main.py -c paddlex/configs/modules/face_detection/PicoDet_LCNet_x2_5_face.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/widerface_coco_examples \
-o CheckDataset.split.enable=True \
-o CheckDataset.split.train_percent=90 \
-o CheckDataset.split.val_percent=10
A single command is sufficient to complete model training, taking the training of PicoDet_LCNet_x2_5_face as an example:
python main.py -c paddlex/configs/modules/face_detection/PicoDet_LCNet_x2_5_face.yaml \
-o Global.mode=train \
-o Global.dataset_dir=./dataset/widerface_coco_examples
The steps required are:
.yaml configuration file of the model (here it is PicoDet_LCNet_x2_5_face.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_dirGlobal 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.-o Train.dy2st=True to enable it.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, .json: Model weight-related files, including network parameters, optimizer, EMA, static graph network parameters, static graph network structure, etc.;.json file) from protobuf(the former.pdmodel file) to be compatible with PIR and more flexible and scalable.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/face_detection/PicoDet_LCNet_x2_5_face.yaml \
-o Global.mode=evaluate \
-o Global.dataset_dir=./dataset/widerface_coco_examples
Similar to model training, the process involves the following steps:
.yaml configuration file for the model(here it's PicoDet_LCNet_x2_5_face.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 to PaddleX 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/face_detection/PicoDet_LCNet_x2_5_face.yaml \
-o Global.mode=predict \
-o Predict.model_dir="./output/best_model/inference" \
-o Predict.input="face_detection.png"
Similar to model training and evaluation, the following steps are required:
Specify the .yaml configuration file path of the model (here it is PicoDet_LCNet_x2_5_face.yaml)
Set the mode to model inference prediction: -o Global.mode=predict
Specify the model weight 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 model can be directly integrated into the PaddleX pipeline or into your own project.
The face detection module can be integrated into PaddleX pipelines such as Face Recognition. Simply replace the model path to update the face detection module of the relevant pipeline. In pipeline integration, you can use high-performance inference and serving deployment to deploy your model.
The weights you produce can be directly integrated into the face detection module. You can refer to the Python example code in Quick Integration, simply replace the model with the path to your trained model.
You can also use the PaddleX high-performance inference plugin to optimize the inference process of your model and further improve efficiency. For detailed procedures, please refer to the PaddleX High-Performance Inference Guide.