Batch prediction for multi-label image classification
EasyVision of Platform for AI (PAI) supports model training and prediction for multi-label image classification, including distributed training and prediction on multiple servers. You can run batch prediction tasks based on existing training models.
Before you begin
-
Prepare your input data. For more information, see Input data formats.
-
Make sure you have a trained model available in Object Storage Service (OSS).
Run the batch prediction command
Run the following PAI command to start batch image labeling. You can run the command by using one of these methods:
-
The SQL Script component.
-
The MaxCompute client. For more information, see MaxCompute client (odpscmd).
-
An ODPS SQL node of DataWorks. For more information, see Develop a MaxCompute SQL task.
pai -name ev_predict_ext
-Dmodel_path='OSS path of your model'
-Dmodel_type='multilabel_classifier'
-Dinput_oss_file='oss://path/to/your/filelist.txt'
-Doutput_oss_file='oss://path/to/your/result.txt'
-Dimage_type='url'
-Dnum_worker=2
-DcpuRequired=800
-DgpuRequired=100
-Dbuckets='Your OSS directory'
-Darn='Alibaba Cloud Resource Name (ARN) of the role that you are assuming'
-DossHost='Your OSS domain'
Parameters
The following table describes the parameters in the command.
| Parameter | Description |
|---|---|
| model_path | The OSS path of your model. |
| model_type | The type of model. Set this parameter to multilabel_classifier for multi-label image classification. |
| input_oss_file | The OSS path of the input file list. |
| output_oss_file | The OSS path of the output result file. |
| image_type | The type of image input. Set this parameter to url. |
| num_worker | The number of workers for distributed prediction. |
| cpuRequired | The CPU resources required for each worker. |
| gpuRequired | The GPU resources required for each worker. |
| buckets | Your OSS directory. |
| arn | The Alibaba Cloud Resource Name (ARN) of the role that you are assuming. |
| ossHost | Your OSS domain. |
For more information about parameters, see Parameters.
Output
Prediction results are written to the file specified by output_oss_file. Each entry consists of the OSS path of the original image followed by a JSON prediction result.
Example output entry:
oss://path/to/your/image1.jpg, {
"class_probs": {
"Sketch": 0.0008051558979786932,
"Life moment": 0.7316102385520935,
"Accessory": 0.0008112151990644634,
"Dancing": 0.0008053297060541809
},
"classes": [1],
"predictions": [false, true, false, false],
"class_names": ["Life moment"],
"probs": [
0.00054657127475366,
0.7316212648051790893,
0.0005365353426896036,
0.0007256706594489515
]
}
Output fields
Each prediction result is a JSON string with the following fields.
| Field | Description | Shape | Data type |
|---|---|---|---|
| classes | The IDs of the predicted labels. | [num_labels] | INT Array |
| class_names | The names of the predicted labels. | [num_labels] | STRING Array |
| class_probs | The probabilities for all labels. | [total_labels] | Dict{Key:STRING, Value:FLOAT} |
| predictions | Whether each label is predicted as positive. | [total_labels] | BOOLEAN Array |
| probs | The prediction probabilities for all labels. | [total_labels] | FLOAT Array |