Run offline image classification predictions with EasyVision, a distributed training and prediction component in Platform for AI (PAI). Use a trained classification model to process images stored in Object Storage Service (OSS) and output per-image category predictions.
Data format
For input data format requirements, see Input data formats.
Run a prediction task
Execute the ev_predict_ext PAI command to start an image classification prediction task. Run the command through any of the following methods:
SQL Script component in PAI
ODPS SQL node in DataWorks
Command syntax
pai -name ev_predict_ext
-Dmodel_path='<model-path>'
-Dmodel_type='classifier'
-Dinput_oss_file='oss://<bucket>/<path>/filelist.txt'
-Doutput_oss_file='oss://<bucket>/<path>/result.txt'
-Dimage_type='url'
-Dnum_worker=2
-DcpuRequired=800
-DgpuRequired=100
-Dbuckets='<oss-directory>'
-Darn='<role-arn>'
-DossHost='<oss-endpoint>'Replace the placeholders with your values:
| Placeholder | Description | Example |
|---|---|---|
<model-path> | OSS path to the trained model | oss://my-bucket/models/resnet50 |
<bucket>/<path> | OSS bucket and path for input/output files | my-bucket/data |
<oss-directory> | OSS directory for data access | oss://my-bucket/ |
<role-arn> | Alibaba Cloud Resource Name (ARN) of the RAM role to assume | acs:ram::1234567890:role/pai-role |
<oss-endpoint> | OSS endpoint for your region | oss-cn-hangzhou-internal.aliyuncs.com |
For the complete parameter reference, see Introduction to offline prediction.
Output format
The output file contains one prediction result per line. Each line consists of an OSS image path followed by a comma and a JSON string:
oss://path/to/your/image1.jpg, {"class": 3, "class_name": "coho4", "class_probs": {...}}
oss://path/to/your/image2.jpg, {"class": 1, "class_name": "coho2", "class_probs": {...}}
oss://path/to/your/image3.jpg, {"class": 0, "class_name": "coho1", "class_probs": {...}}JSON result fields
| Field | Description | Shape | Data type |
|---|---|---|---|
class | The ID of the category. | [] | INT 32 |
class_name | The name of the category. | [] | STRING |
class_probs | The matching probabilities of all categories. | [num_classes] | Dict{Key: STRING, Value: FLOAT} |
Sample output
{
"class": 3,
"class_name": "coho4",
"class_probs": {
"coho1": 4.028851974258174e-10,
"coho2": 0.48115724325180054,
"coho3": 5.116515922054532e-07,
"coho4": 0.5188422446937221
}
}In this example, the model assigns the image to category coho4 (category ID 3) with a matching probability of approximately 51.88%.