智能标签

本文介绍了Python SDK V2.0的安装方式和使用智能标签SDK的示例代码。

版本说明

媒体处理的Python SDK版本需要在3.6版本及以上。阿里云Python SDK V2.0推荐的pip安装方式:

pip install alibabacloud_mts20140618==5.0.0

前提条件

使用前请先初始化客户端,详细说明请参见初始化

提交智能标签作业

调用SubmitSmarttagJob提交智能标签作业,接口字段和参数详细信息请参见提交智能标签作业,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        submit_smarttag_job_request = mts_20140618_models.SubmitSmarttagJobRequest(
            # 管道ID
            pipeline_id='2',
            # 视频标题
            title='example-title-****',
            # 视频内容描述
            content='example content ****',
            # 额外的请求参数
            params='false',
            # Callback路径
            notify_url='https://example.com/endpoint/aliyun/ai?id=76401125000***',
            # 通过回调透传回来的信息
            user_data='{"key":"value"}',
            # 需要分析的视频或图片文件的地址
            input='oss://mybucket-****/example-****.mp4',
            # 模板ID用于指定分析算法
            template_id='39f8e0bc005e4f309379701645f4****',
            # 任务在其对应管道内的优先级
            priority='5'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.submit_smarttag_job_with_options(submit_smarttag_job_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        submit_smarttag_job_request = mts_20140618_models.SubmitSmarttagJobRequest(
            # 管道ID
            pipeline_id='2',
            # 视频标题
            title='example-title-****',
            # 视频内容描述
            content='example content ****',
            # 额外的请求参数
            params='false',
            # Callback路径
            notify_url='https://example.com/endpoint/aliyun/ai?id=76401125000***',
            # 通过回调透传回来的信息
            user_data='{"key":"value"}',
            # 需要分析的视频或图片文件的地址
            input='oss://mybucket-****/example-****.mp4',
            # 模板ID用于指定分析算法
            template_id='39f8e0bc005e4f309379701645f4****',
            # 任务在其对应管道内的优先级
            priority='5'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.submit_smarttag_job_with_options_async(submit_smarttag_job_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:]) 

查询智能标签作业

调用QuerySmarttagJob查询智能标签作业,接口字段和参数详细信息请参见查询智能标签作业,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        query_smarttag_job_request = mts_20140618_models.QuerySmarttagJobRequest(
            #需要查询的智能标签作业ID
            job_id='39f8e0bc005e4f309379701645f4****',
            #额外的请求参数
            params='{"labelResultType":"auto"}'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.query_smarttag_job_with_options(query_smarttag_job_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        query_smarttag_job_request = mts_20140618_models.QuerySmarttagJobRequest(
            # 需要查询的智能标签作业ID
            job_id='39f8e0bc005e4f309379701645f4****',
            # 额外的请求参数
            params='{"labelResultType":"auto"}'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.query_smarttag_job_with_options_async(query_smarttag_job_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

添加模板

调用AddSmarttagTemplate 添加一个模板,接口字段和参数详细信息请参见添加模板,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        add_smarttag_template_request = mts_20140618_models.AddSmarttagTemplateRequest(
            # 自定义模板名称
            template_name='template-example-****',
            # 待分析文件所处行业
            industry='common',
            # 待分析文件使用场景
            scene='search',
            # 分析类型
            analyse_types='ocr',
            # 参与识别的⼈脸库ID列表
            face_category_ids='celebrity',
            # 人脸算法的参数
            face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
            # 参与识别的物体库ID列表
            object_group_ids='general,item,weapon,animal',
            # 参与识别的地域库ID列表
            landmark_group_ids='common',
            # 是否设置为默认模板(设置为默认模板后
            is_default=True,
            # 标注类型
            label_type='hmi',
            # 指定智能标签版本
            label_version='1.0',
            # 智能标签2.0和2.0-custom模式下
            knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
            # 关键词标签配置
            keyword_config='"type": "name,location,organization,other" }'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.add_smarttag_template_with_options(add_smarttag_template_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        add_smarttag_template_request = mts_20140618_models.AddSmarttagTemplateRequest(
            # 自定义模板名称
            template_name='template-example-****',
            # 待分析文件所处行业
            industry='common',
            # 待分析文件使用场景
            scene='search',
            # 分析类型
            analyse_types='ocr',
            # 参与识别的⼈脸库ID列表
            face_category_ids='celebrity',
            # 人脸算法的参数
            face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
            # 参与识别的物体库ID列表
            object_group_ids='general,item,weapon,animal',
            # 参与识别的地域库ID列表
            landmark_group_ids='common',
            # 是否设置为默认模板(设置为默认模板后
            is_default=True,
            # 标注类型
            label_type='hmi',
            # 指定智能标签版本
            label_version='1.0',
            # 智能标签2.0和2.0-custom模式下
            knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
            # 关键词标签配置
            keyword_config='"type": "name,location,organization,other" }'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.add_smarttag_template_with_options_async(add_smarttag_template_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])   

查询模板

调用QuerySmarttagTemplateList查询模板信息,接口字段和参数详细信息请参见查询模板,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        query_smarttag_template_list_request = mts_20140618_models.QuerySmarttagTemplateListRequest(
            # 模板ID
            template_id='05de22f255284c7a8d2aab535dde****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.query_smarttag_template_list_with_options(query_smarttag_template_list_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        query_smarttag_template_list_request = mts_20140618_models.QuerySmarttagTemplateListRequest(
            # 模板ID
            template_id='05de22f255284c7a8d2aab535dde****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.query_smarttag_template_list_with_options_async(query_smarttag_template_list_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])    

更新模板

调用UpdateSmarttagTemplate更新模板信息,接口字段和参数详细信息请参见更新模板,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        update_smarttag_template_request = mts_20140618_models.UpdateSmarttagTemplateRequest(
            # 模板ID
            template_id='05de22f255284c7a8d2aab535dde****',
            # 自定义模板名称
            template_name='template-example-****',
            # 待分析文件所处行业
            industry='common',
            # 使用场景
            scene='search',
            # 分析类型
            analyse_types='ocr,asr',
            # 参与识别的⼈脸库ID列表
            face_category_ids='celebrity',
            # 人脸算法的参数
            face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
            # 参与识别的物体库ID列表
            object_group_ids='general,item,weapon,animal',
            # 参与识别的地域库ID列表
            landmark_group_ids='common',
            # 是否默认模板
            is_default=True,
            # 标注类型
            label_type='hmi',
            # 指定智能标签版本
            label_version='1.0',
            # 智能标签2.0和2.0-custom模式下
            knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
            # 关键词标签配置
            keyword_config='{ "type": "name,location,organization,other" }'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.update_smarttag_template_with_options(update_smarttag_template_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        update_smarttag_template_request = mts_20140618_models.UpdateSmarttagTemplateRequest(
            # 模板ID
            template_id='05de22f255284c7a8d2aab535dde****',
            # 自定义模板名称
            template_name='template-example-****',
            # 待分析文件所处行业
            industry='common',
            # 使用场景
            scene='search',
            # 分析类型
            analyse_types='ocr,asr',
            # 参与识别的⼈脸库ID列表
            face_category_ids='celebrity',
            # 人脸算法的参数
            face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
            # 参与识别的物体库ID列表
            object_group_ids='general,item,weapon,animal',
            # 参与识别的地域库ID列表
            landmark_group_ids='common',
            # 是否默认模板
            is_default=True,
            # 标注类型
            label_type='hmi',
            # 指定智能标签版本
            label_version='1.0',
            # 智能标签2.0和2.0-custom模式下
            knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
            # 关键词标签配置
            keyword_config='{ "type": "name,location,organization,other" }'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.update_smarttag_template_with_options_async(update_smarttag_template_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])   

删除模板

调用DeleteSmarttagTemplate删除模板,接口字段和参数详细信息请参见删除模板,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        delete_smarttag_template_request = mts_20140618_models.DeleteSmarttagTemplateRequest(
            # 需要删除的模板ID
            template_id='05de22f255284c7a8d2aab535dde****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.delete_smarttag_template_with_options(delete_smarttag_template_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        delete_smarttag_template_request = mts_20140618_models.DeleteSmarttagTemplateRequest(
            # 需要删除的模板ID
            template_id='05de22f255284c7a8d2aab535dde****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.delete_smarttag_template_with_options_async(delete_smarttag_template_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

注册自定义人脸

调用RegisterCustomFace注册自定义人脸,接口字段和详细参数信息请参见注册⾃定义⼈脸,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        register_custom_face_request = mts_20140618_models.RegisterCustomFaceRequest(
            # ⼈物库ID
            category_id='CategoryId001-****',
            # ⼈物ID
            person_id='PersonId001-****',
            # 需要注册的⼈脸图⽚公网地址
            image_url='http://example-****.jpeg'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.register_custom_face_with_options(register_custom_face_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        register_custom_face_request = mts_20140618_models.RegisterCustomFaceRequest(
            # ⼈物库ID
            category_id='CategoryId001-****',
            # ⼈物ID
            person_id='PersonId001-****',
            # 需要注册的⼈脸图⽚公网地址
            image_url='http://example-****.jpeg'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.register_custom_face_with_options_async(register_custom_face_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

注销自定义人脸

调用UnregisterCustomFace注销自定义人脸,接口字段和参数详细说明请参见注销⾃定义⼈脸,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        unregister_custom_face_request = mts_20140618_models.UnregisterCustomFaceRequest(
            # ⼈物库ID
            category_id='CategoryId001-****',
            # ⼈物ID
            person_id='PersonId001-****',
            # 人脸ID
            face_id='15****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.unregister_custom_face_with_options(unregister_custom_face_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        unregister_custom_face_request = mts_20140618_models.UnregisterCustomFaceRequest(
            # ⼈物库ID
            category_id='CategoryId001-****',
            # ⼈物ID
            person_id='PersonId001-****',
            # 人脸ID
            face_id='15****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.unregister_custom_face_with_options_async(unregister_custom_face_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

添加自定义人物库或人物标签

调用TagCustomPerson添加自定义人物库或人物标签,接口字段和参数详细信息请参见添加自定义人物库或人物标签,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        tag_custom_person_request = mts_20140618_models.TagCustomPersonRequest(
            # ⼈物库ID
            category_id='CategoryId001-****',
            # ⼈物库名称
            category_name='CategoryNametest-****',
            # ⼈物库描述
            category_description='CategoryDescription001-****',
            # ⼈物ID
            person_id='PersonId001-****',
            # ⼈物名称
            person_name='PersonNametest-****',
            # ⼈物描述
            person_description='PersonDescriptiontest-****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.tag_custom_person_with_options(tag_custom_person_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        tag_custom_person_request = mts_20140618_models.TagCustomPersonRequest(
            # ⼈物库ID
            category_id='CategoryId001-****',
            # ⼈物库名称
            category_name='CategoryNametest-****',
            # ⼈物库描述
            category_description='CategoryDescription001-****',
            # ⼈物ID
            person_id='PersonId001-****',
            # ⼈物名称
            person_name='PersonNametest-****',
            # ⼈物描述
            person_description='PersonDescriptiontest-****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.tag_custom_person_with_options_async(tag_custom_person_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])

列出人物库所有人物和人脸信息

调用ListCustomPersons列出人物库所有人物和人脸信息,接口字段和参数详细说明请参见列出⼈物库所有⼈物和⼈脸信息,调用示例如下:

import os
import sys

from typing import List

from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_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() -> Mts20140618Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
        return Mts20140618Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        list_custom_persons_request = mts_20140618_models.ListCustomPersonsRequest(
            # ⼈物库ID
            category_id='CategoryId-****',
            # ⼈物ID
            person_id='PersonId-****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.list_custom_persons_with_options(list_custom_persons_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        list_custom_persons_request = mts_20140618_models.ListCustomPersonsRequest(
            # ⼈物库ID
            category_id='CategoryId-****',
            # ⼈物ID
            person_id='PersonId-****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.list_custom_persons_with_options_async(list_custom_persons_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])