--- comments: true --- # Image Multi-Label Classification Module Tutorial ## I. Overview The image multi-label classification module is a crucial component in computer vision systems, responsible for assigning multiple labels to input images. Unlike traditional image classification tasks that assign a single category to an image, multi-label classification tasks require assigning multiple relevant categories to an image. The performance of this module directly impacts the accuracy and efficiency of the entire computer vision system. The image multi-label classification module typically takes an image as input and, through deep learning or other machine learning algorithms, classifies it into multiple predefined categories based on its characteristics and content. For example, an image containing both a cat and a dog might be labeled as both "cat" and "dog" by the image multi-label classification module. These classification labels are then output for subsequent processing and analysis by other modules or systems. ## II. Supported Model List > The inference time only includes the model inference time and does not include the time for pre- or post-processing.
| Model | Model Download Link | mAP(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Description |
|---|---|---|---|---|---|---|
| CLIP_vit_base_patch16_448_ML | Inference Model/Training Model | 89.15 | 48.87 / 8.10 | 275.33 / 188.48 | 325.6 | CLIP_ML is an image multi-label classification model based on CLIP, which significantly improves accuracy on multi-label classification tasks by incorporating an ML-Decoder. |
| PP-HGNetV2-B0_ML | Inference Model/Training Model | 80.98 | 7.15 / 1.77 | 21.35 / 8.19 | 39.6 | PP-HGNetV2_ML is an image multi-label classification model based on PP-HGNetV2, which significantly improves accuracy on multi-label classification tasks by incorporating an ML-Decoder. |
| PP-HGNetV2-B4_ML | Inference Model/Training Model | 87.96 | 8.11 / 2.82 | 44.76 / 29.38 | 88.5 | |
| PP-HGNetV2-B6_ML | Inference Model/Training Model | 91.25 | 34.54 / 8.22 | 189.17 / 189.17 | 286.5 | |
| PP-LCNet_x1_0_ML | Inference Model/Training Model | 77.96 | 5.28 / 1.62 | 13.16 / 5.61 | 29.4 | PP-LCNet_ML is an image multi-label classification model based on PP-LCNet, which significantly improves accuracy on multi-label classification tasks by incorporating an ML-Decoder. |
| ResNet50_ML | Inference Model/Training Model | 83.50 | 10.54 / 2.97 | 55.39 / 35.52 | 108.9 | ResNet50_ML is an image multi-label classification model based on ResNet50, which significantly improves accuracy on multi-label classification tasks by incorporating an ML-Decoder. |
| 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.) |
| Parameter | Parameter Description | Parameter Type | Options | Default Value |
|---|---|---|---|---|
model_name |
Name of the model | str |
None | PP-LCNet_x1_0_ML |
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 |
use_hpip |
Whether to enable the high-performance inference plugin | bool |
None | False |
hpi_config |
High-performance inference configuration | dict | None |
None | None |
| 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 |
| 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 |
The specific content of the validation result file is:
{
"done_flag": true,
"check_pass": true,
"attributes": {
"label_file": "../../dataset/mlcls_nus_examples/label.txt",
"num_classes": 33,
"train_samples": 17463,
"train_sample_paths": [
"check_dataset/demo_img/0543_4338693.jpg",
"check_dataset/demo_img/0272_347806939.jpg",
"check_dataset/demo_img/0069_2291994812.jpg",
"check_dataset/demo_img/0012_1222850604.jpg",
"check_dataset/demo_img/0238_53773041.jpg",
"check_dataset/demo_img/0373_541261977.jpg",
"check_dataset/demo_img/0567_519506868.jpg",
"check_dataset/demo_img/0023_289621557.jpg",
"check_dataset/demo_img/0581_484524659.jpg",
"check_dataset/demo_img/0325_120753036.jpg"
],
"val_samples": 17463,
"val_sample_paths": [
"check_dataset/demo_img/0546_130758157.jpg",
"check_dataset/demo_img/0284_2230710138.jpg",
"check_dataset/demo_img/0090_1491261559.jpg",
"check_dataset/demo_img/0013_392798436.jpg",
"check_dataset/demo_img/0246_2248376356.jpg",
"check_dataset/demo_img/0377_1349296474.jpg",
"check_dataset/demo_img/0570_2457645006.jpg",
"check_dataset/demo_img/0027_309333946.jpg",
"check_dataset/demo_img/0584_132639537.jpg",
"check_dataset/demo_img/0329_206031527.jpg"
]
},
"analysis": {
"histogram": "check_dataset/histogram.png"
},
"dataset_path": "mlcls_nus_examples",
"show_type": "image",
"dataset_type": "MLClsDataset"
}
In the above validation 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 33;attributes.train_samples: The number of training set samples in this dataset is 17463;attributes.val_samples: The number of validation set samples in this dataset is 17463;attributes.train_sample_paths: A list of relative paths to the visual samples in the training set of this dataset;attributes.val_sample_paths: A list of relative paths to the visual samples in the validation set of this dataset;Additionally, the dataset validation analyzes the sample number distribution across all classes in the dataset and generates a distribution histogram (histogram.png):

