Shubham Tomar
Shubham Tomar

Reputation: 374

Azure Face API gives APIErrorException: (InvalidRequest) Invalid request has been sent

I am calling Azure Face API using its python sdk. I am getting the following response :-

enter image description here

I have also checked Monetring in Azure portal it shows this:-

enter image description here

When i check it in the Azure price calculator it shows:-

enter image description here

I am using Azure Cognitive Services for Computer Vision, everything works fine, but don't know why only Face API throws exception.
I have also tried similar images with the same code, it works fine with my other account's credentials but still I am facing this error.

Thanks

Upvotes: 3

Views: 1798

Answers (2)

hasManyStupidQuestions
hasManyStupidQuestions

Reputation: 273

Because of updates to Azure's Responsible AI policy, many features of the Face API are locked down except for Limited Access customers. This includes returning the Face ID that the face service creates and uses internally. See this Microsoft thread.

It's not very clear in the documentation, but the default value of the return_face_id parameter (something that is now Limited Access / locked down) of both the detect_with_stream and detect_with_url methods of the FaceOperations class (which is the face attribute of instances of FaceClient) is True, i.e. by default the SDK sends API calls that try to do restricted operations.

If you change return_face_id to False, you will be able to use the API (provided you don't try to use other locked down / Limited Access features).

TL;DR: Instead of

from azure.cognitiveservices.vision.face import FaceClient
...
face_client = FaceClient(endpoint, credentials) 
detected_faces = face_client.face.detect_with_stream(...)

do

from azure.cognitiveservices.vision.face import FaceClient
...
face_client = FaceClient(endpoint, credentials) 
detected_faces = face_client.face.detect_with_stream(..., return_face_id=False)

The same also applies for detect_with_url instead of detect_with_stream.

Upvotes: 0

Nicolas R
Nicolas R

Reputation: 14589

I think the issue you are facing is due to the latest updates of Face API product, which is detailed in this blog post.

In a few words, some features have been disabled.

In particular:

In another change, we will retire facial analysis capabilities that purport to infer emotional states and identity attributes such as gender, age, smile, facial hair, hair, and makeup. We collaborated with internal and external researchers to understand the limitations and potential benefits of this technology and navigate the tradeoffs. In the case of emotion classification specifically, these efforts raised important questions about privacy, the lack of consensus on a definition of “emotions,” and the inability to generalize the linkage between facial expression and emotional state across use cases, regions, and demographics. API access to capabilities that predict sensitive attributes also opens up a wide range of ways they can be misused—including subjecting people to stereotyping, discrimination, or unfair denial of services.

To mitigate these risks, we have opted to not support a general-purpose system in the Face API that purports to infer emotional states, gender, age, smile, facial hair, hair, and makeup. Detection of these attributes will no longer be available to new customers beginning June 21, 2022, and existing customers have until June 30, 2023, to discontinue use of these attributes before they are retired.

In your code, you are asking for some of these attributes (gender & age) so you should remove those attributes and try again.

Upvotes: 1

Related Questions