Skip to content

Lazik00/face-verification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Match Service

Bu microservice backenddan user_id, 3 ta front rasm URLi va 1 ta back/reference rasm URLini oladi. Service rasmlardan yuz embedding chiqaradi, front rasmlarni back rasm bilan solishtiradi va natijani JSON qilib qaytaradi.

Service async ishlaydi: endpointlar async, rasm yuklash httpx.AsyncClient orqali non-blocking, 3 ta front rasm parallel tekshiriladi. InsightFace model inference CPU/GPU bloklovchi ish bo'lgani uchun event loopni to'smaslikka asyncio.to_thread() orqali alohida threadga chiqariladi.

Structure

app/
  api/
    routes/
      face_compare.py
      health.py
    router.py
  core/
    config.py
    model_dependencies.py
  schemas/
    face_compare.py
  services/
    face_analyzer.py
    face_matcher.py
    image_loader.py
  exceptions.py
  main.py
main.py
requirements.txt

main.py faqat compatibility entrypoint. Asosiy service app/ package ichida.

Run

.\venv\Scripts\python.exe -m pip install -r .\requirements.txt
.\venv\Scripts\python.exe -m uvicorn app.main:api --host 0.0.0.0 --port 8333

Windows + Python 3.12 da insightface build qilish uchun Microsoft C++ Build Tools so'rashi mumkin. Eng oson yo'l: Python 3.10 yoki 3.11 bilan yangi venv yaratish.

Docker

docker build -t face-verification-api .
docker run --rm --env-file .env face-verification-api

Asosiy docker-compose.yml ichiga alohida service sifatida qo'shish namunasi:

  face-verification:
    build:
      context: ./face-verification-api
      dockerfile: Dockerfile
    container_name: face_verification_api
    command: uvicorn app.main:api --host 0.0.0.0 --port 8333
    restart: unless-stopped
    volumes:
      - ./face-verification-api:/code
      - insightface_models:/root/.insightface
    expose:
      - "8333"
    env_file:
      - .env

Compose oxiridagi volumes qismiga model cache uchun buni ham qo'shing:

volumes:
  postgres_data:
  insightface_models:

Bu service DB, RabbitMQ yoki Redisga bevosita bog'liq emas. ports kerak emas, chunki tashqariga ochilmaydi. Asosiy backend Docker network ichida HTTP orqali foydalanadi: http://face-verification:8333/compare-faces.

Request

POST /compare-faces
Content-Type: application/json
{
  "user_id": "12345",
  "front_image1": "https://example.com/front1.jpg",
  "front_image2": "https://example.com/front2.jpg",
  "front_image3": "https://example.com/front3.jpg",
  "back_image": "https://example.com/back.jpg"
}

Optional sozlamalar:

{
  "threshold": 0.5,
  "min_matches": 2
}

threshold faqat 0..1 oralig'ida bo'lishi kerak. threshold: -1 yuborilsa, hamma rasm match bo'lib qolishi mumkinligi uchun API bunday qiymatni qabul qilmaydi.

Default holatda required_matches = 2: 3 ta front rasmdan kamida 2 tasi thresholddan yuqori chiqsa matched: true qaytadi. min_matches faqat 2 yoki 3 bo'lishi mumkin. Strict tekshiruv uchun min_matches: 3 yuboring.

Env orqali noto'g'ri qiymat berilsa, masalan FACE_MATCH_MIN_MATCHES=1 yoki FACE_MATCH_THRESHOLD=-1, service xavfsiz defaultga qaytadi: 2 va 0.50.

Response

{
  "user_id": "12345",
  "matched": true
}

Environment

INSIGHTFACE_MODEL=buffalo_l
DETECTION_SIZE=640
FACE_MATCH_THRESHOLD=0.50
FACE_MATCH_MIN_MATCHES=2
IMAGE_DOWNLOAD_TIMEOUT=15
MAX_IMAGE_BYTES=10485760

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors