diff --git a/python_examples/face_clustering.py b/python_examples/face_clustering.py index 9cfe2ca03..c5427cd4c 100755 --- a/python_examples/face_clustering.py +++ b/python_examples/face_clustering.py @@ -100,7 +100,7 @@ for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")): # middle value, such as 10, which is only 10x slower but still gets an # LFW accuracy of 99.3%. -labels = facerec.cluster(descriptors) +labels = facerec.cluster(descriptors, 0.5) label_classes = list(set(labels)) label_classes.sort() num_classes = len(label_classes) diff --git a/tools/python/src/face_recognition.cpp b/tools/python/src/face_recognition.cpp index 68d7ad34a..cf79a01f3 100644 --- a/tools/python/src/face_recognition.cpp +++ b/tools/python/src/face_recognition.cpp @@ -39,7 +39,7 @@ public: cropper->set_max_rotation_degrees(3); } - boost::python::list cluster(boost::python::list descriptors) + boost::python::list cluster(boost::python::list descriptors, float threshold) { boost::python::list clusters; @@ -61,7 +61,7 @@ public: matrix first_descriptor = boost::python::extract>(descriptors[i]); matrix second_descriptor = boost::python::extract>(descriptors[j]); - if (length(first_descriptor-second_descriptor) < 0.6) + if (length(first_descriptor-second_descriptor) < threshold) edges.push_back(sample_pair(i,j)); } } @@ -237,7 +237,7 @@ void bind_face_recognition() .def("save_image_chips", &face_recognition_model_v1::save_image_chips, (arg("img"),arg("faces"),arg("chip_filename")), "Takes an image and a full_object_detections object that reference faces in that image and saves the faces with the specified file name prefix" ) - .def("cluster", &face_recognition_model_v1::cluster, (arg("descriptors")), + .def("cluster", &face_recognition_model_v1::cluster, (arg("descriptors"), arg("threshold")), "Takes a list of descriptors and returns a list that contains a label for each descriptor. Clustering is done using chinese_whispers." ); }