APIErrorException: (BadArgument) 'recognitionModel' is incompatible :AZURE COGNITIVE FACE

眉间皱痕 提交于 2020-03-05 00:34:33

问题


I'm creating an attendance system using AZURE COGNITIVE FACE API. I am storing the attendance in an excel sheet. But there occurs an error " 'recognitionModel' is incompatible." From the documentation I have come to know that there are two recognition models(recognition_01 , recognition_02). Is it required to mention the type? If so how to do it in python?

ERROR:

  File "identify.py", line 58, in <module>
    res = face_client.face.identify(faceIds, global_var.personGroupId)
  File "C:\Python\Python36\lib\site-packages\azure\cognitiveservices\vision\face\operations\_face_operations.py", line 313, in identify
    raise models.APIErrorException(self._deserialize, response)
azure.cognitiveservices.vision.face.models._models_py3.APIErrorException: (BadArgument) 'recognitionModel' is incompatible.

CODE:

from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType
import global_variables as global_var
import os, urllib
import sqlite3
from openpyxl import Workbook, load_workbook
from openpyxl.utils import get_column_letter, column_index_from_string
from openpyxl.cell import Cell
import time
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)



#get current date
currentDate = time.strftime("%d_%m_%y")
wb = load_workbook(filename = "reports.xlsx")
sheet = wb['Cse16']

def getDateColumn():
    for i in range(1, len(list(sheet.rows)[0]) + 1):
        col = get_column_letter(i)
        if sheet['%s%s'% (col,'1')].value == currentDate:
            return col

Key = global_var.key


ENDPOINT = 'https://centralindia.api.cognitive.microsoft.com'
face_client = FaceClient(ENDPOINT,CognitiveServicesCredentials(Key))


connect = sqlite3.connect("Face-DataBase")


attend = [0 for i in range(60)] 

currentDir = os.path.dirname(os.path.abspath(__file__))
directory = os.path.join(currentDir, 'Cropped_faces')
for filename in os.listdir(directory):
    if filename.endswith(".jpg"):
        print(filename)
        img_data = open(os.path.join(directory,filename), 'r+b')
        res = face_client.face.detect_with_stream(img_data)
        print("Res = {}".format(res))

        if len(res) < 1:
            print("No face detected.")
            continue

        faceIds = []
        for face in res:
            faceIds.append(face.face_id)
        res = face_client.face.identify(faceIds, global_var.personGroupId)   #Error occuring line
        #print(filename)
        print("res = {}".format(res))

        for face  in res:
            if not face['candidates']:
                print("Unknown")
            else:
                personId = face['candidates'][0]['personId']
                print("personid = {}".format(personId))
                #cmd =  + personId
                cur = connect.execute("SELECT * FROM Students WHERE personID = (?)", (personId,))
                #print("cur = {}".format(cur))
                for row in cur:
                    print("aya")
                    print("row = {}".format(row))
                    attend[int(row[0])] += 1
                print("---------- " + row[1] + " recognized ----------")
        time.sleep(6)

for row in range(2, len(list(sheet.columns)[0]) + 1):
    rn = sheet.cell(row = row, column  =1).value
    if rn is not None:
        print("rn = {}".format(rn))
        rn = rn[-2:]
        if attend[int(rn)] != 0:
            col = getDateColumn()
            print("col = {}".format(col))
            sheet['%s%s' % (col, str(row))] = 0

wb.save(filename = "reports.xlsx")

回答1:


As mentioned in the services documentation portal (for example here for West Europe but is the same for all regions) for Identify operation:

The 'recognitionModel' associated with the query faces' faceIds should be the same as the 'recognitionModel' used by the target person group or large person group.

So it looks like you have a mismatch here. You don't have to pass the recognitionModel in the Identify operation but in the Detect operation that you are doing first.

And you must ensure that this value is the same as the one used for your personGroup where you want to identify the person (see personGroup create operation, containing the recognition variable)



来源:https://stackoverflow.com/questions/60360341/apierrorexception-badargument-recognitionmodel-is-incompatible-azure-cogni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!