简体中文 | English
The instance segmentation module is a crucial component in computer vision systems, responsible for identifying and marking pixels that contain specific object instances in images or videos. The performance of this module directly impacts the accuracy and efficiency of the entire computer vision system. The instance segmentation module typically outputs pixel-level masks (masks) for each target instance, which are then passed as input to the object recognition module for subsequent processing.
| Model | Mask AP | GPU Inference Time (ms) | CPU Inference Time (ms) | Model Size (M) | Description |
|---|---|---|---|---|---|
| Mask-RT-DETR-H | 50.6 | 132.693 | 4896.17 | 449.9 M | Mask-RT-DETR is an instance segmentation model based on RT-DETR. By adopting the high-performance PP-HGNetV2 as the backbone network and constructing a MaskHybridEncoder encoder, along with introducing IOU-aware Query Selection technology, it achieves state-of-the-art (SOTA) instance segmentation accuracy with the same inference time. |
| Mask-RT-DETR-L | 45.7 | 46.5059 | 2575.92 | 113.6 M |
❗ The above list features the 2 core models that the image classification module primarily supports. In total, this module supports 15 models. The complete list of models is as follows:
| Model | Mask AP | GPU Inference Time (ms) | CPU Inference Time (ms) | Model Size (M) | Description |
|---|---|---|---|---|---|
| Cascade-MaskRCNN-ResNet50-FPN | 36.3 | - | - | 254.8 M | Cascade-MaskRCNN is an improved Mask RCNN instance segmentation model that utilizes multiple detectors in a cascade, optimizing segmentation results by leveraging different IOU thresholds to address the mismatch between detection and inference stages, thereby enhancing instance segmentation accuracy. |
| Cascade-MaskRCNN-ResNet50-vd-SSLDv2-FPN | 39.1 | - | - | 254.7 M | |
| Mask-RT-DETR-H | 50.6 | 132.693 | 4896.17 | 449.9 M | Mask-RT-DETR is an instance segmentation model based on RT-DETR. By adopting the high-performance PP-HGNetV2 as the backbone network and constructing a MaskHybridEncoder encoder, along with introducing IOU-aware Query Selection technology, it achieves state-of-the-art (SOTA) instance segmentation accuracy with the same inference time. |
| Mask-RT-DETR-L | 45.7 | 46.5059 | 2575.92 | 113.6 M | |
| Mask-RT-DETR-M | 42.7 | 36.8329 | - | 66.6 M | |
| Mask-RT-DETR-S | 41.0 | 33.5007 | - | 51.8 M | |
| Mask-RT-DETR-X | 47.5 | 75.755 | 3358.04 | 237.5 M | |
| MaskRCNN-ResNet50-FPN | 35.6 | - | - | 157.5 M | Mask R-CNN is a full-task deep learning model from Facebook AI Research (FAIR) that can perform object classification and localization in a single model, combined with image-level masks to complete segmentation tasks. |
| MaskRCNN-ResNet50-vd-FPN | 36.4 | - | - | 157.5 M | |
| MaskRCNN-ResNet50 | 32.8 | - | - | 128.7 M | |
| MaskRCNN-ResNet101-FPN | 36.6 | - | - | 225.4 M | |
| MaskRCNN-ResNet101-vd-FPN | 38.1 | - | - | 225.1 M | |
| MaskRCNN-ResNeXt101-vd-FPN | 39.5 | - | - | 370.0 M | |
| PP-YOLOE_seg-S | 32.5 | - | - | 31.5 M | PP-YOLOE_seg is an instance segmentation model based on PP-YOLOE. This model inherits PP-YOLOE's backbone and head, significantly enhancing instance segmentation performance and inference speed through the design of a PP-YOLOE instance segmentation head. |
| SOLOv2 | 35.5 | - | - | 179.1 M | SOLOv2 is a real-time instance segmentation algorithm that segments objects by location. This model is an improved version of SOLO, achieving a good balance between accuracy and speed through the introduction of mask learning and mask NMS. |
❗ Before quick integration, please install the PaddleX wheel package. For detailed instructions, refer to the PaddleX Local Installation Tutorial
After installing the wheel package, a few lines of code can complete the inference of the instance segmentation module. You can switch models under this module freely, and you can also integrate the model inference of the instance segmentation module into your project. Before running the following code, please download the demo image to your local machine.
from paddlex import create_model
model = create_model("Mask-RT-DETR-L")
output = model.predict("general_instance_segmentation_004.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, please refer to the PaddleX Single-Model Python Script Usage Instructions.
If you are seeking higher accuracy from existing models, you can use PaddleX's custom development capabilities to develop better instance segmentation models. Before using PaddleX to develop instance segmentation models, please ensure that you have installed the relevant model training plugins for segmentation in PaddleX. The installation process can be found in the custom development section of the PaddleX Local Installation Guide.
Before model training, it is necessary to prepare the corresponding dataset for each task module. PaddleX provides data verification functionality for each module, and only data that passes the verification can be used for model training. Additionally, PaddleX provides demo datasets for each module, allowing you to complete subsequent development based on the officially provided demo data. If you wish to use a private dataset for subsequent model training, you can refer to the PaddleX Instance Segmentation Task Module Data Annotation Tutorial.
You can download the demo dataset to a specified folder using the following command:
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/instance_seg_coco_examples.tar -P ./dataset
tar -xf ./dataset/instance_seg_coco_examples.tar -C ./dataset/
Data verification can be completed with a single command:
python main.py -c paddlex/configs/instance_segmentation/Mask-RT-DETR-L.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/instance_seg_coco_examples
After executing the above command, PaddleX will validate the dataset and summarize its basic information. If the command runs successfully, it will print Check dataset passed ! in the log. The validation results file is saved in ./output/check_dataset_result.json, and related outputs are saved in the ./output/check_dataset directory in the current directory, including visual examples of sample images and sample distribution histograms.
👉 Details of Validation Results (Click to Expand)
The specific content of the validation result file is:
{
"done_flag": true,
"check_pass": true,
"attributes": {
"num_classes": 2,
"train_samples": 79,
"train_sample_paths": [
"check_dataset/demo_img/pexels-photo-634007.jpeg",
"check_dataset/demo_img/pexels-photo-59576.png"
],
"val_samples": 19,
"val_sample_paths": [
"check_dataset/demo_img/peasant-farmer-farmer-romania-botiza-47862.jpeg",
"check_dataset/demo_img/pexels-photo-715546.png"
]
},
"analysis": {
"histogram": "check_dataset/histogram.png"
},
"dataset_path": "./dataset/instance_seg_coco_examples",
"show_type": "image",
"dataset_type": "COCOInstSegDataset"
}
In the above verification results, check_pass being True indicates that the dataset format meets the requirements. Explanations for other indicators are as follows:
attributes.num_classes: The number of classes in this dataset is 2;attributes.train_samples: The number of training samples in this dataset is 79;attributes.val_samples: The number of validation samples in this dataset is 19;attributes.train_sample_paths: A list of relative paths to the visualized training samples in this dataset;attributes.val_sample_paths: A list of relative paths to the visualized validation samples in this dataset;
Additionally, the dataset verification also analyzes the distribution of sample numbers across all categories in the dataset and generates a distribution histogram (histogram.png):After completing data verification, you can convert the dataset format or re-split the training/validation ratio by modifying the configuration file or appending hyperparameters.
A single command can complete model training. Taking the training of the instance segmentation model Mask-RT-DETR-L as an example:
python main.py -c paddlex/configs/instance_segmentation/Mask-RT-DETR-L.yaml \
-o Global.mode=train \
-o Global.dataset_dir=./dataset/instance_seg_coco_examples
The following steps are required:
.yaml configuration file of the model (here it is Mask-RT-DETR-L.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 fields under Global and Train in the .yaml configuration file, or adjusted by appending parameters in the command line. For example, to specify the first 2 GPUs for training: -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 File Parameters Instructions.After completing model training, you can evaluate the specified model weights file on the validation set to verify the model's accuracy. Using PaddleX for model evaluation can be done with a single command:
python main.py -c paddlex/configs/instance_segmentation/Mask-RT-DETR-L.yaml \
-o Global.mode=evaluate \
-o Global.dataset_dir=./dataset/instance_seg_coco_examples
Similar to model training, the following steps are required:
.yaml configuration file path for the model (here it is Mask-RT-DETR-L.yaml)-o Global.mode=evaluate-o Global.dataset_dir. Other related parameters can be set by modifying the Global and Evaluate fields in the .yaml configuration file. For details, refer to PaddleX Common Model Configuration File Parameter Description.After completing model training and evaluation, you can use the trained model weights for inference prediction or Python integration.
To perform inference prediction via 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/instance_segmentation/Mask-RT-DETR-L.yaml \
-o Global.mode=predict \
-o Predict.model_dir="./output/best_model/inference" \
-o Predict.input="general_instance_segmentation_004.png"
Similar to model training and evaluation, the following steps are required:
.yaml configuration file path of the model (here it's Mask-RT-DETR-L.yaml)-o Global.mode=predict-o Predict.model_dir="./output/best_model/inference"-o Predict.input="...". Other related parameters can be set by modifying the Global and Predict fields in the .yaml configuration file. For details, refer to PaddleX Common Model Configuration File Parameter Description.The model can be directly integrated into the PaddleX Pipeline or into your own project.
1.Pipeline Integration
The instance segmentation module can be integrated into the General Instance Segmentation Pipeline of PaddleX. Simply replace the model path to update the instance segmentation module of the relevant pipeline.
2.Module Integration The weights you produce can be directly integrated into the instance segmentation module. Refer to the Python example code in Quick Integration , and simply replace the model with the path to your trained model.