This topic describes how to configure image classification in the procedure of creating datasets, labeling images, creating tasks, training models, and deploying and calling models.

Prerequisites

  • AutoLearning is authorized to access Object Storage Service (OSS). For more information, see OSS authorization.
  • An instance is created. For more information, see Create an instance.
  • Images that are used for model training are uploaded to OSS. We recommend that you use the graphical management tool ossbrowser to upload images in bulk. For more information, see Quick start.

Background information

  • Dataset requirements
    • Image quality: Undamaged images. AutoLearning supports images in JPG, JPEG, and PNG formats.
    • Data balance: To reach data balance among image categories, we recommend that each category contain more than 20 images.
    • Data distribution: The images are similar to those that are applied in your business.
    • Generalization: Select images that are taken in real scenes from different angles.
  • Dataset requirements
    |-- your_image_dir /
        |-- label_1 /
            | -- a.jpg
            | -- b.png
        | -- label_2 /
            | -- c.jpg
            | -- d.png
        |-- test_1.png
        ...
    The images stored in OSS must meet the preceding requirements. your_image_dir refers to the folder that stores the images. You can create multiple subfolders to store images of different categories. For example, your_image_dir/label_1 refers to the subfolder that stores the images bound to lable_1. You can store the images whose categories are to be determined in the your_image_dir folder. For example, your_image_dir/test_1.png indicates that the test_1.png image is not labeled.
    Note The names of subfolders (label_1, label_2...) must be in English.

Test data: DEMO data.

Step 1: Create a dataset

  1. Visit the Computer Vision Model Training page.
    1. Log on to the Machine Learning Platform for AI console.
    2. In the left-side navigation pane, choose AutoLearning > Computer Vision Model Training.
  2. On the Computer Vision Model Training page, click Open in the Operation column.
  3. On the Data Preparation wizard page, click New Dataset.
  4. On the New Dataset page, set the following parameters.
    Parameter Description
    Dataset Name The dataset name must be 1 to 30 characters in length and can contain underscores (_) and hyphens (-). It must start with a letter or digit.
    Description Enter the description of the dataset, which helps distinguish different datasets.
    Storage type Only the default storage type OSS is supported.
    OSS path Specify the OSS path where the images for model training are stored.
  5. Click Submit.
    AutoLearning automatically creates indexes on images and labeling data. However, AutoLearning does not save the indexed images. Authorization is required only when AutoLearning needs to retrieve your images stored in OSS to train models. You can view the information of datasets in the Data list section.

Step 2: Label images

If your dataset contains unlabeled images, you can label them on the AutoLearning platform.

  1. On the Data Preparation wizard page, navigate to the Dataset list section. Then, click Labeling in the Operation column.
  2. On the Labeling page, label all images and click Submit.Image labeling
  3. Click Preview to view the labeling results.

Step 3: Create a task

  1. On the Data Preparation wizard page, click Training tasks.
  2. On the Training tasks wizard page, click New task.
  3. On the New task page, configure the following parameters.
    Section Parameter Description
    Basic information Task name The task 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, which helps distinguish different tasks.
    Dataset Select dataset Select an image dataset for model training.
    Select label Select at least two labels for image classification.
    Algorithm and training Select algorithm The following two algorithms are supported.
    • Classification (High Performance): provides fast prediction services while balancing the inference performance of the server on the cloud and clients.
    • Classification (High Precision): provides higher precision but a lower prediction speed compared with that of the high-performance algorithm.
    Resource configuration Specify the Number of GPUs and GPU type for the training task.
  4. Click Start training.

Step 4: View training details

  1. On the Training tasks wizard page, click Training details in the Operation column.
  2. On the Training details page, you can perform the following operations.
    Operation Description
    View training progress On the Training process tab, view the training progress and relevant information in the Basic information section.Training progress
    Terminate tasks On the Training process tab, click Terminate task.
    View node information
    1. On the Training process tab, click a node.
    2. On the Node Information page that appears, view the status of the node and the information in the Basic information and Step information sections.
    View training logs
    1. On the Training process tab, click a node.
    2. On the Node Information page, click the log tab.

Step 5: Generate a mini program to test the model

  1. On the Training details page, click Model and deploy.
  2. On the Model and deploy wizard page, scan the QR code by using the Alipay app.Test the model
  3. Use the mini program to scan objects to test how the model recognizes and classifies objects in real time.Test the model

Step 6: Deploy the model

  1. On the Model and deploy wizard page, click Go to PAI-EAS deployment.
  2. On the Resources And Models page that appears, select a Resources Type, and click Next.
  3. On the Deployment details and confirmation page, enter a Custom Model Name.
  4. In the Number Of Instances and Quota fields, click Up arrow and Down arrow to adjust the number of resources.
  5. Click Deploy.
    Visit the Elastic Algorithm Service page. When the status of the model changes to Running in the State column, the model is deployed.
  6. Call the model.
    Make an API call
    • HTTP method: POST.
    • Request URL: After the model is deployed on the server, a public endpoint is automatically generated. To view the Access address and Token, perform the following steps:
      1. On the Elastic Algorithm Service page, click Invoke Intro in the Service Method column.
      2. On the Invoke Intro page, click the Public Network Invoke tab to view Access address and Token.
    • Request body
      {
        "dataArray":[
          {
            "name":"image",
            "type":"stream",
            "body": "Base64-encoded data"
          }
        ]
      }
      Parameter Required Type Description
      name No string N/A
      type No string The type of the data. The default type is stream and cannot be changed.
      body Yes string The image data. The data is encoded by using Base64. Images in JPG, PNG, and BMP formats are supported.
    • Response parameters
      Parameter Type Description
      success bool Specifies whether the call is successful.
      result object The returned result.
      output array The classification result that is returned in an array.
      label string The label of the image, which represents the category of the image.
      conf number The confidence level.
      meta object The image information.
      height number The height of the image.
      width number The width of the image.
    • Error codes
      Error code Error message Description
      1001 INPUT_FORMAT_ERROR The error message returned because the input format is invalid. For example, a required parameter is missing. Check whether the input format is valid.
      1002 IMAGE_DECODE_ERROR The error message returned because image decoding is failed. The image is not in the JPG, PNG, or other supported formats. Check the image format.
      2001 UNKNOWN_ERROR The error message returned because an internal server error occurred.
      2002 GET_INSTANCE_ERROR The error message returned because the system failed to obtain the instance. This error may occur due to insufficient resources. Increase resources such as the number of CPU cores and memory size.
      2003 MODEL_FORWARD_ERROR The error message returned because a model inference failure occurred. This error is caused by an internal server error.
    Examples
    • Sample requests
      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 encoding information in this example with the actual values.
    • Sample responses
      {
        "success":true,
        "result":{
          "output":[
            {
              "type":"cv_common",
              "body":[
                {"label":"hua","conf":0.8},
                {"label":"feihua","conf":0.2}
              ]
            }
          ],
          "meta":{
            "height":1920,
            "width":1080
          }
        }
      }                                    
    • Sample error responses
      If a request error occurs, the response contains the following parameters:
      • errorCode: the error code.
      • errorMsg: the error message.
      For example, when dataArray is missing in the input parameter, the following response is returned:
      {
        "success":false,
        "errorCode":"1001",
        "errorMsg":"INPUT_FORMAT_ERROR"
      }