2025-11-08 01:02:14 +09:00
|
|
|
# UniFace Quick Start Guide
|
|
|
|
|
|
|
|
|
|
Get up and running with UniFace in 5 minutes! This guide covers the most common use cases.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
```bash
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
# macOS (Apple Silicon) - automatically includes ARM64 optimizations
|
|
|
|
|
pip install uniface
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
# Linux/Windows with NVIDIA GPU
|
|
|
|
|
pip install uniface[gpu]
|
|
|
|
|
|
|
|
|
|
# CPU-only (all platforms)
|
|
|
|
|
pip install uniface
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 1. Face Detection (30 seconds)
|
|
|
|
|
|
|
|
|
|
Detect faces in an image:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from uniface import RetinaFace
|
|
|
|
|
|
|
|
|
|
# Load image
|
|
|
|
|
image = cv2.imread("photo.jpg")
|
|
|
|
|
|
|
|
|
|
# Initialize detector (models auto-download on first use)
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
|
|
|
|
|
# Detect faces
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
|
|
|
|
|
# Print results
|
|
|
|
|
for i, face in enumerate(faces):
|
|
|
|
|
print(f"Face {i+1}:")
|
|
|
|
|
print(f" Confidence: {face['confidence']:.2f}")
|
|
|
|
|
print(f" BBox: {face['bbox']}")
|
|
|
|
|
print(f" Landmarks: {len(face['landmarks'])} points")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Output:**
|
2025-11-30 20:32:07 +09:00
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
```
|
|
|
|
|
Face 1:
|
|
|
|
|
Confidence: 0.99
|
|
|
|
|
BBox: [120.5, 85.3, 245.8, 210.6]
|
|
|
|
|
Landmarks: 5 points
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 2. Visualize Detections (1 minute)
|
|
|
|
|
|
|
|
|
|
Draw bounding boxes and landmarks:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from uniface import RetinaFace
|
|
|
|
|
from uniface.visualization import draw_detections
|
|
|
|
|
|
|
|
|
|
# Detect faces
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
image = cv2.imread("photo.jpg")
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
|
|
|
|
|
# Extract visualization data
|
|
|
|
|
bboxes = [f['bbox'] for f in faces]
|
|
|
|
|
scores = [f['confidence'] for f in faces]
|
|
|
|
|
landmarks = [f['landmarks'] for f in faces]
|
|
|
|
|
|
|
|
|
|
# Draw on image
|
2025-12-07 19:51:08 +09:00
|
|
|
draw_detections(
|
|
|
|
|
image=image,
|
|
|
|
|
bboxes=bboxes,
|
|
|
|
|
scores=scores,
|
|
|
|
|
landmarks=landmarks,
|
|
|
|
|
vis_threshold=0.6,
|
|
|
|
|
)
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
# Save result
|
|
|
|
|
cv2.imwrite("output.jpg", image)
|
|
|
|
|
print("Saved output.jpg")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 3. Face Recognition (2 minutes)
|
|
|
|
|
|
|
|
|
|
Compare two faces:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
import numpy as np
|
|
|
|
|
from uniface import RetinaFace, ArcFace
|
|
|
|
|
|
|
|
|
|
# Initialize models
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
recognizer = ArcFace()
|
|
|
|
|
|
|
|
|
|
# Load two images
|
|
|
|
|
image1 = cv2.imread("person1.jpg")
|
|
|
|
|
image2 = cv2.imread("person2.jpg")
|
|
|
|
|
|
|
|
|
|
# Detect faces
|
|
|
|
|
faces1 = detector.detect(image1)
|
|
|
|
|
faces2 = detector.detect(image2)
|
|
|
|
|
|
|
|
|
|
if faces1 and faces2:
|
|
|
|
|
# Extract embeddings
|
|
|
|
|
emb1 = recognizer.get_normalized_embedding(image1, faces1[0]['landmarks'])
|
|
|
|
|
emb2 = recognizer.get_normalized_embedding(image2, faces2[0]['landmarks'])
|
|
|
|
|
|
|
|
|
|
# Compute similarity (cosine similarity)
|
|
|
|
|
similarity = np.dot(emb1, emb2.T)[0][0]
|
|
|
|
|
|
|
|
|
|
# Interpret result
|
|
|
|
|
if similarity > 0.6:
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
print(f"Same person (similarity: {similarity:.3f})")
|
2025-11-08 01:02:14 +09:00
|
|
|
else:
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
print(f"Different people (similarity: {similarity:.3f})")
|
2025-11-08 01:02:14 +09:00
|
|
|
else:
|
|
|
|
|
print("No faces detected")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Similarity thresholds:**
|
2025-11-30 20:32:07 +09:00
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
- `> 0.6`: Same person (high confidence)
|
|
|
|
|
- `0.4 - 0.6`: Uncertain (manual review)
|
|
|
|
|
- `< 0.4`: Different people
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 4. Webcam Demo (2 minutes)
|
|
|
|
|
|
|
|
|
|
Real-time face detection:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from uniface import RetinaFace
|
|
|
|
|
from uniface.visualization import draw_detections
|
|
|
|
|
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
cap = cv2.VideoCapture(0)
|
|
|
|
|
|
|
|
|
|
print("Press 'q' to quit")
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
if not ret:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
# Detect faces
|
|
|
|
|
faces = detector.detect(frame)
|
|
|
|
|
|
|
|
|
|
# Draw results
|
|
|
|
|
bboxes = [f['bbox'] for f in faces]
|
|
|
|
|
scores = [f['confidence'] for f in faces]
|
|
|
|
|
landmarks = [f['landmarks'] for f in faces]
|
2025-12-07 19:51:08 +09:00
|
|
|
draw_detections(
|
|
|
|
|
image=frame,
|
|
|
|
|
bboxes=bboxes,
|
|
|
|
|
scores=scores,
|
|
|
|
|
landmarks=landmarks,
|
|
|
|
|
)
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
# Show frame
|
|
|
|
|
cv2.imshow("UniFace - Press 'q' to quit", frame)
|
|
|
|
|
|
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
cap.release()
|
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 5. Age & Gender Detection (2 minutes)
|
|
|
|
|
|
|
|
|
|
Detect age and gender:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from uniface import RetinaFace, AgeGender
|
|
|
|
|
|
|
|
|
|
# Initialize models
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
age_gender = AgeGender()
|
|
|
|
|
|
|
|
|
|
# Load image
|
|
|
|
|
image = cv2.imread("photo.jpg")
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
|
|
|
|
|
# Predict attributes
|
|
|
|
|
for i, face in enumerate(faces):
|
2025-12-10 00:18:11 +09:00
|
|
|
gender, age = age_gender.predict(image, face['bbox'])
|
|
|
|
|
gender_str = 'Female' if gender == 0 else 'Male'
|
|
|
|
|
print(f"Face {i+1}: {gender_str}, {age} years old")
|
2025-11-08 01:02:14 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Output:**
|
2025-11-30 20:32:07 +09:00
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
```
|
|
|
|
|
Face 1: Male, 32 years old
|
|
|
|
|
Face 2: Female, 28 years old
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 6. Facial Landmarks (2 minutes)
|
|
|
|
|
|
|
|
|
|
Detect 106 facial landmarks:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from uniface import RetinaFace, Landmark106
|
|
|
|
|
|
|
|
|
|
# Initialize models
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
landmarker = Landmark106()
|
|
|
|
|
|
|
|
|
|
# Detect face and landmarks
|
|
|
|
|
image = cv2.imread("photo.jpg")
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
|
|
|
|
|
if faces:
|
|
|
|
|
landmarks = landmarker.get_landmarks(image, faces[0]['bbox'])
|
|
|
|
|
print(f"Detected {len(landmarks)} landmarks")
|
|
|
|
|
|
|
|
|
|
# Draw landmarks
|
|
|
|
|
for x, y in landmarks.astype(int):
|
|
|
|
|
cv2.circle(image, (x, y), 2, (0, 255, 0), -1)
|
|
|
|
|
|
|
|
|
|
cv2.imwrite("landmarks.jpg", image)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2025-12-14 14:07:46 +09:00
|
|
|
## 7. Gaze Estimation (2 minutes)
|
|
|
|
|
|
|
|
|
|
Estimate where a person is looking:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
import numpy as np
|
|
|
|
|
from uniface import RetinaFace, MobileGaze
|
|
|
|
|
from uniface.visualization import draw_gaze
|
|
|
|
|
|
|
|
|
|
# Initialize models
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
gaze_estimator = MobileGaze()
|
|
|
|
|
|
|
|
|
|
# Load image
|
|
|
|
|
image = cv2.imread("photo.jpg")
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
|
|
|
|
|
# Estimate gaze for each face
|
|
|
|
|
for i, face in enumerate(faces):
|
|
|
|
|
bbox = face['bbox']
|
|
|
|
|
x1, y1, x2, y2 = map(int, bbox[:4])
|
|
|
|
|
face_crop = image[y1:y2, x1:x2]
|
|
|
|
|
|
|
|
|
|
if face_crop.size > 0:
|
|
|
|
|
pitch, yaw = gaze_estimator.estimate(face_crop)
|
|
|
|
|
print(f"Face {i+1}: pitch={np.degrees(pitch):.1f}°, yaw={np.degrees(yaw):.1f}°")
|
|
|
|
|
|
|
|
|
|
# Draw gaze direction
|
|
|
|
|
draw_gaze(image, bbox, pitch, yaw)
|
|
|
|
|
|
|
|
|
|
cv2.imwrite("gaze_output.jpg", image)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Output:**
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Face 1: pitch=5.2°, yaw=-12.3°
|
|
|
|
|
Face 2: pitch=-8.1°, yaw=15.7°
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2025-12-14 21:13:53 +09:00
|
|
|
## 8. Face Parsing (2 minutes)
|
|
|
|
|
|
|
|
|
|
Segment face into semantic components (skin, eyes, nose, mouth, hair, etc.):
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
import numpy as np
|
|
|
|
|
from uniface.parsing import BiSeNet
|
|
|
|
|
from uniface.visualization import vis_parsing_maps
|
|
|
|
|
|
|
|
|
|
# Initialize parser
|
|
|
|
|
parser = BiSeNet() # Uses ResNet18 by default
|
|
|
|
|
|
|
|
|
|
# Load face image (already cropped)
|
|
|
|
|
face_image = cv2.imread("face.jpg")
|
|
|
|
|
|
|
|
|
|
# Parse face into 19 components
|
|
|
|
|
mask = parser.parse(face_image)
|
|
|
|
|
|
|
|
|
|
# Visualize with overlay
|
|
|
|
|
face_rgb = cv2.cvtColor(face_image, cv2.COLOR_BGR2RGB)
|
|
|
|
|
vis_result = vis_parsing_maps(face_rgb, mask, save_image=False)
|
|
|
|
|
|
|
|
|
|
# Convert back to BGR for saving
|
|
|
|
|
vis_bgr = cv2.cvtColor(vis_result, cv2.COLOR_RGB2BGR)
|
|
|
|
|
cv2.imwrite("parsed_face.jpg", vis_bgr)
|
|
|
|
|
|
|
|
|
|
print(f"Detected {len(np.unique(mask))} facial components")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Output:**
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Detected 12 facial components
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**19 Facial Component Classes:**
|
|
|
|
|
- Background, Skin, Eyebrows (L/R), Eyes (L/R), Eye Glasses
|
|
|
|
|
- Ears (L/R), Ear Ring, Nose, Mouth, Lips (Upper/Lower)
|
|
|
|
|
- Neck, Neck Lace, Cloth, Hair, Hat
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2025-12-20 20:57:42 +09:00
|
|
|
## 9. Face Anonymization (2 minutes)
|
|
|
|
|
|
|
|
|
|
Automatically blur faces for privacy protection:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from uniface.privacy import anonymize_faces
|
|
|
|
|
import cv2
|
|
|
|
|
|
|
|
|
|
# One-liner: automatic detection and blurring
|
|
|
|
|
image = cv2.imread("group_photo.jpg")
|
|
|
|
|
anonymized = anonymize_faces(image, method='pixelate')
|
|
|
|
|
cv2.imwrite("anonymized.jpg", anonymized)
|
|
|
|
|
print("Faces anonymized successfully!")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Manual control with custom parameters:**
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from uniface import RetinaFace
|
|
|
|
|
from uniface.privacy import BlurFace
|
|
|
|
|
|
|
|
|
|
# Initialize detector and blurrer
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
blurrer = BlurFace(method='gaussian', blur_strength=5.0)
|
|
|
|
|
|
|
|
|
|
# Detect and anonymize
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
anonymized = blurrer.anonymize(image, faces)
|
|
|
|
|
cv2.imwrite("output.jpg", anonymized)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Available blur methods:**
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
# Pixelation (news media standard)
|
|
|
|
|
blurrer = BlurFace(method='pixelate', pixel_blocks=8)
|
|
|
|
|
|
|
|
|
|
# Gaussian blur (smooth, natural)
|
|
|
|
|
blurrer = BlurFace(method='gaussian', blur_strength=4.0)
|
|
|
|
|
|
|
|
|
|
# Black boxes (maximum privacy)
|
|
|
|
|
blurrer = BlurFace(method='blackout', color=(0, 0, 0))
|
|
|
|
|
|
|
|
|
|
# Elliptical blur (natural face shape)
|
|
|
|
|
blurrer = BlurFace(method='elliptical', blur_strength=3.0, margin=30)
|
|
|
|
|
|
|
|
|
|
# Median blur (edge-preserving)
|
|
|
|
|
blurrer = BlurFace(method='median', blur_strength=3.0)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Webcam anonymization:**
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from uniface import RetinaFace
|
|
|
|
|
from uniface.privacy import BlurFace
|
|
|
|
|
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
blurrer = BlurFace(method='pixelate')
|
|
|
|
|
cap = cv2.VideoCapture(0)
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
if not ret:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
faces = detector.detect(frame)
|
|
|
|
|
frame = blurrer.anonymize(frame, faces, inplace=True)
|
|
|
|
|
|
|
|
|
|
cv2.imshow('Anonymized', frame)
|
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
cap.release()
|
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
|
```
|
|
|
|
|
|
2025-12-20 21:27:26 +09:00
|
|
|
**Command-line tool:**
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Anonymize image with pixelation
|
|
|
|
|
python scripts/run_anonymization.py --image photo.jpg
|
|
|
|
|
|
|
|
|
|
# Real-time webcam anonymization
|
|
|
|
|
python scripts/run_anonymization.py --webcam --method gaussian
|
|
|
|
|
|
|
|
|
|
# Custom blur strength
|
|
|
|
|
python scripts/run_anonymization.py --image photo.jpg --method gaussian --blur-strength 5.0
|
|
|
|
|
```
|
|
|
|
|
|
2025-12-20 20:57:42 +09:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 10. Batch Processing (3 minutes)
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
Process multiple images:
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import cv2
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from uniface import RetinaFace
|
|
|
|
|
|
|
|
|
|
detector = RetinaFace()
|
|
|
|
|
|
|
|
|
|
# Process all images in a folder
|
|
|
|
|
image_dir = Path("images/")
|
|
|
|
|
output_dir = Path("output/")
|
|
|
|
|
output_dir.mkdir(exist_ok=True)
|
|
|
|
|
|
|
|
|
|
for image_path in image_dir.glob("*.jpg"):
|
|
|
|
|
print(f"Processing {image_path.name}...")
|
|
|
|
|
|
|
|
|
|
image = cv2.imread(str(image_path))
|
|
|
|
|
faces = detector.detect(image)
|
|
|
|
|
|
|
|
|
|
print(f" Found {len(faces)} face(s)")
|
|
|
|
|
|
|
|
|
|
# Save results
|
|
|
|
|
output_path = output_dir / image_path.name
|
|
|
|
|
# ... draw and save ...
|
|
|
|
|
|
|
|
|
|
print("Done!")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2025-12-20 20:57:42 +09:00
|
|
|
## 11. Model Selection
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
Choose the right model for your use case:
|
|
|
|
|
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
### Detection Models
|
|
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
```python
|
2025-12-03 23:35:56 +09:00
|
|
|
from uniface.detection import RetinaFace, SCRFD, YOLOv5Face
|
|
|
|
|
from uniface.constants import RetinaFaceWeights, SCRFDWeights, YOLOv5FaceWeights
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
# Fast detection (mobile/edge devices)
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
detector = RetinaFace(
|
2025-11-08 01:02:14 +09:00
|
|
|
model_name=RetinaFaceWeights.MNET_025,
|
|
|
|
|
conf_thresh=0.7
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Balanced (recommended)
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
detector = RetinaFace(
|
2025-11-08 01:02:14 +09:00
|
|
|
model_name=RetinaFaceWeights.MNET_V2
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-03 23:35:56 +09:00
|
|
|
# Real-time with high accuracy
|
|
|
|
|
detector = YOLOv5Face(
|
|
|
|
|
model_name=YOLOv5FaceWeights.YOLOV5S,
|
|
|
|
|
conf_thresh=0.6,
|
|
|
|
|
nms_thresh=0.5
|
|
|
|
|
)
|
|
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
# High accuracy (server/GPU)
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
detector = SCRFD(
|
2025-11-08 01:02:14 +09:00
|
|
|
model_name=SCRFDWeights.SCRFD_10G_KPS,
|
|
|
|
|
conf_thresh=0.5
|
|
|
|
|
)
|
|
|
|
|
```
|
|
|
|
|
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
### Recognition Models
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from uniface import ArcFace, MobileFace, SphereFace
|
|
|
|
|
from uniface.constants import MobileFaceWeights, SphereFaceWeights
|
|
|
|
|
|
|
|
|
|
# ArcFace (recommended for most use cases)
|
|
|
|
|
recognizer = ArcFace() # Best accuracy
|
|
|
|
|
|
|
|
|
|
# MobileFace (lightweight for mobile/edge)
|
|
|
|
|
recognizer = MobileFace(model_name=MobileFaceWeights.MNET_V2) # Fast, small size
|
|
|
|
|
|
|
|
|
|
# SphereFace (angular margin approach)
|
|
|
|
|
recognizer = SphereFace(model_name=SphereFaceWeights.SPHERE20) # Alternative method
|
|
|
|
|
```
|
|
|
|
|
|
2025-12-14 14:07:46 +09:00
|
|
|
### Gaze Estimation Models
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from uniface import MobileGaze
|
|
|
|
|
from uniface.constants import GazeWeights
|
|
|
|
|
|
|
|
|
|
# Default (recommended)
|
|
|
|
|
gaze_estimator = MobileGaze() # Uses RESNET34
|
|
|
|
|
|
|
|
|
|
# Lightweight (mobile/edge devices)
|
|
|
|
|
gaze_estimator = MobileGaze(model_name=GazeWeights.MOBILEONE_S0)
|
|
|
|
|
|
|
|
|
|
# High accuracy
|
|
|
|
|
gaze_estimator = MobileGaze(model_name=GazeWeights.RESNET50)
|
|
|
|
|
```
|
|
|
|
|
|
2025-12-14 21:13:53 +09:00
|
|
|
### Face Parsing Models
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from uniface.parsing import BiSeNet
|
|
|
|
|
from uniface.constants import ParsingWeights
|
|
|
|
|
|
|
|
|
|
# Default (recommended, 50.7 MB)
|
|
|
|
|
parser = BiSeNet() # Uses RESNET18
|
|
|
|
|
|
|
|
|
|
# Higher accuracy (89.2 MB)
|
|
|
|
|
parser = BiSeNet(model_name=ParsingWeights.RESNET34)
|
|
|
|
|
```
|
|
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Common Issues
|
|
|
|
|
|
|
|
|
|
### 1. Models Not Downloading
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
# Manually download a model
|
|
|
|
|
from uniface.model_store import verify_model_weights
|
|
|
|
|
from uniface.constants import RetinaFaceWeights
|
|
|
|
|
|
|
|
|
|
model_path = verify_model_weights(RetinaFaceWeights.MNET_V2)
|
|
|
|
|
print(f"Model downloaded to: {model_path}")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2. Check Hardware Acceleration
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import onnxruntime as ort
|
|
|
|
|
print("Available providers:", ort.get_available_providers())
|
|
|
|
|
|
|
|
|
|
# macOS M-series should show: ['CoreMLExecutionProvider', ...]
|
|
|
|
|
# NVIDIA GPU should show: ['CUDAExecutionProvider', ...]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3. Slow Performance on Mac
|
|
|
|
|
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
The standard installation includes ARM64 optimizations for Apple Silicon. If performance is slow, verify you're using the ARM64 build of Python:
|
2025-11-08 01:02:14 +09:00
|
|
|
|
|
|
|
|
```bash
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
python -c "import platform; print(platform.machine())"
|
|
|
|
|
# Should show: arm64 (not x86_64)
|
2025-11-08 01:02:14 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 4. Import Errors
|
|
|
|
|
|
|
|
|
|
```python
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
# Correct imports
|
|
|
|
|
from uniface.detection import RetinaFace
|
|
|
|
|
from uniface.recognition import ArcFace
|
|
|
|
|
from uniface.landmark import Landmark106
|
2025-11-08 01:02:14 +09:00
|
|
|
|
ref: Add comprehensive test suite and enhance model functionality
- Add new test files for age_gender, factory, landmark, recognition, scrfd, and utils
- Add new scripts for age_gender, landmarks, and video detection
- Update documentation in README.md, MODELS.md, QUICKSTART.md
- Improve model constants and face utilities
- Update detection models (retinaface, scrfd) with enhanced functionality
- Update project configuration in pyproject.toml
2025-11-15 21:09:37 +09:00
|
|
|
# Wrong imports
|
2025-11-08 01:02:14 +09:00
|
|
|
from uniface import retinaface # Module, not class
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Next Steps
|
|
|
|
|
|
2025-12-07 19:51:08 +09:00
|
|
|
### Jupyter Notebook Examples
|
|
|
|
|
|
|
|
|
|
Explore interactive examples for common tasks:
|
|
|
|
|
|
|
|
|
|
| Example | Description | Notebook |
|
|
|
|
|
|---------|-------------|----------|
|
|
|
|
|
| **Face Detection** | Detect faces and facial landmarks | [face_detection.ipynb](examples/face_detection.ipynb) |
|
|
|
|
|
| **Face Alignment** | Align and crop faces for recognition | [face_alignment.ipynb](examples/face_alignment.ipynb) |
|
|
|
|
|
| **Face Recognition** | Extract face embeddings and compare faces | [face_analyzer.ipynb](examples/face_analyzer.ipynb) |
|
|
|
|
|
| **Face Verification** | Compare two faces to verify identity | [face_verification.ipynb](examples/face_verification.ipynb) |
|
|
|
|
|
| **Face Search** | Find a person in a group photo | [face_search.ipynb](examples/face_search.ipynb) |
|
2025-12-14 21:13:53 +09:00
|
|
|
| **Face Parsing** | Segment face into semantic components | [face_parsing.ipynb](examples/face_parsing.ipynb) |
|
2025-12-20 21:27:26 +09:00
|
|
|
| **Face Anonymization** | Blur or pixelate faces for privacy protection | [face_anonymization.ipynb](examples/face_anonymization.ipynb) |
|
2025-12-14 21:13:53 +09:00
|
|
|
| **Gaze Estimation** | Estimate gaze direction | [gaze_estimation.ipynb](examples/gaze_estimation.ipynb) |
|
2025-12-07 19:51:08 +09:00
|
|
|
|
|
|
|
|
### Additional Resources
|
|
|
|
|
|
2025-11-08 01:02:14 +09:00
|
|
|
- **Model Benchmarks**: See [MODELS.md](MODELS.md) for performance comparisons
|
|
|
|
|
- **Full Documentation**: Read [README.md](README.md) for complete API reference
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
- **RetinaFace Training**: [yakhyo/retinaface-pytorch](https://github.com/yakhyo/retinaface-pytorch)
|
2025-12-03 23:35:56 +09:00
|
|
|
- **YOLOv5-Face ONNX**: [yakhyo/yolov5-face-onnx-inference](https://github.com/yakhyo/yolov5-face-onnx-inference)
|
2025-11-08 01:02:14 +09:00
|
|
|
- **Face Recognition Training**: [yakhyo/face-recognition](https://github.com/yakhyo/face-recognition)
|
2025-12-14 14:07:46 +09:00
|
|
|
- **Gaze Estimation Training**: [yakhyo/gaze-estimation](https://github.com/yakhyo/gaze-estimation)
|
2025-12-14 21:13:53 +09:00
|
|
|
- **Face Parsing Training**: [yakhyo/face-parsing](https://github.com/yakhyo/face-parsing)
|
2025-11-08 01:02:14 +09:00
|
|
|
- **InsightFace**: [deepinsight/insightface](https://github.com/deepinsight/insightface)
|