Views
No views yet
transformers custom model. All four published variants live in this single repository as subfolders and are accessible through the standard AutoModel / AutoImageProcessor API with built-in MediaPipe face alignment.edgenext (timm) backbone with a 512-d embedding head trained for face recognition. Two variants additionally apply a static low-rank factorization to their linear layers — EdgeFace's "gamma" trick, baked into the pretrained weights and unrelated to PEFT adapters.| Subfolder | Backbone | Low-rank ratio | Params | |
|---|---|---|---|---|
edgeface-base | edgenext_base | — | ~18 M | default |
edgeface-s-gamma-05 | edgenext_small | 0.5 | ~5 M | |
edgeface-xs-gamma-06 | edgenext_x_small | 0.6 | ~3 M | |
edgeface-xxs | edgenext_xx_small | — | ~1 M |
1pip install transformers timm torch safetensors huggingface_hub numpy
2
3# Face alignment (do_align=True) also requires:
4pip install mediapipe opencv-python1from transformers import pipeline
2
3pipe = pipeline("image-feature-extraction", model="anjith2006/edgeface", trust_remote_code=True)1import torch
2import torch.nn.functional as F
3from PIL import Image
4from transformers import AutoModel, AutoImageProcessor
5
6repo = "anjith2006/edgeface"
7variant = "edgeface-xxs" # or edgeface-base / edgeface-s-gamma-05 / edgeface-xs-gamma-06
8
9model = AutoModel.from_pretrained(repo, subfolder=variant, trust_remote_code=True).eval()
10processor = AutoImageProcessor.from_pretrained(repo, subfolder=variant, trust_remote_code=True)
11
12@torch.no_grad()
13def embed(path):
14 img = Image.open(path).convert("RGB")
15 inputs = processor(img, return_tensors="pt") # do_align=True by default
16 return F.normalize(model(**inputs).embeddings, dim=-1)
17
18score = F.cosine_similarity(embed("a.jpg"), embed("b.jpg")).item()
19print(f"{score:.4f}") # → ~0.9+ same person, lower for different1# Full image → detect face, align, normalize (default)
2inputs = processor(img, return_tensors="pt")
3
4# Pre-aligned 112×112 crop → skip detection, just normalize
5inputs = processor(crop, do_align=False, return_tensors="pt")
6
7# Known landmarks → skip detection, align from provided 5 points
8inputs = processor(img, landmarks=pts, return_tensors="pt") # pts: ndarray (5, 2)1# "auto" (default): try the Tasks API, fall back to legacy solutions.face_mesh
2# "tasks": force the modern API — downloads face_landmarker.task once to ~/.cache/edgeface/
3# "solutions": force the legacy API (older mediapipe installs)
4processor = AutoImageProcessor.from_pretrained(
5 repo, subfolder=variant, trust_remote_code=True, mp_backend="tasks"
6)
7
8# Offline / custom bundle:
9processor = AutoImageProcessor.from_pretrained(
10 repo, subfolder=variant, trust_remote_code=True,
11 mp_model_path="/path/to/face_landmarker.task"
12)
13# or: export EDGEFACE_MP_MODEL=/path/to/face_landmarker.task1imgs = [Image.open(p).convert("RGB") for p in paths]
2inputs = processor(imgs, return_tensors="pt")
3with torch.no_grad():
4 embs = F.normalize(model(**inputs).embeddings, dim=-1) # (N, 512)trust_remote_code1from edgeface import register_edgeface
2register_edgeface() # wires EdgeFace into AutoConfig / AutoModel / AutoImageProcessor
3
4model = AutoModel.from_pretrained("anjith2006/edgeface", subfolder="edgeface-xxs").eval()
5processor = AutoImageProcessor.from_pretrained("anjith2006/edgeface", subfolder="edgeface-xxs")nn.Linear modules, so PEFT targets them without any naming collision:1from peft import LoraConfig, get_peft_model
2
3model = AutoModel.from_pretrained(repo, subfolder=variant, trust_remote_code=True)
4
5# Gamma variants (edgeface-s-gamma-05, edgeface-xs-gamma-06):
6lora_cfg = LoraConfig(r=8, lora_alpha=16, target_modules=["linear1", "linear2"])
7
8# Base / XXS variants (no factorized layers — target the backbone linears directly):
9# print([n for n, _ in model.named_modules() if isinstance(_, torch.nn.Linear)])
10lora_cfg = LoraConfig(r=8, lora_alpha=16, target_modules=["fc1", "fc2"])
11
12model = get_peft_model(model, lora_cfg)
13model.print_trainable_parameters()| File | Purpose |
|---|---|
configuration_edgeface.py | EdgeFaceConfig |
modeling_edgeface.py | EdgeFaceModel, LowRankLinear, EdgeFaceOutput |
image_processing_edgeface.py | EdgeFaceImageProcessor (MediaPipe alignment + normalize) |
convert_edgeface.py | Download original .pt checkpoints, convert, push |
example.py | Same-person / different-person sanity check |
NOTICE for details. Verify compliance before commercial use or redistribution.1@article{george2024edgeface,
2 title = {EdgeFace: Efficient Face Recognition Model for Edge Devices},
3 author = {George, Anjith and Ecabert, Christophe and Otroshi Shahreza, Hatef
4 and Kotwal, Ketan and Marcel, Sebastien},
5 journal = {IEEE Transactions on Biometrics, Behavior, and Identity Science},
6 year = {2024},
7 doi = {10.1109/TBIOM.2024.3352169}
8}