Image Search provides the batch operation feature. You can use the feature to import images from Alibaba Cloud Object Storage Service (OSS) to Image Search and delete images from Image Search at a time. This feature provides the following benefits: high stability, high efficiency, and ease of use. This feature is suitable for scenarios in which you need to manage large-scale images by using a single task. This topic describes how to add and delete images at a time.

Procedure

  1. Activate OSS.
  2. Import images to OSS.
  3. Create a file named increment.meta.
  4. Authorize an Image Search account to access OSS.
  5. Create a batch task.

Activate OSS

If OSS is not activated, activate OSS. For more information, see Activate OSS. After you activate OSS, you must create buckets. For more information, see Create buckets.
Note
  • You are separately billed for OSS. For more information about the billing methods, see Overview.
  • Your OSS bucket and Image Search instance must be deployed in the same region. Otherwise, the batch operation feature is unavailable.

Import images to OSS

For information about how to import images to OSS, see Upload objects.
Note You can specify a path to store the images that are to be imported. When you create a batch task, you must specify this path.

Create a file named increment.meta

Create a file named increment.meta in the path in which the images are stored. This file is used to store the details of the batch task.
Note The increment.meta file and the images specified in the increment.meta file must be stored in the same path. Otherwise, your batch operation fails.
The following code provides a sample of a configured increment.meta file:
{"OperationType": "ADD","ProductId": "1000","PicName": "girl_cloth1.jpg","CategoryId": 0,"IntAttr": 0,"StrAttr": "value1","CustomContent": "k1:v1,k2:v2,k3:v3","Region": "20,40,60,80"}
{"OperationType": "ADD","ProductId": "1000","PicName": "girl_cloth2.jpg","CategoryId": 0,"IntAttr": 0,"StrAttr": "value2","CustomContent": "k1:v1,k2:v2,k3:v3","Region": "20,40,60,80"}
{"OperationType": "ADD","ProductId": "1001","PicName": "girl_cloth3.jpg","CategoryId": 1,"CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "ADD","ProductId": "1002","PicName": "girl_cloth4.jpg","CategoryId": 0,"CustomContent": "k1:v1,k2:v2,k3:v3","Crop": false}
{"OperationType": "ADD","ProductId": "1003","PicName": "girl_cloth7.jpg","CustomContent": "https://www.aliyun.com/imagesearch/girl_cloth7.jpg"}
{"OperationType": "ADD","ProductId": "1003","PicName": "girl_cloth6.jpg","CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "DELETE","ProductId": "1004","PicName": "fengyi.jpg"}
{"OperationType": "DELETE","ProductId": "1005"}
In this file, information about each image is encoded in JSON format. The following table describes the parameters in the file.
Parameter Type Required Description
OperationType String Yes The type of the operation. Valid values:
  • ADD: the operation to add the image.
  • DELETE: the operation to delete the image.
ProductId String Yes The unique ID of the image.
PicName String Yes The name of the image that is stored in the OSS bucket.
Note Each row contains at most one image name. If an image ID corresponds to multiple image names, you must write a row for each of the image names.
CategoryId Integer No The category of the image. For more information, see Category reference.
  • For product image searches, if you specify a category for an image, the specified category prevails. The specified category must be within the scope described in the Category reference topic. Otherwise, Image Search is unable to import the image to the image gallery. If you do not specify a category for an image, the system predicts the category, and returns the prediction result in the response.
  • Forgeneric image searches, the parameter value is set to 88888888, regardless of whether a category is specified.
CustomContent String Yes The user-defined content. This value can be a maximum of 4,096 characters in length.
IntAttr Integer No The integer attribute. This attribute can be used to filter images when you search for images.
StrAttr String No The string attribute. This value can be a maximum of 128 characters in length. This attribute can be used to filter images when you search for images.
Crop Boolean No Specifies whether to identify the subject in the image and search for images based on the identified subject. Default value: true. Valid values:
  • true: The system identifies the subject in the image and searches for the image based on the recognized subject.
  • false: The system does not identify the subject in the image, and searches for the image based on the entire image.
Region String No The subject area in the image. The subject area is displayed in the format of x1,x2,y1,y2. x1 and y1 represent the upper-left pixel. x2 and y2 represent the lower-right pixel.
Note

If you specify this parameter, the Crop parameter does not take effect.

Authorize an Image Search account to access OSS

To implement the batch operation feature in Image Search, you must use Image Search together with OSS. The first time you use the batch operation feature, authorize your Image Search account to access OSS. If your account is authorized, skip this step.

  1. Log on to the Image Search console.
  2. Select the service type and click the name of your instance.
  3. Click the Batch Operation tab.
  4. Click Create Batch Task. In the dialog box that appears, click Confirm the authorization.
  5. On the Cloud Resource Access Authorization page, click Confirm Authorization Policy.

Create a batch task

  1. Log on to the Image Search console.
  2. Select the service type and click the name of your instance.
  3. Click the Batch Operation tab.
  4. Click Create Batch Task.
  5. Configure the following parameters for the batch task:
    • Region

      This parameter specifies the region where the instance is deployed.

    • Bucket Name
      This parameter specifies the name of the bucket that you created in OSS.
      Notice Make sure that your OSS bucket and Image Search instance are deployed in the same region.
    • Path
      This parameter specifies the path in which the images and the increment.meta file are stored. Batch operation - Path
    • META files

      This parameter specifies the file used to store the details about the images to be processed. The file is named increment.meta. You can click the Refresh icon on the right of the field to check whether the file exists.

    • Call backs after the operation completes
      This parameter specifies the callback URL. The URL must start with http or https.
      {
        "finishTime": "2021-05-19 17:50:00",
        "instanceId": "imagesearch-cn-xxxx",
        "instanceName": "instanceName",
        "message": "success",
        "processResultUrl": "https://image-search-task-info.oss-cn-shanghai.aliyuncs.com/yyyyyyyyyy",
        "status": "NORMAL",
        "taskId": 111
      }
      Parameter Description
      finishTime The time when the batch task was completed. The time is accurate to the second.
      instanceName The name of the Image Search instance.
      instanceId The ID of the Image Search instance.
      status The result of the batch task. The value NORMAL indicates that the batch task was completed. The value FAIL indicates that the batch task failed.
      taskId The ID of the task.
      message The description of the task result. The value success indicates that the task was completed.
      processResultUrl The URL used to download the failure information.

What to do next

On the Instance Details page of the instance, you can view the details about all batch tasks on the Batch Operation tab. If a batch task is in the Imported state, you can view the description of the batch task result in the Error Message column.
  • You can filter batch tasks by bucket name or path.
  • If the Some of the images cannot be processed and are isolated. message appears in the Error Message column for a batch task, some images failed to be processed. You can click Download Result in the Result column to view the reason why the images failed to be processed.