Help Center/ ImageSearch/ Getting Started/ Create an ImageSearch Instance
Updated on 2023-12-13 GMT+08:00

Create an ImageSearch Instance

For details about the concept, advantages, functions, and application scenarios of ImageSearch, see the Service Overview.

The procedure of using ImageSearch is as follows:

Scenario Description

To help you quickly get familiar with ImageSearch, this document describes how to use the general image search function of ImageSearch to search for images that match the local image from the image library.

In this example, select the local image 1.jpg. Use ImageSearch to create an instance, select the general image search service model, and import the existing image library to an OBS bucket. After the instance is executed, the information about the images that match the local image 1.jpg is outputted through instance test.

Step 1: Applying for a Service

The procedure is as follows:

  1. Log in to Huawei Cloud. If you do not have a Huawei Cloud account, register on the registration page as prompted.
  2. On the top of the Huawei Cloud page, choose Products > Enterprise Intelligence > ImageSearch. The ImageSearch product page is displayed.
  3. On the product page, click Try Now and enter the username and password to access the ImageSearch management console.
  4. The Dashboard page displays the total number of API calls in the latest week and the status of all instances. See Figure 1.
    Figure 1 Dashboard

Step 2: Creating an Instance

Before using ImageSearch, create an instance and select a service model for search.

  1. On the Dashboard or Instance Management page, create an instance.

    Creating an instance on the Instance Management page is used as an example. On the Instance Management page, click Create Instance. The Create Instance page is displayed. Refer to the following table to understand the parameters for creating an instance.

    Figure 2 shows the instance parameters.

    Figure 2 Creating an instance
    Table 1 Parameters for creating an instance

    Parameter

    Description

    Instance Name

    Name of the instance to be created. The value contains only lowercase letters, digits, hyphens (-), and underscores (_) and must start with a lowercase letter.

    Service Model

    Support General image search.

    General image search: searches for images of similar content or categories in the image library.

    Customize Tag

    You can add image tags to facilitate image filtering when adding or querying images. A maximum of 10 tags can be added.

    For example, when creating an instance, add a custom tag scenery. After the instance is created, upload an image on the Add Image page, for example, an image of the sky. The value of the scenery tag can be set to sky. After the image is added, you can upload the image to be searched on the Search Image page and enter the tag value sky in the scenery field. In this way, only the image whose tag value is sky is returned in the search result.

    You can set custom tags to filter images that are found. If you do not set a custom tag when creating an instance, you can choose Instance Management > Instance Details to set one.

    Description

    Description of the created instance.

    You can purchase a discount package to call ImageSearch APIs. The package quota is deducted when you start to use the service.

  2. Click Create Now. The created instance is displayed on the Instance Management page. See Figure 3.
    Figure 3 Instance management

Step 3: Offline Import

ImageSearch provides the offline import function. You can import image files to instances in batches. Before using this function, upload the required image files to OBS.

1. Preparations before offline data import

  1. Before using OBS, you need to subscribe to it. For details, see Logging In to OBS Console in the Object Storage Service Console Operation Guide.
  2. To store data in OBS, create a bucket first. A bucket is a container used to store objects in OBS. For details about how to create a bucket, see Creating a Bucket in the Object Storage Service Console Operation Guide.

    Information about the created OBS bucket:

    Region: CN North-Beijing1

    Bucket Name: obs-5daf

    Storage Class: Standard

    Bucket Policy: Private

    1. You can only import images from Object Storage Service (OBS) to ImageSearch. Before using this function, upload the images to OBS.
    2. Retain the default value of Bucket Policy.
    3. The region of the ImageSearch instance must be the same as that of the OBS bucket to which the image is uploaded.
  3. Upload files to the OBS bucket. For details about how to upload file, see Uploading a File in the Object Storage Service Console Operation Guide.

2. Executing the offline import task

