Quick fix for face rec (#16226)

* Check both

* Fix api order
This commit is contained in:
Nicolas Mowen 2025-01-29 17:02:40 -07:00 committed by Blake Blackshear
parent 9236898a9d
commit fb316874ef
2 changed files with 28 additions and 28 deletions

View File

@ -41,19 +41,36 @@ def get_faces():
return JSONResponse(status_code=200, content=face_dict)
@router.post("/faces/{name}")
async def register_face(request: Request, name: str, file: UploadFile):
@router.post("/faces/reprocess")
def reclassify_face(request: Request, body: dict = None):
if not request.app.frigate_config.face_recognition.enabled:
return JSONResponse(
status_code=400,
content={"message": "Face recognition is not enabled.", "success": False},
)
json: dict[str, any] = body or {}
training_file = os.path.join(
FACE_DIR, f"train/{sanitize_filename(json.get('training_file', ''))}"
)
if not training_file or not os.path.isfile(training_file):
return JSONResponse(
content=(
{
"success": False,
"message": f"Invalid filename or no file exists: {training_file}",
}
),
status_code=404,
)
context: EmbeddingsContext = request.app.embeddings
result = context.register_face(name, await file.read())
response = context.reprocess_face(training_file)
return JSONResponse(
status_code=200 if result.get("success", True) else 400,
content=result,
content=response,
status_code=200,
)
@ -100,36 +117,19 @@ def train_face(request: Request, name: str, body: dict = None):
)
@router.post("/faces/reprocess")
def reclassify_face(request: Request, name: str, body: dict = None):
@router.post("/faces/{name}")
async def register_face(request: Request, name: str, file: UploadFile):
if not request.app.frigate_config.face_recognition.enabled:
return JSONResponse(
status_code=400,
content={"message": "Face recognition is not enabled.", "success": False},
)
json: dict[str, any] = body or {}
training_file = os.path.join(
FACE_DIR, f"train/{sanitize_filename(json.get('training_file', ''))}"
)
if not training_file or not os.path.isfile(training_file):
return JSONResponse(
content=(
{
"success": False,
"message": f"Invalid filename or no file exists: {training_file}",
}
),
status_code=404,
)
context: EmbeddingsContext = request.app.embeddings
response = context.reprocess_face(training_file)
result = context.register_face(name, await file.read())
return JSONResponse(
content=response,
status_code=200,
status_code=200 if result.get("success", True) else 400,
content=result,
)

View File

@ -215,7 +215,7 @@ class FaceProcessor(RealTimeProcessorApi):
if not self.landmark_detector:
return None
if not self.recognizer:
if not self.label_map or not self.recognizer:
self.__build_classifier()
if not self.recognizer: