2

我可以使用 Python insightface 包和 onnx 预训练模型实时进行人脸识别。(https://github.com/deepinsight/insightface/tree/master/python-package)如果你能帮助我,我真的面临很多问题和挑战。我使用以下代码为 1000 个特征提取的人脸识别人脸:

import cv2
import sys
import time
import numpy as np
import insightface
from insightface.app import FaceAnalysis
from imutils import paths
import os
import pickle
from numpy as np
from numpy.linalg import norm


parser = argparse.ArgumentParser()
parser.add_argument('--ctx', default=0, type=int, help='GPU')
args = parser.parse_args()
app = FaceAnalysis(name='models')
app.prepare(ctx_id=args.ctx, det_size=(640, 640))

database = {}

def compare(feat1, feat2):

    distance = np.dot(feat2, feat1) / norm(feat2) * norm(feat1))

    return distance

verification_threshhold = 0.3
database = {}

data = pickle.loads(open('encodings.pickle', "rb").read())

encoding = np.empty(512, )
imagePaths = list(paths.list_images('dataset'))

for (i, imagePath) in enumerate(imagePaths):
       
       name = os.path.splitext(os.path.basename(imagePath))[0]
       image = cv2.imread(imagePath)

        t1 = time.time()
        encodings = app.get(frame)
        t2 = time.time()
        print('elapsed time for extract encodings: ',(t2-t1))

        ts = time.time()
        for num, e in enumerate(encodings):

            encoding = e.embedding

            identity = ''
            for (name, db_enc) in data.items():

                dist = compare(encoding, db_enc)

                if 0.35 < dist:
                    identity = name
        te = time.time()
        print('elapsed time for  compare face in 1000 data')

在这里,我使用不同的图像进行识别,每张图像都有不同数量的面孔。例如,一张图像有一张脸,另一张图像有 6 张脸,另一张有 15 张脸。在测试了不同的图像后,我想出了以下输出:

图片 1(1 人脸)>>> 提取编码所用时间:0.019 秒,在 1000 个数据中比较人脸所用时间:0.009 秒图片 2(6 人脸)>>> 提取编码所用时间:0.057 秒,所用时间比较 1000 个数据中的人脸:0.05 秒图片 2(15 个人脸)>>> 提取编码的经过时间:0.19 秒,比较 1000 个数据中的人脸经过的时间:0.22 秒

考虑到使用具有至少 20,000 个面部的多个摄像头进行实时检测以进行比较,这对我的目的根本没有用。我怎样才能减少这个时间?我在做正确的事吗?预先感谢您的回复

4

0 回答 0