要在AWS CLI(Windows)中启用“detect-custom-labels”功能,您需要先安装最新版本的AWS CLI,并确保已配置正确的访问密钥和区域。接下来,您需要使用以下命令来安装AWS SDK for Python(Boto3):
pip install boto3
安装完成后,您可以使用以下Python代码示例来执行detect-custom-labels操作:
import boto3
def detect_custom_labels(image_path):
# 创建Rekognition客户端
rekognition_client = boto3.client('rekognition')
# 执行detect-custom-labels操作
response = rekognition_client.detect_custom_labels(
Image={
'Bytes': open(image_path, 'rb').read()
},
ProjectVersionArn='YOUR_PROJECT_VERSION_ARN'
)
# 处理响应
custom_labels = response['CustomLabels']
for label in custom_labels:
print('Label: ' + label['Name'])
print('Confidence: ' + str(label['Confidence']))
# 调用detect_custom_labels函数并传入要检测的图像路径
detect_custom_labels('path/to/your/image.jpg')
请确保将“YOUR_PROJECT_VERSION_ARN”替换为您自己的项目版本ARN。此代码将打印出检测到的自定义标签及其置信度。
希望这可以帮助您解决问题!