All Products
Search
Document Center

Intelligent Media Management:Image label detection

Last Updated:Nov 14, 2024

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.

图片标签检测..jpeg

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:

  • PNG

  • JPG

  • JPEG

Image size

The following image size limits apply:

  • The image to detect cannot exceed 20 MB in size.

  • The height or width of the image to detect cannot exceed 30,000 pixels.

  • The number of total pixels of the image to detect cannot exceed 250,000,000.

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.

    Note
    • You 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:

    test-object

Sample request

{
    "ProjectName": "test-project",
    "SourceURI": "oss://test-bucket/test-object.jpg",
    "Threshold": 0.7
}

Sample response

{
  "RequestId": "91C92EBA-5E51-50C8-B51B-8C3BDC66EB86",
  "Labels": [
    {
      "CentricScore": 0.797,
      "Language": "zh-Hans",
      "LabelConfidence": 1,
      "LabelName": "Apparel",
      "LabelLevel": 2,
      "ParentLabelName": "Clothing"
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 1,
      "LabelName": "Carnivore",
      "LabelLevel": 2,
      "LabelName": "Wildlife",
    },
    {
      "CentricScore": 0.723,
      "Language": "zh-Hans",
      "LabelConfidence": 0.987,
      "LabelName": "Tent",
      "LabelLevel": 2,
      "ParentLabelName": "Other scenes"
    },
    {
      "CentricScore": 0.759,
      "Language": "zh-Hans",
      "LabelConfidence": 0.963,
      "LabelName": "Building",
      "LabelLevel": 3,
      "ParentLabelName": "Landmark"
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 0.949,
      "LabelName": "Pets",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.787,
      "Language": "zh-Hans",
      "LabelConfidence": 0.944,
      "LabelName": "Portrait",
      "LabelLevel": 2,
      "ParentLabelName": "Face"
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 0.939,
      "LabelName": "Dog",
      "LabelLevel": 3,
      "ParentLabelName": "Pet dog"
    },
    {
      "CentricScore": 0.803,
      "Language": "zh-Hans",
      "LabelConfidence": 0.924,
      "LabelName": "Person",
      "LabelLevel": 2,
      "ParentLabelName": "Face"
    },
    {
      "CentricScore": 0.687,
      "Language": "zh-Hans",
      "LabelConfidence": 0.895,
      "LabelName": "Golden Retriever",
      "LabelLevel": 3,
      "ParentLabelName": "Pet dog"
    },
    {
      "CentricScore": 0.689,
      "Language": "zh-Hans",
      "LabelConfidence": 0.885,
      "LabelName": "Camping",
      "LabelLevel": 2,
      "ParentLabelName": "Entertainment"
    },
    {
      "CentricScore": 0.76,
      "Language": "zh-Hans",
      "LabelConfidence": 0.883,
      "LabelName": "Furniture",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.802,
      "Language": "zh-Hans",
      "LabelConfidence": 0.878,
      "LabelName": "Male",
      "LabelLevel": 2,
      "ParentLabelName": "Face"
    },
    {
      "CentricScore": 0.792,
      "Language": "zh-Hans",
      "LabelConfidence": 0.85,
      "LabelName": "Female",
      "LabelLevel": 2,
      "ParentLabelName": "Face"
    },
    {
      "CentricScore": 0.722,
      "Language": "zh-Hans",
      "LabelConfidence": 0.849,
      "LabelName": "Plant",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.729,
      "Language": "zh-Hans",
      "LabelConfidence": 0.84,
      "LabelName": "Lawn",
      "LabelLevel": 3,
      "ParentLabelName": "Natural landscape"
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 0.818,
      "LabelName": "Animal",
      "LabelLevel": 2,
      "LabelName": "Wildlife",
    },
    {
      "CentricScore": 0.782,
      "Language": "zh-Hans",
      "LabelConfidence": 0.816,
      "LabelName": "T-shirt",
      "LabelLevel": 2,
      "ParentLabelName": "Clothing"
    },
    {
      "CentricScore": 0.749,
      "Language": "zh-Hans",
      "LabelConfidence": 0.813,
      "LabelName": "Shoes",
      "LabelLevel": 2,
      "ParentLabelName": "Clothing"
    },
    {
      "CentricScore": 0.826,
      "Language": "zh-Hans",
      "LabelConfidence": 0.813,
      "LabelName": "Footwear",
      "LabelLevel": 2,
      "ParentLabelName": "Clothing"
    },
    {
      "CentricScore": 0.685,
      "Language": "zh-Hans",
      "LabelConfidence": 0.775,
      "LabelName": "Labrador",
      "LabelLevel": 3,
      "ParentLabelName": "Pet dog"
    },
    {
      "CentricScore": 0.76,
      "Language": "zh-Hans",
      "LabelConfidence": 0.746,
      "LabelName": "Chair",
      "LabelLevel": 2,
      "ParentLabelName": "Furniture"
    },
    {
      "CentricScore": 0.757,
      "Language": "zh-Hans",
      "LabelConfidence": 0.742,
      "LabelName": "Girl",
      "LabelLevel": 2,
      "ParentLabelName": "Face"
    },
    {
      "CentricScore": 0.776,
      "Language": "zh-Hans",
      "LabelConfidence": 0.726,
      "LabelName": "Smile",
      "LabelLevel": 2,
      "ParentLabelName": "Appearance"
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 0.722,
      "LabelName": "Dog Sports",
      "LabelLevel": 2,
      "ParentLabelName": "Sports"
    },
    {
      "CentricScore": 0.685,
      "Language": "zh-Hans",
      "LabelConfidence": 0.664,
      "LabelName": "Golden Retriever",
      "LabelLevel": 3,
      "ParentLabelName": "Pet dog"
    },
    {
      "CentricScore": 0.826,
      "Language": "zh-Hans",
      "LabelConfidence": 1,
      "LabelName": "Clothing",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 1,
      "LabelName": "Wildlife",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.723,
      "Language": "zh-Hans",
      "LabelConfidence": 0.987,
      "LabelName": "Other scenes"
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.759,
      "Language": "zh-Hans",
      "LabelConfidence": 0.963,
      "LabelName": "Landmark",
      "LabelLevel": 2,
      "ParentLabelName": "Tourism & Geography"
    },
    {
      "CentricScore": 0.803,
      "Language": "zh-Hans",
      "LabelConfidence": 0.944,
      "LabelName": "Face",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 0.939,
      "LabelName": "Pet dog",
      "LabelLevel": 2,
      "ParentLabelName": "Pets"
    },
    {
      "CentricScore": 0.689,
      "Language": "zh-Hans",
      "LabelConfidence": 0.885,
      "LabelName": "Entertainment",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.729,
      "Language": "zh-Hans",
      "LabelConfidence": 0.84,
      "LabelName": "Natural landscape",
      "LabelLevel": 2,
      "ParentLabelName": "Tourism & Geography"
    },
    {
      "CentricScore": 0.776,
      "Language": "zh-Hans",
      "LabelConfidence": 0.726,
      "LabelName": "Appearance",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.695,
      "Language": "zh-Hans",
      "LabelConfidence": 0.722,
      "LabelName": "Sports",
      "LabelLevel": 1,
      "ParentLabelName": ""
    },
    {
      "CentricScore": 0.759,
      "Language": "zh-Hans",
      "LabelConfidence": 0.963,
      "LabelName": "Tourism & Geography",
      "LabelLevel": 1,
      "ParentLabelName": ""
    }
  ]
}
Note

The image contains the following labels:

  • Parent labels: Clothing, Wildlife, Landmark, Face, Pet dog, and more

  • Labels: Apparel, Carnivore, Tent, Building, Pets, Face, Dog, and more

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

  1. 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.

Note

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.