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
- Step 1: Applying for a Service
- Step 2: Creating an Instance
- Step 3: Offline Import
- Step 4: Testing the Instance
- Step 5: Deleting the Instance
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:
- Log in to Huawei Cloud. If you do not have a Huawei Cloud account, register on the registration page as prompted.
- On the top of the Huawei Cloud page, choose Products > Enterprise Intelligence > ImageSearch. The ImageSearch product page is displayed.
- On the product page, click Try Now and enter the username and password to access the ImageSearch management console.
- The Dashboard page displays the total number of API calls in the latest week and the status of all instances. See Figure 1.
Step 2: Creating an Instance
Before using ImageSearch, create an instance and select a service model for search.
- 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.
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.
- Click Create Now. The created instance is displayed on the Instance Management page. See Figure 3.
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
- Before using OBS, you need to subscribe to it. For details, see Using OBS Console in the Object Storage Service Console Operation Guide.
- To store data in OBS, create a bucket first. A bucket is a container used to store objects in OBS. For 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
- You can only import images from Object Storage Service (OBS) to ImageSearch. Before using this function, upload the images to OBS.
- Retain the default value of Bucket Policy.
- The region of the ImageSearch instance must be the same as that of the OBS bucket to which the image is uploaded.
- Upload files to the OBS bucket. For how to upload a 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.
- On the Instance Management page, click Offline Import in the Operation column. The Offline Import page is displayed.
Figure 4 Offline import
- 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.
- Click OK to create an offline import task. See Figure 5.
- 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.
- On the Instance Management page, click Offline Import in the Operation column. The Offline Import page is displayed.
- 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:
- The file name extension must be .batch.
- 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.
- 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.
Step 4: Testing the Instance
- 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.
- On the Search Image tab page, set Search Method to Local, select image 1.jpg, and click Search, as shown in Figure 9.
- 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.
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.
- In the left navigation pane, click Instance Management. The Instance Management page is displayed.
- Locate the row that contains test1, and choose Mode > Delete in the Operation column.
- In the dialog box that is displayed, click OK to delete the instance.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot