APIErrorException: (BadArgument) «Модель распознавания» несовместима: AZURE COGNITIVE FACE

Я создаю систему посещаемости, используя AZURE COGNITIVE FACE API. Я сохраняю посещаемость в таблице Excel. Но возникает ошибка «Модель распознавания несовместима». Из документации я узнал, что существует две модели распознавания (распознавание_01, распознавание_02). Обязательно ли упоминать тип? Если да, то как это сделать на Python?

ОШИБКА:

  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.

КОД:

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")

person Arun Soorya    schedule 23.02.2020    source источник


Ответы (1)


Как указано на портале документации служб (например, здесь для Западной Европы, но одинаково для всех регионов) для Identify операции:

«Модель распознавания», связанная с FaceIds лиц в запросе, должна быть такой же, как «Модель распознавания», используемая целевой группой людей или большой группой людей.

Похоже, у вас здесь несоответствие. Вам не нужно передавать распознаваниеModel в операции Identify, но в операции Detect, которую вы выполняете в первую очередь.

И вы должны убедиться, что это значение совпадает со значением, используемым для вашей personGroup, в которой вы хотите идентифицировать человека (см. PersonGroup create operation, содержащая переменную распознавания)

person Nicolas R    schedule 26.02.2020
comment
Да, я обнаружил несоответствие. Спасибо за информацию - person Arun Soorya; 27.02.2020