## github 1. https://github.com/deepinsight/insightface 2. https://github.com/serengil/deepface 3. https://github.com/layumi/Person_reID_baseline_pytorch #### DeepFace * 支持的模型 1. **VGG-Face**:基於 VGG 架構的模型,提供了較高的識別準確性。 2. Google FaceNet:由 Google 開發的模型,用於生成高質量的面部嵌入向量。 3. OpenFace:基於 OpenFace 項目的模型,旨在提供高效和準確的人臉識別。 4. Facebook DeepFace:由 Facebook 開發的模型,是最早的人臉識別深度學習模型之一。 5. DeepID:由中國科學院開發的模型,用於高精度的人臉識別。 6. ArcFace:采用 ArcFace 損失函數的模型,提高了人臉識別的準確性。 7. Dlib:基於 Dlib 庫的模型,提供了高效的人臉檢測和識別功能。 8. SFace:另一個高性能的人臉識別模型,提供了良好的識別效果。 9. Facenet512:基於 FaceNet 的512維度模型,提供了高維度的面部特征嵌入。 10. GhostFaceNet:輕量級的高效人臉識別模型,適用於資源有限的場景。 * 支持的檢測後端 1. OpenCV:基於 Haar Cascades 或 DNN 模塊的檢測方法。 2. SSD:使用單階段檢測器(Single Shot MultiBox Detector)進行人臉檢測。 3. Dlib:使用 Dlib 庫中的人臉檢測器。 4. MTCNN:多任務卷積神經網絡(MTCNN)用於高效的人臉檢測和關鍵點定位。 5. RetinaFace:高精度的人臉檢測器,基於 RetinaNet 框架。 6. MediaPipe:由 Google 提供的跨平台機器學習框架,提供了高效的人臉檢測功能。 7. YOLOv8:最新版本的 YOLO(You Only Look Once)檢測器,提供了高效的實時檢測性能。 8. YUNet:用於人臉檢測的輕量級模型。 9. CenterFace:一種基於中心關鍵點檢測的人臉檢測方法。 * 人臉檢測算法 1. Haar Cascades:Haar Cascades 是一種基於機器學習的對象檢測算法,常用於人臉檢測。它是 OpenCV 中提供的一種經典方法。 2. MTCNN(Multi-task Cascaded Convolutional Networks):MTCNN 是一種深度學習模型,專門用於高效和準確的人臉檢測,支持人臉對齊和關鍵點檢測。 3. RetinaFace:RetinaFace 是一種基於 RetinaNet 的人臉檢測算法,具有高精度和高效能的特點。 * 核心功能 1. 人臉檢測:檢測圖像中的人臉,並返回人臉的位置和尺寸。 ``` result = DeepFace.verify( img1_path = "img1.jpg", img2_path = "img2.jpg",) ``` 2. 人臉識别:識别人脸,并返回匹配的身份信息。 ``` dfs = DeepFace.find( img_path = "img1.jpg", db_path = "C:/workspace/my_db",) ``` 3. 屬性分析:分析人臉的屬性,如年齡、性别、種族和表情。 ``` objs = DeepFace.analyze( img_path = "img4.jpg", actions = ['age', 'gender', 'race', 'emotion'],) ``` 4. 臉部驗証:驗証兩張人臉是否屬于同一个人。 ``` dfs = DeepFace.find( img_path = "img1.jpg", img2_path = "img2.jpg",) ``` 5. 表示提取:提取人臉的嵌入向量,用于比較和識别。 ``` embedding_objs = DeepFace.represent( img_path = "img.jpg") ``` * Deepface.find 各參數對臉部準確度影響表格 (官方建議準確度 > 97.5 ,較適合用於人臉辨識) **各參數預設值**: ``` model_name = "VGG-Face" detector_backend = "opencv" distance_metric = "cosine" align = True ``` ![image](https://hackmd.io/_uploads/rJ-ZfEhMkl.png) 參考: https://github.com/serengil/deepface/tree/master/benchmarks * DeepFace.find 人臉辨識預設距離門檻值 DeepFace.find 如果沒有設定 threshold 參數,會自動根據所選 model ,產生一個預設距離門檻值,如果輸入的人臉和資料庫所有人臉比對,距離都高於此門檻(表示資料庫查無此人臉),結果會回傳一個空的 DataFrame,以下為各 model 對應的門檻值: ``` python= base_threshold = {"cosine": 0.40, "euclidean": 0.55, "euclidean_l2": 0.75} thresholds = { "VGG-Face": { "cosine": 0.68, "euclidean": 1.17, "euclidean_l2": 1.17, }, "Facenet": {"cosine": 0.40, "euclidean": 10, "euclidean_l2": 0.80}, "Facenet512": {"cosine": 0.30, "euclidean": 23.56, "euclidean_l2": 1.04}, "ArcFace": {"cosine": 0.68, "euclidean": 4.15, "euclidean_l2": 1.13}, "Dlib": {"cosine": 0.07, "euclidean": 0.6, "euclidean_l2": 0.4}, "SFace": {"cosine": 0.593, "euclidean": 10.734, "euclidean_l2": 1.055}, "OpenFace": {"cosine": 0.10, "euclidean": 0.55, "euclidean_l2": 0.55}, "DeepFace": {"cosine": 0.23, "euclidean": 64, "euclidean_l2": 0.64}, "DeepID": {"cosine": 0.015, "euclidean": 45, "euclidean_l2": 0.17}, "GhostFaceNet": {"cosine": 0.65, "euclidean": 35.71, "euclidean_l2": 1.10}, } ``` 舉例 ``` python3= """ 以下參數設定,預設門檻值為 0.3 """ result1 = DeepFace.find( input_face_image, db_path="your_face_db", enforce_detection=False, detector_backend = "ssd", model_name="Facenet512", distance_metric="cosine" ) if result1[0].empty == True: #資料庫找不到與 input_face_image 相似的人臉(找不到門檻 <= 0.3 的人臉) else: #資料庫找到與 input_face_image 相似的人臉 """ 以下參數設定,預設門檻值為 4.15 """ result2 = DeepFace.find( input_face_image, db_path="your_face_db", enforce_detection=False, detector_backend = "yolov8", model_name="ArcFace", distance_metric="euclidean" ) if result2[0].empty == True: #資料庫找不到與 input_face_image 相似的人臉(找不到門檻 <= 4.15 的人臉) else: #資料庫找到與 input_face_image 相似的人臉 ``` #### [ DeepFake](https://github.com/Ming-Lian/Machine-Learning-Course-in-UCAS/blob/master/deepfake-faceswap%E6%8D%A2%E8%84%B8%E5%A4%A7%E6%B3%95%EF%BC%9A%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B.md) 換臉 #### [Face Recognition](https://github.com/ageitgey/face_recognition) * 基於dlib * face_recognition/Script/activate 開啟安裝環境 * face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/ * --tolerance 預設容差值為 0.6,較低的數字使臉部比較更加嚴格 * --show-distance true 每個匹配計算的臉部距離以調整容差設置(可用於相似度比較 越接近0越像) * --cpus 4 加速 ![image](https://hackmd.io/_uploads/S1OGlZe8C.png) * 對資料庫臉部偵測不佳(以下角度無法偵測) | ![B15](https://hackmd.io/_uploads/HJTSRxxL0.jpg) | ![B21](https://hackmd.io/_uploads/HynLCxxIR.jpg) | ![B22](https://hackmd.io/_uploads/r1SPCxxLC.jpg) | ![B28](https://hackmd.io/_uploads/ryusAeeLC.jpg)| | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | --- | * 辨識效果不佳,會跳動 * 速度慢,每次都要從新計算 * 支援多人 --- * python face_recognition_cli.py --show-distance true./pictures_of_people_i_know/ ./unknown_pictures/ * https://github.com/ageitgey/face_recognition/blob/master/face_recognition/face_recognition_cli.py ## [ReID](https://github.com/layumi/Person_reID_baseline_pytorch) * cd D:\ReID\vision\apex * python train.py --name ft_ResNet50 --train_all --batchsize 32 --data_dir D:\ReID\vision\Market\pytorch * cpu跑不動 * 行人檢測(目標識別) --> 特征提取 --> 行人跟蹤(目標跟蹤)--> 跨鏡頭行人跟蹤 --> 向量存儲與檢索 * ![image](https://hackmd.io/_uploads/SkgnlLbIR.png) ## [ArcFace]() * [InsightFace](https://github.com/deepinsight/insightface): * 可偵測人臉 * ![t1_output](https://hackmd.io/_uploads/By4ZOjGIA.jpg) * 辨識疑似需要GPU訓練 * 有一對多換臉功能([in_swapper](https://github.com/deepinsight/insightface/tree/master/examples/in_swapper)) * L2-Norm 來計算之間的距離 * https://github.com/chingi071/Face_recognition (3) * tensorflow / retinaface版本不相容 * https://github.com/peteryuX/arcface-tf2 (5) * tensorflow 版本不相容 * https://github.com/yinguobing/arcface * 示範影片偵測人臉不佳 * https://www.bilibili.com/video/BV16T4y1P72j/ * https://blog.csdn.net/guyuealian/article/details/130600472 ### insight face swap * 單人換臉 * 多人換臉(注意順序) * 混和多人臉部後換臉(最多3個) * 可用於comfyui * https://www.youtube.com/watch?v=72xow6bNWSc * 有多種組合方式,可呈現人臉特徵 * FaceID Plus(Insightface+clipvision) * portrait https://github.com/xxrjun/face-recognition https://github.com/SthPhoenix/InsightFace-REST https://github.com/PaddlePaddle/FastDeploy/blob/develop/examples/vision/facedet/retinaface/python/README_CN.md