deepinsight / deepinsight/insightface
improve the speed of face recognition on CPU
- Dominant language
- Python
- Stars
- 29.7k
- Forks
- 6.1k
- PR merge metrics
- No merged PRs in 30d
Description
How I can increase the speed of below program I can use GPU in this time I want to increase speed on CPU. Any suggestion?
Why all the model loaded and how I can disable them?
# Import libraries
import torch
import insightface
import cv2
import numpy as np
# Load a face recognition model
model = insightface.app.FaceAnalysis()
model.prepare(ctx_id = -1) # use CPU and set NMS threshold
#model.prepare(ctx_id = 0)
# Load two images
img1 = cv2.imread(r"D:\20240127_120414.png")
img2 = cv2.imread(r"D:\code\IMG_20240205_140538.jpg")
faces1 = model.get(img1)
box = faces1[0]['bbox']
bbox = box.astype(int)
# x_min, y_min, x_max, y_max = int(box['left']), int(box['top']), int(box['right']), int(box['bottom'])
face_img = img1[bbox[1]:bbox[3], bbox[0]:bbox[2]]
print(face_img.shape)
cv2.imwrite("./test.png", face_img)
faces2 = model.get(img2)
# Extract face embeddings
embeddings1 = np.array([face.normed_embedding for face in faces1])
embeddings2 = np.array([face.normed_embedding for face in faces2])
# Compute cosine similarity between embeddings
similarity = np.dot(embeddings1, embeddings2.T)
**output**
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\windows/.insightface\models\buffalo_l\1k3d68.onnx landmark_3d_68 ['None', 3, 192, 192] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\windows/.insightface\models\buffalo_l\2d106det.onnx landmark_2d_106 ['None', 3, 192, 192] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\windows/.insightface\models\buffalo_l\det_10g.onnx detection [1, 3, '?', '?'] 127.5 128.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\windows/.insightface\models\buffalo_l\genderage.onnx genderage ['None', 3, 96, 96] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\windows/.insightface\models\buffalo_l\w600k_r50.onnx recognition ['None', 3, 112, 112] 127.5 127.5
set det-size: (640, 640)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.