(1) Dataset Format Conversion
The multi-label image classification supports the conversion of COCO format datasets to MLClsDataset format. The parameters for dataset format conversion can be set by modifying the fields under CheckDataset in the configuration file. Examples of some parameters in the configuration file are as follows:
CheckDataset:convert:enable: Whether to perform dataset format conversion. Multi-label image classification supports converting COCO format datasets to MLClsDataset format. Default is False;src_dataset_type: If dataset format conversion is performed, the source dataset format needs to be set. Default is null, with the optional value of COCO; For example, if you want to convert a COCO format dataset to MLClsDataset format, you need to modify the configuration file as follows:
cd /path/to/paddlex
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/det_coco_examples.tar -P ./dataset
tar -xf ./dataset/det_coco_examples.tar -C ./dataset/
......
CheckDataset:
......
convert:
enable: True
src_dataset_type: COCO
......
Then execute the command:
python main.py -c paddlex/configs/modules/image_multilabel_classification/PP-LCNet_x1_0_ML.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/det_coco_examples
After the data conversion is executed, the original annotation files will be renamed to xxx.bak in the original path.
The above parameters also support being set by appending command line arguments:
python main.py -c paddlex/configs/modules/image_multilabel_classification/PP-LCNet_x1_0_ML.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/det_coco_examples \
-o CheckDataset.convert.enable=True \
-o CheckDataset.convert.src_dataset_type=COCO
The dataset splitting parameters can be set by modifying the fields under CheckDataset in the configuration file. An example of part of the configuration file is shown below:
CheckDataset:split:enable: Whether to re-split the dataset. Set to True to perform dataset splitting, default is False;train_percent: If re-splitting the dataset, set the percentage of the training set, an integer between 0-100, ensuring the sum with val_percent is 100;val_percent: If re-splitting the dataset, set the percentage of the validation set, an integer between 0-100, ensuring the sum with train_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/image_multilabel_classification/PP-LCNet_x1_0_ML.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/det_coco_examples
After the data splitting is executed, the original annotation files will be renamed to xxx.bak in the original path.
These parameters can also be set by appending command-line arguments:
python main.py -c paddlex/configs/modules/image_multilabel_classification/PP-LCNet_x1_0_ML.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/det_coco_examples \
-o CheckDataset.split.enable=True \
-o CheckDataset.split.train_percent=90 \
-o CheckDataset.split.val_percent=10
output. If you need to specify a save path, you can set it through 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.When evaluating the model, you need to specify the model weights file path. Each configuration file has a default weight save path. If you need to change it, simply append the command line parameter to set it, such as -o Evaluate.weight_path=./output/best_model/best_model.pdparams.
After completing the model evaluation, an evaluate_result.json file will be produced, which records the evaluation results, specifically, whether the evaluation task was completed successfully and the model's evaluation metrics, including MultiLabelMAP;