简体中文 | English
Mainbody detection is a fundamental task in object detection, aiming to identify and extract the location and size of specific target objects, people, or entities from images and videos. By constructing deep neural network models, mainbody detection learns the feature representations of image subjects to achieve efficient and accurate detection.
| Model | mAP(0.5:0.95) | mAP(0.5) | GPU Inference Time (ms) | CPU Inference Time (ms) | Model Size (M) | Description |
|---|---|---|---|---|---|---|
| PP-ShiTuV2_det | 41.5 | 62.0 | 33.7 | 537.0 | 27.54 | A mainbody detection model based on PicoDet_LCNet_x2_5, which may detect multiple common subjects simultaneously. |
❗ 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 mainbody detection inference with just a few lines of code. You can easily switch between models under this module, and integrate the mainbody 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-ShiTuV2_det"
model = create_model(model_name)
output = model.predict("general_object_detection_002.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")
For more information on using PaddleX's single-model inference APIs, refer to 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 mainbody detection models. Before developing mainbody detection models with PaddleX, ensure you have installed the PaddleDetection plugin for PaddleX. The installation process can be found in 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/mainbody_det_examples.tar -P ./dataset
tar -xf ./dataset/mainbody_det_examples.tar -C ./dataset/
You can complete data validation with a single command:
python main.py -c paddlex/configs/mainbody_detection/PP-ShiTuV2_det.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/mainbody_det_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.
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.
Model training can be completed with a single command, taking the training of PP-ShiTuV2_det as an example:
python main.py -c paddlex/configs/mainbody_detection/PP-ShiTuV2_det.yaml \
-o Global.mode=train \
-o Global.dataset_dir=./dataset/mainbody_det_examples
The steps required are:
.yaml configuration file path for the model (here it is PP-ShiTuV2_det.yaml)-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.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/mainbody_detection/PP-ShiTuV2_det.yaml \
-o Global.mode=evaluate \
-o Global.dataset_dir=./dataset/mainbody_det_examples
Similar to model training, the process involves the following steps:
.yaml configuration file for the model(here it's PP-ShiTuV2_det.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。After completing model training and evaluation, you can use the trained model weights for inference predictions. In PaddleX, model inference predictions can be achieved through two methods: command line and wheel package.
To perform inference predictions 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/mainbody_detection/PP-ShiTuV2_det.yaml \
-o Global.mode=predict \
-o Predict.model_dir="./output/best_model/inference" \
-o Predict.input="general_object_detection_002.png"
Similar to model training and evaluation, the following steps are required:
Specify the .yaml configuration file path of the model (here it is PP-ShiTuV2_det.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 model can be directly integrated into the PaddleX pipeline or directly into your own project.
The main body detection module can be integrated into PaddleX pipelines such as General Object Detection (comming soon). Simply replace the model path to update the main body detection module of the relevant pipeline. In pipeline integration, you can use high-performance inference and service-oriented deployment to deploy your trained model.
The weights you produce can be directly integrated into the main body detection module. You can refer to the Python example code in Quick Integration, simply replace the model with the path to your trained model.