CoolFace
Modelpublic

convaiinnovations/convrec-face-recognition

sourceHugging Faceotherupdated 11mo agoView on Hugging Face
1likes
example.py59 linesDownload Raw Back to root
1"""2ConvRec Face Recognition - Quick Example3Shows how to use the model for face verification4"""5 6from face_recognition import FaceRecognition7 8# Initialize the ConvRec model9print("Loading ConvRec model...")10model = FaceRecognition('best_model.pth')11 12# Example 1: Verify if two faces are the same person13print("\n--- Face Verification Example ---")14# Replace with your image paths15image1 = 'data/img1.jpg'16image2 = 'data/img2.jpg'17 18try:19    result = model.verify_faces(image1, image2, threshold=0.5)20 21    if result['is_same']:22        print(f"✓ These are the SAME person")23    else:24        print(f"✗ These are DIFFERENT people")25 26    print(f"Similarity score: {result['similarity']:.3f}")27    print(f"Threshold used: {result['threshold']}")28 29except Exception as e:30    print(f"Please ensure you have images in the data folder")31    print(f"Error: {e}")32 33# Example 2: Build a gallery and search34print("\n--- Gallery Search Example ---")35try:36    # Build gallery from data folder37    print("Building face gallery from data folder...")38    gallery = model.build_gallery('data/', max_per_person=3)39 40    if gallery:41        # Search for a face42        query_image = 'data/img1.jpg'43        print(f"\nSearching for: {query_image}")44 45        matches = model.search_in_gallery(query_image, gallery, top_k=3)46 47        print("\nTop matches:")48        for i, (person, similarity) in enumerate(matches, 1):49            print(f"{i}. {person}: {similarity:.3f}")50    else:51        print("No gallery could be built. Add folders with images to data/")52 53except Exception as e:54    print(f"Error in gallery search: {e}")55 56print("\n--- ConvRec Model Ready ---")57print("Model successfully loaded and ready for face recognition tasks!")58print("For more examples, check the documentation at:")59print("https://huggingface.co/convaiinnovations/convrec-face-recognition")