The image recognition feature uses AI technology to detect tags and confidence levels in images.
New features and optimizations for Intelligent Media Management (IMM) are primarily available in the new version. The old version is being gradually phased out. For a better experience, use the image tag detection feature provided by the new version of IMM. For a comparison of the new and old versions of Intelligent Media Management, see New and old version usage guide.
Prerequisites
Intelligent Media Management (IMM) is activated and bound to Object Storage Service (OSS). For more information, see Quick Start.
If you use a Resource Access Management (RAM) user to access IMM features, ensure that the RAM user has the following permissions.
System permissions:
AliyunOSSReadOnlyAccessandAliyunIMMFullAccess.For more information, see Manage RAM user permissions.
Custom permissions:
oss:ProcessImmandram:GetRole.Create the custom permissions and then grant them to the RAM user. For more information, see Grant custom access policies to a RAM user.
Parameters
Action: imm/tagimage
The following table describes the response parameters.
Tags are organized in a hierarchical structure, where each tag usually has a parent tag. More than 30 categories and thousands of tags are supported. For more information, see Content recognition.
Name | Type | Description |
RequestId | string | The ID of the request. |
ImageUri | string | The OSS URI of the image. |
TagConfidence | Float | The confidence score of the tag. This is a floating-point number that is less than or equal to 1. |
TagLevel | Integer | The level of the tag. The value is an integer that starts from 1. A value of 1 indicates a top-level tag. A value of 2 indicates a second-level tag, and so on. |
TagName | String | The name of the tag. |
ParentTagName | String | The name of the parent tag. If the tag is a top-level tag, this parameter is empty. |
httpStatusCode | Integer | The HTTP status code of the response. It indicates the result of the request. For example, a status code of 200 indicates that the request was successful. |
success | Boolean | Indicates whether the request was successful. A value of |
Sample response:
{
"ImageUri":"oss://image-demo/example.jpg",
"RequestId":"5C3D858E530E23D52CA0ED09",
"Tags":[
{
"TagConfidence":0.2999534606933594,
"TagLevel":1,
"TagName":"Landscape"
},
{
"ParentTagName":"Landscape",
"TagConfidence":0.2999534606933594,
"TagLevel":2,
"TagName":"Night"
},
{
"TagConfidence":0.2677214741706848,
"TagLevel":1,
"TagName":"Outdoors"
},
{
"ParentTagName":"Outdoors",
"TagConfidence":0.2677214741706848,
"TagLevel":2,
"TagName":"City"
}
],
"httpStatusCode":200,
"success":true
}For more information about parsing image tags, see Content recognition.
Examples
Assume that you send a request for the image.jpg file in the imm-demo bucket. The bucket is in the China (Hangzhou) region, and the endpoint is oss-cn-hangzhou.aliyuncs.com. The following code shows the structure of the unsigned request:
http://image-demo.oss-cn-hangzhou.aliyuncs.com/image.jpg?x-oss-process=imm/tagimageThe following code shows how to call this action using the software development kit (SDK) for Python:
# Create a bucket instance.
bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
# Recognize the image.
style = 'imm/tagimage'
resp = bucket.get_object(objectKey, process=style)
# Parse the result.
data = resp.read(resp.content_length)
result = json.loads(data)
print "requestId: " + json.dumps(result["RequestId"], indent=4, sort_keys=True)
print "SuccessDetails: " + json.dumps(result["SuccessDetails"], indent=4, sort_keys=True)
print "FailDetails: " + json.dumps(result["FailDetails"], indent=4, sort_keys=True)