The visual modeling platform plug-in allows you to label training data, train common
computer vision models, and deploy the models. It deeply optimizes the models that
are used on mobile platforms. You can test the performance of a model on your mobile
phone by scanning the QR code of the model. You can also deploy a model on your mobile
device. This topic describes how to use the visual modeling platform plug-in to implement
optical character recognition (OCR).
Prerequisites
- AutoLearning is authorized to access Object Storage Service (OSS). For more information,
see OSS authorization.
- An instance of the OCR type is created. For more information, see Create instances.
- The image dataset for model training is uploaded to OSS. The image dataset must meet
the requirements and specifications of OCR. For more information, see Usage notes. We recommend that you use the graphical management tool ossbrowser to upload images
in bulk. For more information, see Use ossbrowser.
Background information
Test data: OCR demo data.
Usage notes
The image dataset for OCR must meet the following dataset requirements and specifications:
Step 1: Create a dataset
- Go to the Computer Vision Model Training page.
- Log on to the PAI console.
- In the left-side navigation pane, choose .
- On the Computer Vision Model Training page, find the instance that you want to manage and click Open in the Operation column.
- In the Data Preparation step, click New Dataset.
- In the New Dataset panel, set the parameters.
Parameter |
Description |
Dataset name |
The name of the dataset. The name must be 1 to 30 characters in length and can contain
underscores (_) and hyphens (-). It must start with a letter or digit.
|
Description |
The description of the dataset. The description helps distinguish different datasets.
|
Storage type |
Only OSS is supported. You cannot change the value.
|
OSS path |
The OSS path where the images for model training are stored. |
- Click Confirm.
The visual modeling platform plug-in automatically creates indexes on images and labeling
data, but does not save the indexed images. The plug-in can retrieve your images in
OSS to train models only after the plug-in is authorized. You can view the information
of datasets in the Dataset list section. If the status of the dataset changes from Data import to To be manually marked or Labeling completed, the dataset is created.
Step 3: Create a task
- In the Data Preparation step, click the Training tasks step in the upper part of the page.
- In the Training tasks step, click New task.
- In the New task panel, set the parameters.
Step |
Parameter |
Description |
Basic Information |
Task name |
The name of the task. The name must be 1 to 30 characters in length and can contain
underscores (_) and hyphens (-). It must start with a letter or digit.
|
Description |
The description of the task. The description helps distinguish different tasks. |
Dataset |
Select dataset |
Select the created dataset as the training dataset. |
Algorithm and training |
Select algorithm |
OCR (High Performance): balances the inference performance of the server in the cloud and clients and provides
fast prediction services.
|
Resource configuration |
Set the Number of GPUs and GPU type parameters for the training task.
|
Show Advanced Settings |
Click Show Advanced Settings to customize the algorithm parameters that are involved in model training. For more
information, see Table 1. If you customize no parameters in the Show Advanced Settings section, default values
are used.
|
Table 1. Parameters in the Show Advanced Settings section
Parameter |
Description |
Default value |
Data Enhancement |
The following data enhancement methods are supported:
- Rotate: Rotate an image.
- Blur: Blur an image.
- Noise: Add noises to an image.
- Shear: Perform a shearing on an image.
- FlipLR: Flip an image left and right.
- FlipUD: Flip an image up and down.
|
Rotate and Noise |
Model width |
Valid values: 0.35, 0.5, 0.75 and 1. |
0.75 |
Epoch Training |
The number of epochs for model training. |
100 |
Optimizer |
The optimization algorithms for model training. Valid values:
|
Adam |
Initialize learning rate |
The initial learning rate during model training. |
0.001 |
Quantization compression |
Specifies whether to perform quantization compression. |
Yes |
- Click Start training.
Step 4: View training details
- In the Training tasks step, click Training details in the Operation column of the task that you created.
- On the page that appears, you can perform the following operations.
Operation |
Description |
View the training progress |
On the Training process tab, view the training progress and relevant information in the Basic information section.  |
Terminate the training task |
On the Training process tab, click Terminate task.
|
View the node information |
- On the Training process tab, click a node.
- In the Node Information panel, view the status of the node and the information in the Basic information and Step information sections.
|
View training logs |
- On the Training process tab, click a node.
- In the Node Information panel, click the Log tab.
|
Step 5: Generate a mini program to test the model
- After the training is complete, click Model and deploy in the upper-right corner of the training details page.
- In the Model and deploy step, scan the QR code by using the Alipay app.

The values of the following model metrics are calculated based on a validation set.
A validation set is a portion of the training data. By default, 10% of the training
data is extracted and used as a validation set.
- loss: calculates the loss between ground truth and the predicted value by using the loss
function. A lower loss indicates a more precise model.
- model_size: obtains the model size based on optimization methods such as training, quantization,
and encoding.
- Use the mini program to scan objects to test how the model recognizes characters in
real time.
Step 6: Deploy the model
- In the Model and deploy step, click Go to PAI-EAS deployment.
- Set model parameters.
- In the Model Configuration panel, set the Custom Model Name and Resources Type parameters. Other parameters are automatically set.
- Click Next.
- In the Deployment details and confirmation panel, set the parameters.
Parameter |
Description |
Number Of Instances |
Click the or icon to adjust the number of instances.
|
Quota |
The specifications of an instance. This parameter is displayed only when the Resources Type parameter is set to CPU. One quota contains one core and 4 GB of memory.
|
Resources on a single instance |
The specifications of a GPU server. This parameter is displayed only when the Resources Type is set to GPU.
|
.
- Click Deploy.
The Elastic Algorithm Service page appears. If the status of the model changes to Running in the State column, the model is deployed.
- Call the model service.
Examples
- Sample request
curl http://****.cn-shanghai.pai-eas.aliyuncs.com/api/predict/**** -H 'Authorization:****==' -d '{"dataArray": [{"body": "****", "type": "stream", "name": "image"}]}'
Replace the URL, token, and Base64-encoded information in this example with actual
values.
- Sample response
{
"success":true,
"result":{
"output":[
{
"type":"cv_common",
"body":[
{
"label":"06174727742034996",
"conf":0.95,
"pos":[[468,992],[976,1012],[972,1072],[464,1052]]
}
]
}
],
"meta":{
"height":1920,
"width":1080
}
}
}
- Sample error response
If a request error occurs, the response contains the following parameters:
- errorCode: the error code.
- errorMsg: the error message.
For example, if the request does not contain the
dataArray field, the following response is returned:
{
"success":false,
"errorCode":"1001",
"errorMsg":"INPUT_FORMAT_ERROR"
}