File size: 1,853 Bytes
aba2c79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
ConvRec Face Recognition - Quick Example
Shows how to use the model for face verification
"""

from face_recognition import FaceRecognition

# Initialize the ConvRec model
print("Loading ConvRec model...")
model = FaceRecognition('best_model.pth')

# Example 1: Verify if two faces are the same person
print("\n--- Face Verification Example ---")
# Replace with your image paths
image1 = 'data/img1.jpg'
image2 = 'data/img2.jpg'

try:
    result = model.verify_faces(image1, image2, threshold=0.5)

    if result['is_same']:
        print(f"✓ These are the SAME person")
    else:
        print(f"✗ These are DIFFERENT people")

    print(f"Similarity score: {result['similarity']:.3f}")
    print(f"Threshold used: {result['threshold']}")

except Exception as e:
    print(f"Please ensure you have images in the data folder")
    print(f"Error: {e}")

# Example 2: Build a gallery and search
print("\n--- Gallery Search Example ---")
try:
    # Build gallery from data folder
    print("Building face gallery from data folder...")
    gallery = model.build_gallery('data/', max_per_person=3)

    if gallery:
        # Search for a face
        query_image = 'data/img1.jpg'
        print(f"\nSearching for: {query_image}")

        matches = model.search_in_gallery(query_image, gallery, top_k=3)

        print("\nTop matches:")
        for i, (person, similarity) in enumerate(matches, 1):
            print(f"{i}. {person}: {similarity:.3f}")
    else:
        print("No gallery could be built. Add folders with images to data/")

except Exception as e:
    print(f"Error in gallery search: {e}")

print("\n--- ConvRec Model Ready ---")
print("Model successfully loaded and ready for face recognition tasks!")
print("For more examples, check the documentation at:")
print("https://huggingface.co/convaiinnovations/convrec-face-recognition")