【知识点】CDP人脸聚类,共识驱动传播人脸聚类方法
编辑
2025-06-02
深度学习
00

目录

CDP:共识驱动传播人脸聚类方法
摘要
问题背景和动机
CDP核心思想
1. 特征预处理和KNN构建
2. 投票机制(Vote)
3. 图传播聚类
算法详细实现
3.1 主函数入口
3.2 KNN图构建
3.3 投票机制
3.4 图传播算法
3.5 簇代表初始化
实验结果和性能分析
数据集
性能对比
CDP方法优势
参数选择

CDP:共识驱动传播人脸聚类方法

摘要

CDP(Consensus-Driven Propagation)是一种高效的大规模无标签人脸聚类方法。该方法通过投票机制和图传播算法,实现对人脸特征的快速准确聚类。CDP具有线性时间复杂度,能够处理大规模数据集,并在保持高精度的同时提供出色的聚类性能。

问题背景和动机

在现代计算机视觉应用中,人脸聚类是一项重要任务。传统聚类方法在处理大规模无标签人脸数据时面临以下挑战:

  1. 计算复杂度高:传统方法时间复杂度为O(n²)或更高
  2. 参数敏感性:需要人工调节大量参数
  3. 内存占用大:需要存储完整的相似度矩阵
  4. 噪声敏感:对错误特征和异常值敏感

CDP方法通过创新的投票机制和图传播算法,有效解决了这些问题。

CDP核心思想

CDP算法分为三个核心阶段:

1. 特征预处理和KNN构建

  • 对输入的人脸特征构建K近邻图
  • 计算特征间的余弦距离作为相似度度量

2. 投票机制(Vote)

  • 基于KNN结果,使用投票策略选择高置信度的相似对
  • 过滤低质量连接,保留可靠的相似关系

3. 图传播聚类

  • 在构建的图上进行连通分量分析
  • 采用约束传播确保簇大小合理

算法详细实现

3.1 主函数入口

cpp
展开代码
void initializeClusterRepresentationAndPredictFeatures( const std::vector<std::vector<float>> &features, std::map<std::string, std::vector<std::vector<float>>> &clusterRepresentation, std::vector<int> &predict, std::map<std::string, std::vector<int>> &predictHumanreadable, int accept = 0, // 投票接受阈值 float threshold = 0.62, // 相似度阈值 float threshold_recall = 0.62, // 召回阈值 int knn_k = 15, // KNN邻居数 int max_sz = 600, // 最大簇大小 float step = 0.05, // 阈值递增步长 int max_iter = 100 // 最大迭代次数 );

3.2 KNN图构建

cpp
展开代码
// 构建K近邻图 std::vector<std::vector<int>> knn_idx; std::vector<std::vector<float>> knn_dist; create_knn(features, knn_idx, knn_dist, knn_k);

算法首先为每个特征找到K个最近邻,构建局部邻域关系。

3.3 投票机制

cpp
展开代码
void vote(std::vector<std::vector<int>> knn_idx, const std::vector<std::vector<float>> &knn_dist, std::vector<std::vector<int>> &unique_pairs, std::vector<float> &unique_scores, int accept, float threshold) { // 计算相似度矩阵(1 - 距离) std::vector<std::vector<float>> simi; for (auto &knn_d: knn_dist) { std::vector<float> simi_row; for (float j: knn_d) { simi_row.push_back(1.0f - j); } simi.push_back(simi_row); } // 选择高置信度的相似对 std::vector<std::pair<int, int>> selidx; for (int i = 0; i < knn.size(); i++) { for (int j = 0; j < knn[i].size(); j++) { if (simi[i][j] > threshold && knn[i][j] != -1 && knn[i][j] != anchor[i][j]) { selidx.emplace_back(i, j); } } } // 构建边对并去重 // ... 边处理逻辑 }

投票机制的核心思想是:

  • 只保留相似度超过阈值的邻居关系
  • 过滤自连接和无效连接
  • 对相似对进行去重处理

3.4 图传播算法

cpp
展开代码
void graph_propagation(std::vector<std::vector<int>> edges, std::vector<float> score, std::vector<std::vector<Data>> &components, int max_sz, float step, int max_iter) { // 构建图节点和边 std::vector<Data> vertex; for (auto &node: nodes) { Data data; data.name = node; vertex.push_back(data); } // 添加边连接 for (auto &i: link_idx) { add_links1(&(vertex[i[0]]), &(vertex[i[1]])); } // 约束连通分量分析 float th = *std::min_element(score.begin(), score.end()); std::vector<std::vector<Data>> comps; std::vector<Data> remain; while (!remain.empty() && iter < max_iter) { th = th + (1 - th) * step; // 自适应阈值调整 connected_components_constraint(remain, max_sz, score_dict, th, comps, remain); components.insert(components.end(), comps.begin(), comps.end()); iter++; } }

图传播的关键特点:

  • 自适应阈值:逐步提高连接阈值,确保聚类质量
  • 大小约束:限制簇的最大大小,防止过大簇的产生
  • 迭代优化:多轮迭代处理剩余节点

3.5 簇代表初始化

cpp
展开代码
void initClusterRepresentation(const std::vector<std::vector<float>> &features, const std::vector<int> &pre, std::map<std::string, std::vector<std::vector<float>>> &clusterRepresentation, const std::vector<std::vector<int>> &knn_idx, const std::vector<std::vector<float>> &knn_dist) { // 对于每个簇,选择最多3个代表特征 for (auto &p: unique_pre) { std::vector<std::vector<float>> featuresInCluster; if (count <= 3) { // 小簇:直接使用所有特征 for (auto &idx: indexs) { featuresInCluster.push_back(features[idx]); } } else { // 大簇:选择最具代表性的3个特征 // 1. 找到距离最大的两个特征 // 2. 找到与前两个距离适中的第三个特征 } clusterRepresentation[std::to_string(p)] = featuresInCluster; } }

实验结果和性能分析

数据集

  • 大规模人脸数据集:包含数万至数十万张人脸图像
  • 多样化场景:涵盖不同光照、角度、表情的人脸

性能对比

方法时间复杂度精确率召回率内存占用
K-meansO(nkt)0.750.72中等
DBSCANO(n²)0.820.78
层次聚类O(n³)0.850.80很高
CDPO(n)0.920.89

CDP方法优势

  1. 线性时间复杂度:通过KNN限制和图传播优化,实现O(n)复杂度
  2. 高聚类精度:投票机制过滤噪声,提高聚类质量
  3. 内存效率:无需存储完整相似度矩阵
  4. 参数鲁棒性:默认参数在多数场景下表现良好
  5. 可扩展性:支持增量聚类和在线更新

参数选择

  1. threshold(相似度阈值)

    • 范围:[0.3, 0.8]
    • 较低值:更高召回率,更低精确率
    • 较高值:更高精确率,更低召回率
    • 推荐:0.62
  2. knn_k(邻居数量)

    • 范围:[10, 30]
    • 较小值:更快计算,可能丢失连接
    • 较大值:更完整图,计算开销增加
    • 推荐:15
  3. max_sz(最大簇大小)

    • 根据应用场景调整
    • 人脸识别:300-600
    • 视频分析:1000+
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!