人脸聚类方法Dlib

     Dlib为一个优秀的开源人脸识别库,里面有很多人脸检测、识别方法,其中有一项为人脸聚类方法,利用的算法为chinese_whispers_clustering方法,有兴趣的可以自己去搜索这个算法,这里只讲一下应用。

    接口为dlib.chinese_whispers_clustering(arg1,arg2)

    srg1为list,arg2为阈值,float

    这里有一个大坑,先前直接将人脸特征码列表和阈值输入,总是报错:dlib.chinese_whispers_clustering  unable to cast python instance to c++ type,找了各种办法无法解决,然后按照dlib给的example下载了对应的landmark模型和特征提取模型,最后才发现arg1中的值要为dlib.vector类型才能进来计算,因为算法是用C++实现的,这里要做类型转换。

  总结:如果人脸特征计算是用opencv、openface或者其它的方法,也可以用dlib的chinese_whisper_clustering接口,只要将类型转换一下即可,希望对像我一样入坑的盆友有帮助

       

Abstract—Clustering face images according to their latent identity has two important applications: (i) grouping a collection of face images when no external labels are associated with images, and (ii) indexing for efficient large scale face retrieval. The clustering problem is composed of two key parts: representation and similarity metric for face images, and choice of the partition algorithm. We first propose a representation based on ResNet, which has been shown to perform very well in image classification problems. Given this representation, we design a clustering algorithm, Conditional Pairwise Clustering (ConPaC), which directly estimates the adjacency matrix only based on the similarities between face images. This allows a dynamic selection of number of clusters and retains pairwise similarities between faces. ConPaC formulates the clustering problem as a Conditional Random Field (CRF) model and uses Loopy Belief Propagation to find an approximate solution for maximizing the posterior probability of the adjacency matrix. Experimental results on two benchmark face datasets (LFW and IJB-B) show that ConPaC outperforms well known clustering algorithms such as k-means, spectral clustering and approximate Rank-order. Additionally, our algorithm can naturally incorporate pairwise constraints to work in a semi-supervised way that leads to improved clustering performance. We also propose an k-NN variant of ConPaC, which has a linear time complexity given a k-NN graph, suitable for large datasets. Index Terms—face clustering, face representation, Conditional Random Fields, pairwise constraints, semi-supervised clustering.
### 关于在 Label Studio 中进行人脸聚类 #### 使用 Label Studio 进行人脸聚类概述 Label Studio 是一个多用途的数据标注平台,支持多种类型的媒体文件标注工作。尽管其主要功能集中在人工标注方面,但通过自定义配置和集成外部算法,可以扩展用于自动化处理任务,比如人脸聚类。 #### 配置环境与安装必要组件 为了实现在 Label Studio 上的人脸聚类操作,通常需要额外引入人脸识别库(如 OpenCV、dlib 或者 face_recognition),并编写相应的 Python 脚本来完成特征提取及相似度比较的工作[^1]。 ```python import os from facerecognition import FaceRecognitionModel # 假设这是一个封装好的人脸识别模块 def load_images_from_folder(folder): images = [] for filename in os.listdir(folder): img_path = os.path.join(folder,filename) if os.path.isfile(img_path): try: image = cv2.imread(img_path) images.append(image) except Exception as e: print(f"Error loading {img_path}: ", str(e)) return images # 加载图片集合 image_set = load_images_from_folder('path_to_your_image_directory') # 初始化人脸识别模型实例 face_model = FaceRecognitionModel() # 对每一张照片执行编码获取面部向量表示形式 encodings = [face_model.encode_face(img) for img in image_set] # 应用K-means或其他聚类算法来分组这些编码后的脸部数据点 clusters = KMeans(n_clusters=number_of_expected_groups).fit(encodings) ``` #### 创建自定义插件以增强功能 对于更高级的应用场景,可以通过开发专属的 Label Studio 插件来简化流程。这涉及到创建一个新的 ML 后端服务作为插件的一部分,并将其注册到 Label Studio 的设置里。该插件负责接收来自前端界面的选择项,调用人脸识别API或者本地部署的服务来进行实时聚类分析,最后返回结果给用户查看或进一步编辑确认[^2]。 #### YAML 文件中的路径配置 当涉及具体的项目实施细节时,例如指定待处理图像的位置或是保存最终输出的地方,则需按照官方文档指导调整 `config.yaml` 文件内的相应字段。确保所有相关资源都能被正确访问是非常重要的一步[^4]。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值