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

Function chinese_whispers_clustering

tools/python/src/face_recognition.cpp:269–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269py::list chinese_whispers_clustering(py::list descriptors, float threshold)
270{
271 DLIB_CASSERT(threshold > 0);
272 py::list clusters;
273
274 size_t num_descriptors = py::len(descriptors);
275
276 // This next bit of code creates a graph of connected objects and then uses the Chinese
277 // whispers graph clustering algorithm to identify how many objects there are and which
278 // objects belong to which cluster.
279 std::vector<sample_pair> edges;
280 std::vector<unsigned long> labels;
281 for (size_t i = 0; i < num_descriptors; ++i)
282 {
283 for (size_t j = i; j < num_descriptors; ++j)
284 {
285 matrix<double,0,1>& first_descriptor = descriptors[i].cast<matrix<double,0,1>&>();
286 matrix<double,0,1>& second_descriptor = descriptors[j].cast<matrix<double,0,1>&>();
287
288 if (length(first_descriptor-second_descriptor) < threshold)
289 edges.push_back(sample_pair(i,j));
290 }
291 }
292 chinese_whispers(edges, labels);
293 for (size_t i = 0; i < labels.size(); ++i)
294 {
295 clusters.append(labels[i]);
296 }
297 return clusters;
298}
299
300py::list chinese_whispers_raw(py::list edges)
301{

Callers

nothing calls this directly

Calls 7

lenFunction · 0.85
chinese_whispersFunction · 0.85
lengthFunction · 0.50
sample_pairClass · 0.50
push_backMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected