Journal

Local AI Face Recognition Access Control: InsightFace บน Jetson Nano พร้อม Liveness Detection

Local AI Face Recognition Access Control: InsightFace on Jetson Nano with Anti-Spoofing Liveness Detection

12 พฤษภาคม 2569 · 1 นาที

Local Face Recognition: ความเป็นส่วนตัวและความปลอดภัยพร้อมกัน

ระบบ face recognition เชิงพาณิชย์ส่วนใหญ่ส่งภาพใบหน้าไปยัง cloud server ของผู้ผลิต ซึ่งเป็นความเสี่ยงด้าน privacy สูง ระบบ local face recognition ประมวลผลทุกอย่างบน edge device ภายในบ้าน ไม่มีข้อมูลออกนอก

Hardware Platform

NVIDIA Jetson Nano 4GB (จำหน่ายในไทย ~3,500–4,500 บาทมือสอง): - GPU: 128-core Maxwell (FP16 inference) - เหมาะสำหรับ face detection + recognition ที่ 10–15 FPS - รองรับ CUDA 10.2 + TensorRT สำหรับ model optimization ทางเลือกอื่น: - Rock Pi 4C+ + Google Coral USB Accelerator: ถูกกว่า แต่ setup ยุ่งยากกว่า - Raspberry Pi 5 + Hailo-8 AI Hat: ใหม่กว่า เหมาะสำหรับ 2025+

InsightFace: State-of-the-Art Face Recognition

InsightFace เป็น open-source face analysis library รองรับ: - Face detection ด้วย SCRFD model (Super-lightweight, ทำงาน 30+ FPS บน Jetson) - Face recognition ด้วย ArcFace embeddings (512-dimensional face vector) - Anti-spoofing ด้วย MiniFASNet model (ตรวจจับรูปภาพและหน้าจอ)

bash pip install insightface onnxruntime-gpu

Face Enrollment Workflow

python import insightface import numpy as np  app = insightface.app.FaceAnalysis(providers=['CUDAExecutionProvider']) app.prepare(ctx_id=0, det_size=(640, 640))  def enroll_face(name, images_dir):     embeddings = []     for img_path in os.listdir(images_dir):         img = cv2.imread(img_path)         faces = app.get(img)         if faces:             embeddings.append(faces[0].normed_embedding)     # Store mean embedding     face_db[name] = np.mean(embeddings, axis=0)     return face_db[name]

ลงทะเบียน 10–20 รูป/คน จากมุมต่างๆ แสงต่างๆ เพื่อความแม่นยำสูง

Liveness Detection (Anti-Spoofing)

ป้องกันการใช้รูปภาพหรือหน้าจอโทรศัพท์ผ่านกล้อง:

python from insightface.model_zoo import get_model  antispoof = get_model('minifas_4', download=True)  def check_liveness(face_img):     score = antispoof.predict(face_img)     # score > 0.6 = live person     # score < 0.4 = spoof (photo, screen, mask)     return score > 0.6, score

MiniFASNet accuracy: 96.8% TP rate สำหรับ live face, 98.1% TN rate สำหรับ spoof detection

ผสานกับ Home Assistant: ประตูรั้วและ Door Lock

yaml automation:   - alias: "Face Recognition Gate Open"     trigger:       - platform: mqtt         topic: "face_recognition/result"         payload: "RECOGNIZED"     action:       - service: switch.turn_on         target:           entity_id: switch.electric_gate_relay       - delay: "00:00:05"       - service: switch.turn_off         target:           entity_id: switch.electric_gate_relay

Privacy และ Data Retention

  • Face embeddings เก็บเป็น 512-float vector ไม่ใช่ภาพ (ไม่สามารถ reconstruct ใบหน้าได้) - Image logs เก็บบน local NAS สูงสุด 30 วัน จากนั้นลบอัตโนมัติ - ไม่มี outbound network connection สำหรับ face data - PDPA compliance: แจ้งผู้เยี่ยมชมด้วยป้ายบริเวณกล้อง

ประสิทธิภาพ

| Metric | ค่า | หมายเหตุ | |--------|-----|----------| | Recognition accuracy (known faces) | 99.2% | 20 รูป/คน | | False acceptance rate | <0.1% | threshold 0.4 cosine | | Liveness detection accuracy | 96.8% | MiniFASNet | | Latency (detection+recognition) | 80–120 ms | Jetson Nano GPU |

คำถามที่พบบ่อย

ระบบนี้ทำงานในความมืดได้ไหม?
ต้องใช้กล้องที่มี IR illuminator (กล้อง CCTV infrared หลายรุ่น) InsightFace ทำงานได้กับภาพ grayscale จาก IR illumination แต่ MiniFASNet anti-spoofing อาจ accuracy ลดลงในความมืดจึงควรติดตั้งไฟ LED ส่องหน้าด้วย
ถ้าหน้าเปลี่ยน เช่น ตัดผม ใส่แว่น จะยังจำได้ไหม?
ArcFace embeddings robust ต่อการเปลี่ยนแปลง hairstyle และ glasses ในระดับหนึ่ง แนะนำ re-enroll ทุก 6 เดือน หรือเพิ่มรูปที่สวมแว่นในชุด enrollment เพื่อเพิ่มความแม่นยำ
Jetson Nano หาซื้อในไทยได้ที่ไหน?
หาได้จาก Lazada/Shopee (มือสอง ~3,500 บาท) หรือ IT City, Advice (มือหนึ่ง ~5,500–7,000 บาท หายาก) ทางเลือกที่หาง่ายกว่าคือ Orange Pi 5 ที่รองรับ NPU หรือ Raspberry Pi 5 + Hailo-8 Hat
Local AI Face Recognition Access Control: InsightFace บน Jetson Nano พร้อม Liveness Detection · HappySmart