【问题标题】:Azure Detect With Stream Invalid RequestAzure 检测流无效请求
【发布时间】:2022-08-03 14:16:05
【问题描述】:

这是我第一次使用 Azure 人脸检测 API,我在这里使用此代码:

import os
import io
import cv2
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
from PIL import Image, ImageDraw, ImageFont

API_KEY = \'...\'
ENDPOINT = \'...\'
image = open(\'realmadrid.jpg\', \'rb\')

face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(API_KEY))


response_detected_faces = face_client.face.detect_with_stream(
    image=image,
    detection_model=\'detection_03\',
    recognition_model=\'recognition_04\',
    return_face_landmarks=True,
)

if not response_detected_faces:
    raise Exception(\"No face detected!\")

print(f\"Number of face detected {len(response_detected_faces)}\")

问题是每次我运行这段代码时都会出现异常:

/home/thecowmilk/dev/azure_faceapi/venv/bin/python /home/thecowmilk/dev/azure_faceapi/faceapi/starting.py
Traceback (most recent call last):
  File \"/home/thecowmilk/dev/azure_faceapi/faceapi/starting.py\", line 20, in <module>
    detected_faces = face_client.face.detect_with_stream(
  File \"/home/thecowmilk/dev/azure_faceapi/venv/lib/python3.8/site-packages/azure/cognitiveservices/vision/face/operations/_face_operations.py\", line 782, in detect_with_stream
    raise models.APIErrorException(self._deserialize, response)
azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (InvalidRequest) Invalid request has been sent.

Process finished with exit code 1

我不知道如何解决这个问题。它看起来没有太多关于 Azure 人脸检测 API 的信息。我会很感激你的想法<3!

    标签: python azure


    【解决方案1】:
    • 根据Get face landmarks获取人脸地标数据,将detectionModel参数设置为DetectionModel.Detection01,将returnFaceLandmarks参数设置为true
    IList<DetectedFace> faces2 = await faceClient.Face.DetectWithUrlAsync(url: imageUrl, returnFaceId: true, returnFaceLandmarks: true, detectionModel: DetectionModel.Detection01);
    
    var faces3 = await faceClient.Face.DetectWithUrlAsync(url: imageUrl, returnFaceId: true, returnFaceAttributes: requiredFaceAttributes, detectionModel: DetectionModel.Detection01, recognitionModel: RecognitionModel.Recognition04);
    

    而不是detection_03 使用detection_01

    response_detected_faces = face_client.face.detect_with_stream(
        image=image,
        detection_model='detection_01',
        recognition_model='recognition_04',
        return_face_landmarks=True,
    )
    

    您可以参考最近关于 Face API 某些功能的更改/限制:Responsible AI investments and safeguards for facial recognition

    【讨论】:

      猜你喜欢
      • 2020-06-16
      • 2021-05-19
      • 2019-07-19
      • 1970-01-01
      • 2019-04-23
      • 2014-03-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多