facenet-pytorch icon indicating copy to clipboard operation
facenet-pytorch copied to clipboard

Extremely low fps in real time face recognition

Open brandonsin197 opened this issue 3 years ago • 1 comments

Hi, I am having an issue running the face recognition in real time as the frame drops to around 1 or 2 when running the algorithm comparing the embedding data to my dataset. I lowered the frame size to 360,360 and tried using my GPU cuda 0 but doesn't seem to help much. from what i can see when running it my gpu is hardly getting used only around a few percent usage but my cpu is up at around 70% usage with all cores being used. any advice would be great, thanks.

Specs: CPU: I7 7700 GPU: Rtx 3070

Code: device = 'cuda' if torch.cuda.is_available() else 'cpu' print('Running on device: {}'.format(device)) mtcnn = MTCNN(image_size=360, margin=14, min_face_size=20, device=device)
resnet = InceptionResnetV1(pretrained='vggface2').eval()

def face_match(img): # img_path= location of photo, data_path= location of data.pt

try:
    if img is not None:
        face, prob = mtcnn(img, return_prob=True)  # returns cropped face and probability
        emb = resnet(face.unsqueeze(0)).detach()  # detech is to make required gradient false

        # embedding_list = saved_data[0]  # getting embedding data
        # name_list = saved_data[1]  # getting list of names
        dist_list = []  # list of matched distances, minimum distance is used to identify the person

        for _, emb_db in enumerate(embedding_list):
            dist = torch.dist(emb, emb_db).item()
            dist_list.append(dist)

        idx_min = dist_list.index(min(dist_list))

        return name_list[idx_min], min(dist_list)
    else:
        return None
except:
    print("Error Missing Face")
    return None

brandonsin197 avatar Feb 16 '21 16:02 brandonsin197

Did you fix it? Why did you change the image_size parameter? It controls the size of the output face image and has nothing to do with the input size. Did you measure the time of each operation (profiling) to see which step is the most time-consuming one?

Sinuhe96 avatar Feb 18 '23 17:02 Sinuhe96