Skip to content

UniFace: A Unified Face Analysis Library for Python | Detection, alignment, landmarks, face-mesh, recognition, parsing, gaze, attributes and anti-spoofing under one API.

chore: Update docstrings and comments (#119)

Yakhyokhuja Valikhujaev7882ec5cb45f
diff --git a/uniface/detection/retinaface.py b/uniface/detection/retinaface.py
index e7616a4..a46763e 100644
--- a/uniface/detection/retinaface.py
+++ b/uniface/detection/retinaface.py
@@ -202,7 +202,7 @@ class RetinaFace(BaseDetector):
height, width, _ = image.shape
image_tensor = self.preprocess(image)
- # ONNXRuntime inference
+ # Inference
outputs = self.inference(image_tensor)
# Postprocessing
diff --git a/uniface/detection/scrfd.py b/uniface/detection/scrfd.py
index 9f781c1..f09c5d9 100644
--- a/uniface/detection/scrfd.py
+++ b/uniface/detection/scrfd.py
@@ -247,9 +247,10 @@ class SCRFD(BaseDetector):
image_tensor = self.preprocess(image)
- # ONNXRuntime inference
+ # Inference
outputs = self.inference(image_tensor)
+ # Postprocessing
scores_list, bboxes_list, kpss_list = self.postprocess(outputs, image_size=image.shape[:2])
# Handle case when no faces are detected
diff --git a/uniface/detection/yolov8.py b/uniface/detection/yolov8.py
index c674c48..31def87 100644
--- a/uniface/detection/yolov8.py
+++ b/uniface/detection/yolov8.py
@@ -2,13 +2,6 @@
# Author: Yakhyokhuja Valikhujaev
# GitHub: https://github.com/yakhyo
-"""
-YOLOv8-Face detector implementation.
-
-Uses anchor-free design with DFL (Distribution Focal Loss) for bbox regression.
-Reference: https://github.com/yakhyo/yolov8-face-onnx-inference
-"""
-
from typing import Any, Literal
import numpy as np
@@ -273,16 +266,14 @@ class YOLOv8Face(BaseDetector):
if len(keep) == 0:
return np.array([]), np.array([])
- # Limit to max_det
+ # Filter detections and limit to max_det
keep = keep[: self.max_det]
boxes = boxes[keep]
scores = scores[keep]
landmarks = landmarks[keep]
- # === SCALE TO ORIGINAL IMAGE COORDINATES ===
+ # Scale back to original image coordinates
pad_w, pad_h = padding
-
- # Scale boxes back to original image coordinates
boxes[:, [0, 2]] = (boxes[:, [0, 2]] - pad_w) / scale
boxes[:, [1, 3]] = (boxes[:, [1, 3]] - pad_h) / scale
@@ -297,7 +288,7 @@ class YOLOv8Face(BaseDetector):
# Reshape landmarks to (N, 5, 2)
landmarks = landmarks.reshape(-1, 5, 2)
- # Combine box and score
+ # Combine results
detections = np.concatenate([boxes, scores[:, None]], axis=1)
return detections, landmarks
diff --git a/uniface/gaze/models.py b/uniface/gaze/models.py
index eea5cc1..1f87147 100644
--- a/uniface/gaze/models.py
+++ b/uniface/gaze/models.py
@@ -179,6 +179,13 @@ class MobileGaze(BaseGazeEstimator):
This method orchestrates the full pipeline: preprocessing the input,
running inference, and postprocessing to return the gaze direction.
+
+ Args:
+ face_image (np.ndarray): A cropped face image in BGR format with shape (H, W, 3).
+
+ Returns:
+ GazeResult: Estimated gaze direction containing ``pitch`` (vertical) and
+ ``yaw`` (horizontal) angles in radians.
"""
input_tensor = self.preprocess(face_image)
outputs = self.session.run(self.output_names, {self.input_name: input_tensor})
diff --git a/uniface/headpose/models.py b/uniface/headpose/models.py
index 070287f..6352c8a 100644
--- a/uniface/headpose/models.py
+++ b/uniface/headpose/models.py
@@ -170,6 +170,13 @@ class HeadPose(BaseHeadPoseEstimator):
This method orchestrates the full pipeline: preprocessing the input,
running inference, and postprocessing to return the head orientation.
+
+ Args:
+ face_image (np.ndarray): A cropped face image in BGR format with shape (H, W, 3).
+
+ Returns:
+ HeadPoseResult: Estimated head orientation containing ``pitch`` (vertical),
+ ``yaw`` (horizontal), and ``roll`` (in-plane) angles in degrees.
"""
input_tensor = self.preprocess(face_image)
outputs = self.session.run(self.output_names, {self.input_name: input_tensor})