This topic describes the application scenarios and usage of image label detection in Intelligent Media Management (IMM).
Overview
Image label detection recognizes image content such as scenes, objects, and events and automatically labels images. IMM provides thousands of image labels that fall into more than 30 categories. The following table lists label categories.
Scenarios
Scenario | Description |
Content recognition | You can use image label detection to build image content recognition applications that involve object identification and science popularization. These applications can recognize information such as objects and scenes in images. |
Photo and album management | Photos in a photo album are automatically classified based on image content. This enables efficient and automated photo management. |
Scene analysis | Image content is automatically analyzed and labeled, which improves analysis efficiency and reduces manual labeling costs. |
Content marketing | You can use image label detection to improve content marketing on platforms such as social networking, news, and e-commerce platforms. |
Limits
The following describes limits on image label detection.
Item | Limit |
Image formats | Image label detection supports the following image formats:
|
Image size | The following image size limits apply:
|
Prerequisites
An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.
Object Storage Service (OSS) is activated, a bucket is created, and objects are uploaded to the bucket. For more information, see Upload objects.
IMM is activated. For more information, see Activate IMM.
A project is created in the IMM console. For more information, see Create a project.
The OSS bucket and the IMM project reside in the same region.
NoteYou can call the CreateProject operation to create a project. For more information, see CreateProject.
You can call the ListProjects operation to query the existing projects in a specific region. For more information, see ListProjects.
Usage
Call the DetectImageLabels operation to detect image labels.
Example
IMM project: test-project
Image location: oss://test-bucket/test-object.jpg
Image:
Sample request
{
"ProjectName": "test-project",
"SourceURI": "oss://test-bucket/test-object.jpg",
"Threshold": 0.7
}
Sample response
Sample code
The following sample code provides an example on how to use IMM SDK for Python to detect image labels:
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint.
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all the API operations. To prevent security risks, we recommend that you call API operations or perform routine O&M as a RAM user.
# For security reasons, we recommend that you do not embed your AccessKey pair (AccessKey ID and AccessKey secret) in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For more information about how to configure environment variables, visit https://help.aliyun.com/document_detail/2361894.html.
imm_access_key_id = os.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
imm_access_key_secret = os.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
detect_image_labels_request = imm_20200930_models.DetectImageLabelsRequest(
project_name='test-project',
source_uri='oss://test-bucket/test-object.jpg',
threshold=0.7
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
client.detect_image_labels_with_options(detect_image_labels_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# The AccessKey pair of an Alibaba Cloud account has permissions on all the API operations. To prevent security risks, we recommend that you call API operations or perform routine O&M as a RAM user.
# For security reasons, we recommend that you do not embed your AccessKey pair (AccessKey ID and AccessKey secret) in your project code.
# In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For more information about how to configure environment variables, visit https://help.aliyun.com/document_detail/2361894.html.
imm_access_key_id = os.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
imm_access_key_secret = os.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
# Initialize the client.
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
detect_image_labels_request = imm_20200930_models.DetectImageLabelsRequest(
project_name='test-project',
source_uri='oss://test-bucket/test-object.jpg',
threshold=0.7
)
runtime = util_models.RuntimeOptions()
try:
# Write your code to print the response of the API operation if necessary.
await client.detect_image_labels_with_options_async(detect_image_labels_request, runtime)
except Exception as error:
# Print the error message if necessary.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
FAQ
Does image label detection recognize text, date information, and location information from images?
No, image label detection does not recognize text, date information, and location information from images. To extract text from images, you can use semantic retrieval. You can use extracted text to check for dates and organization names. To recognize location information from an image that has Exchangeable Image File Format (EXIF) data, you can call the operation to query the coordinates of the location where the image was taken.
Image label detection may not accurately detect violence, pornography, or other inappropriate content from images. We recommend that you use image label detection together with manual image auditing to improve content moderation.