APIErrorException:(BadArgument)'recognitionModel'不兼容:AZURE COGNITIVE FACE [英] APIErrorException: (BadArgument) 'recognitionModel' is incompatible :AZURE COGNITIVE FACE

查看:288
本文介绍了APIErrorException:(BadArgument)'recognitionModel'不兼容:AZURE COGNITIVE FACE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AZURE COGNITIVE FACE API创建一个考勤系统.我将出勤记录存储在Excel工作表中.但是会出现错误'recognitionModel'不兼容".从文档中,我知道有两种识别模型(recognition_01和Recognition_02).是否需要提及类型?如果可以的话,如何在python中做?

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?

错误:

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

推荐答案

如服务文档门户中所述(例如

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

与查询面孔的faceIds关联的"recognitionModel"应 与目标人员组使用的识别模型"相同 或大型团体.

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.

因此,您似乎在此处不匹配.您不必在Identify操作中传递识别模型,而在首先执行的Detect操作中传递.

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.

并且您必须确保此值与您要用来标识此人的personGroup所使用的值相同(请参阅personGroup创建

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)

这篇关于APIErrorException:(BadArgument)'recognitionModel'不兼容:AZURE COGNITIVE FACE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