MCPcopy Create free account
hub / github.com/davisking/dlib / bottom_up_clustering

Function bottom_up_clustering

tools/python/src/face_recognition.cpp:238–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236// ----------------------------------------------------------------------------------------
237
238py::list bottom_up_clustering(py::list descriptors, const int min_num_clusters, const double max_dist)
239{
240 DLIB_CASSERT(min_num_clusters > 0);
241
242 size_t num_descriptors = py::len(descriptors);
243 matrix<float> dist(static_cast<long>(num_descriptors), static_cast<long>(num_descriptors));
244
245 for (size_t i = 0; i < num_descriptors; ++i)
246 {
247 for (size_t j = i+1; j < num_descriptors; ++j)
248 {
249 const long i2 = static_cast<long>(i);
250 const long j2 = static_cast<long>(j);
251 matrix<double,0,1>& first_descriptor = descriptors[i].cast<matrix<double,0,1>&>();
252 matrix<double,0,1>& second_descriptor = descriptors[j].cast<matrix<double,0,1>&>();
253 dist(i2, j2) = dlib::length( first_descriptor- second_descriptor);
254 dist(j2, i2) = dist(i2, j2);
255 }
256 }
257
258 std::vector<unsigned long> labels;
259 const auto num_clusters = dlib::bottom_up_cluster(dist, labels, min_num_clusters, max_dist);
260
261 py::list clusters;
262 for (size_t i = 0; i < labels.size(); ++i)
263 {
264 clusters.append(labels[i]);
265 }
266 return clusters;
267}
268
269py::list chinese_whispers_clustering(py::list descriptors, float threshold)
270{

Callers

nothing calls this directly

Calls 6

lenFunction · 0.85
distFunction · 0.85
bottom_up_clusterFunction · 0.85
lengthFunction · 0.50
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected