python - Azure Face API,python SDK 属性 url
问题描述
我正在使用Azure 文档提供的 Python SDK 片段。
BASE_URL ="https://eastus.api.cognitive.microsoft.com/face/v1.0/
CF.BaseUrl.set(BASE_URL)
我想返回人脸属性,此处引用的文档建议添加
/detect[&returnFaceAttributes=age,gender]
到 Base URl 将返回年龄和性别属性。它给我一个错误,我错过了什么吗?
这是我第一次使用 Azure Face API。
解决方案
我们可以使用以下代码来获取 returnFaceAttributes
faces = CF.face.detect(img_url,attributes='age,gender')
整个演示代码
import cognitive_face as CF
KEY = 'xxxxx' # Replace with a valid subscription key (keeping the quotes in place).
CF.Key.set(KEY)
BASE_URL = 'https://{location}.api.cognitive.microsoft.com/face/v1.0' # Replace with your regional Base URL
CF.BaseUrl.set(BASE_URL)
#You can use this example JPG or replace the URL below with your own URL to a JPEG image.
img_url = 'https://raw.githubusercontent.com/Microsoft/Cognitive-Face-Windows/master/Data/detection1.jpg'
faces = CF.face.detect(img_url,attributes='age,gender')
测试结果:
推荐阅读
- python - 使用多处理时设置池映射操作的时间限制?
- postgresql - 在 Postgres 中设置 search_path 是否会阻塞?
- machine-learning - 如何在 pytorch 中从预训练模型创建子模型,而无需重写整个架构?
- database - 数据库应该避免删除资源吗?
- python - 从另一个 .py 导入变量而不运行模块
- javascript - 如何知道在多条件打字稿中哪个条件失败
- css - Angular 材质 Sass 通过全局 scss 文件上的 map-get 和深色主题动态获取样式
- django - 姜戈射频。如何获得具有嵌套关系的 Django 模型
- javascript - Javascript中异步函数的困惑
- git - 现有的 git(私人远程)仓库已经存在。无法与之前的开发者取得联系