The offline import function can be implemented by using OBS buckets or list files.

  • Method 1: Import data from an OBS bucket. (You need to provide the OBS directory where the data is stored.)

    To implement offline import with OBS, grant the permission to access OBS objects to the ImageSearch service account.

    1. On the Instance Management page, click Offline Import in the Operation column. The Offline Import page is displayed.
      Figure 4 Offline import
    2. Select the OBS bucket where data is stored, for example, obs-5daf. Click Authorize. When the button becomes unavailable, the OBS authorization is complete.

      The authorization operation needs to performed only once. If the Authorize button becomes unavailable, the selected bucket has been authorized. If the Authorize button is available, the OBS bucket needs to be authorized.

    3. Click OK to create an offline import task. See Figure 5.
      Figure 5 Importing data from an OBS bucket
    4. If you select Specify Directory/File, enter a folder in the OBS bucket and import data from the specified directory. For example, import data from the data directory in the obs-5daf bucket. See Figure 6.
      Figure 6 Importing data from an OBS directory
  • Method 2: Import data from a list file. (You need to provide a JSON file with the extension .batch.)

    ImageSearch can obtain the information about the images to be imported from a list file. The file list stores the content related to the offline import task. You can customize tags for the images. The list file format must comply with the following rules:

    1. The file name extension must be .batch.
    2. The list file needs to be stored in the bucket where the data is stored. There are no special requirements on the directories in the bucket. Figure 7 shows offline import with a list file.
      Figure 7 Importing data with a list file
    3. The content format of the list file is as follows:
      • Each line corresponds to an image. See Example list file.
      • The images are in JSON format. For details about the fields, see Table 2.
        Table 2 Parameters in the list file

        Parameter

        Mandatory

        Type

        Description

        operation

        Yes

        String

        Operation type. The value can be add, indicating adding an image.

        path

        Yes

        String

        Image URL. The URL is used as the ID of an indexed image in the gallery, as well as the address for downloading the image. Currently, images can be downloaded only from OBS in the region where ImageSearch is located.

        tags

        No

        Array

        Custom image tag. A maximum of 10 tags are supported.

      • Example list file
        {"operation":"add","path":"https://obs-5daf.obs.cn-north-1.myhuaweicloud.com/data/1.jpg", "tags":{"tag1":"v1"}}
        {"operation":"add","path":"https://obs-5daf.obs.cn-north-1.myhuaweicloud.com/data/1.jpg"}
        {"operation":"add","path":"data/1.jpg", "tags":{"my_tag1":"v1","my_tag2":"v2","my_tag3":"v3"}}

3. Viewing the offline import tasks

On the Instance Management page, click Offline Import in the Operation column. On the Offline Import page that is displayed, view the offline import tasks.

The offline import status can be Initializing, Running, or Successful. Initializing indicates that the task is being prepared. Running indicates that the image is being imported to the instance. Successful indicates that the offline import task is completed,

as shown in Figure 8.

Figure 8 Viewing the offline import tasks

Step 4: Testing the Instance

  1. On the Instance Management page, click Test in the Operation column. On the Test page that is displayed, add an image and search for the similar images.

    This example shows how to search for images that are similar to image 1.jpg in the OBS bucket.

  2. On the Search Image tab page, set Search Method to Local, select image 1.jpg, and click Search, as shown in Figure 9.
    Figure 9 Testing an instance
  3. In the Response Result area, the matching result between the imagesearch-test instance and the local image 1.jpg in the obs-5daf bucket is displayed. For details about the response parameters, see the response parameter description.
    Figure 10 shows the response result.
    Figure 10 Response result

Step 5: Deleting the Instance

If an instance is no longer needed after the instance is run, you can delete it to avoid wasting resources or occupying the quota.

An instance cannot be deleted if it has any offline import task that has not been completed.

Deleted instance cannot be recovered. Exercise caution when performing this operation.

  1. In the left navigation pane, click Instance Management. The Instance Management page is displayed.
  2. Locate the row that contains test1, and choose Mode > Delete in the Operation column.
  3. In the dialog box that is displayed, click OK to delete the instance.