Exemplo n.º 1
0
 def __init__(self,
              p_model_path="fid/mtcnn/mtcnn_checkpoints/pnet_epoch.pt",
              r_model_path="fid/mtcnn/mtcnn_checkpoints/rnet_epoch.pt",
              o_model_path="fid/mtcnn/mtcnn_checkpoints/onet_epoch.pt",
              use_cuda=1,
              min_face_size=15):
     pnet, rnet, onet = create_mtcnn_net(p_model_path, r_model_path,
                                         o_model_path, use_cuda)
     self.detector = MtcnnDetector(pnet=pnet,
                                   rnet=rnet,
                                   onet=onet,
                                   min_face_size=min_face_size)
Exemplo n.º 2
0
def main(csv_path, img_path):
    pnet, rnet, onet = create_mtcnn_net(
        p_model_path="fid/mtcnn/mtcnn_checkpoints/pnet_epoch.pt",
        r_model_path="fid/mtcnn/mtcnn_checkpoints/rnet_epoch.pt",
        o_model_path="fid/mtcnn/mtcnn_checkpoints/onet_epoch.pt",
        use_cuda=True)
    mtcnn_detector = MtcnnDetector(pnet=pnet,
                                   rnet=rnet,
                                   onet=onet,
                                   min_face_size=24)
    mobileFace = mobile_face_model(
        "fid/InsightFace_Pytorch/facenet_checkpoints/model_ir_se50.pth")
    labels, old_features = get_data(csv_path)
    img = cv2.imread(img_path)
    print(get_names(mtcnn_detector, mobileFace, labels, old_features, img))
Exemplo n.º 3
0
def one_manImg(
    img_dir,
    csv_path,
    model_path="fid/InsightFace_Pytorch/facenet_checkpoints/model_ir_se50.pth"
):
    pnet, rnet, onet = create_mtcnn_net(
        p_model_path="fid/mtcnn/mtcnn_checkpoints/pnet_epoch.pt",
        r_model_path="fid/mtcnn/mtcnn_checkpoints/rnet_epoch.pt",
        o_model_path="fid/mtcnn/mtcnn_checkpoints/onet_epoch.pt",
        use_cuda=True)
    mtcnn_detector = MtcnnDetector(pnet=pnet,
                                   rnet=rnet,
                                   onet=onet,
                                   min_face_size=24)
    mobileFace = mobile_face_model(model_path)
    img_paths = os.listdir(img_dir)
    if not os.path.exists(csv_path):
        print('创建数据库')
        with open(csv_path, 'w', encoding='UTF-8') as file_csv:
            writer = csv.writer(file_csv)
            header = ['Features%d' % x for x in range(512)]
            header.insert(0, 'Name')
            writer.writerow(header)

    with open(csv_path, 'r', encoding='UTF-8') as file_csv:
        reader = csv.reader(file_csv)
        names = [row[0] for row in reader][1:]
    with open(csv_path, 'a+', encoding='UTF-8') as file_csv:
        writer = csv.writer(file_csv)
        for img_path in img_paths:
            label = os.path.splitext(img_path)[0]
            if label in names:
                print('%s的数据已存在,跳过' % label)
            else:
                img_path = os.path.join(img_dir, img_path)
                image = cv2.imread(img_path)
                faces, _ = detect_face(mtcnn_detector, image)
                if len(faces) == 1:
                    print('正在输入:', label)
                    # cv2.imshow('demo', faces[0])
                    # cv2.waitKey(0)
                    features = get_faceFeatures(mobileFace, faces[0])[0]
                    content = np.append(label, features)
                    writer.writerow(content)

                else:
                    print('%s图片不符合要求' % img_path)
Exemplo n.º 4
0
def make_model():
    yolo = yolo_model()
    reid = FeatureExtractor(
        model_name='osnet_x1_0',
        model_path=
        'pid/deep_person_reid/checkpoints/osnet_x1_0_market_256x128_amsgrad_ep150_stp60_lr0.0015_b64_fb10_softmax_labelsmooth_flip.pth',
        verbose=False)
    pnet, rnet, onet = create_mtcnn_net(
        p_model_path="fid/mtcnn/mtcnn_checkpoints/pnet_epoch.pt",
        r_model_path="fid/mtcnn/mtcnn_checkpoints/rnet_epoch.pt",
        o_model_path="fid/mtcnn/mtcnn_checkpoints/onet_epoch.pt",
        use_cuda=True)
    mtcnn_detector = MtcnnDetector(pnet=pnet,
                                   rnet=rnet,
                                   onet=onet,
                                   min_face_size=24)
    mobileFace = mobile_face_model(
        "fid/InsightFace_Pytorch/facenet_checkpoints/model_ir_se50.pth")
    return yolo, reid, mtcnn_detector, mobileFace
Exemplo n.º 5
0
    if use_cuda:
        images = images.cuda()
    normal_features = []
    with torch.no_grad():
        features = faceModel(images)
    for i in range(0, len(features), 2):
        normal_feature = (features[i] + features[i + 1])
        normal_features.append(l2_norm(normal_feature).cpu().detach().numpy())
    return normal_features


if __name__ == '__main__':

    pnet, rnet, onet = create_mtcnn_net(
        p_model_path="fid/mtcnn/mtcnn_checkpoints/pnet_epoch.pt",
        r_model_path="fid/mtcnn/mtcnn_checkpoints/rnet_epoch.pt",
        o_model_path="fid/mtcnn/mtcnn_checkpoints/onet_epoch.pt",
        use_cuda=True)
    mtcnn_detector = MtcnnDetector(pnet=pnet,
                                   rnet=rnet,
                                   onet=onet,
                                   min_face_size=24)
    faceModel = mobile_face_model()
    img = cv2.imread("/home/supermc/Pictures/IZTY.png")
    faces, _ = detect_face(mtcnn_detector, img)
    for id, face in enumerate(faces):
        image_path = os.path.join("data/face_with_name", chr(id + 65) + ".png")
        # cv2.imwrite(image_path, face)
        # cv2.imshow('demo', face)
        # cv2.waitKey(0)
    features = get_faceFeatures(faceModel, faces)