def __init__(self, method='mtcnn', cascPath=None):
     assert method in ['mtcnn', 'haar'], 'Method not supported'
     self.method = method
     if method == 'mtcnn':
         self.mtcnn = fn.MTCNN(select_largest=False,
                               device='cpu')
     if method == 'haar':
         assert cascPath is not None, 'Cascad not provided'
         self.faceCascade = cv2.CascadeClassifier(cascPath)
 def __init__(self, path, recache=False):
     self.resnet = fn.InceptionResnetV1(pretrained='vggface2').eval()
     self.mtcnn = fn.MTCNN(image_size=160,
                           margin=0,
                           min_face_size=20,
                           thresholds=[0.6, 0.7, 0.7],
                           factor=0.709,
                           post_process=True)
     cache_path = os.path.join(path, 'faces.db')
     if os.path.exists(cache_path) and not recache:
         print('Loading from: ', cache_path)
         with open(cache_path, 'rb') as f:
             self.matcher_db = pickle.load(f)
     else:
         print('Building Cache...')
         self.matcher_db = self.init_matcher_db(path)
Exemple #3
0
    def __init__(self, run_dir, n=12, device='cuda'):
        self.run_dir = run_dir
        with open(path.join(run_dir, 'infer.yml')) as f:
            self.config = yaml.safe_load(f)
        self.facedet = facenet_pytorch.MTCNN(device=device,
                                             **self.config['facedet_kwargs'])
        self.device = device
        self.n = n

        model_dir = max(glob.glob(path.join(run_dir, 'runs', '*')))
        config = path.join(model_dir, 'config.yaml')
        model_pth = max(glob.glob(path.join(model_dir, '_ckpt_epoch_*.ckpt')))
        model_config = util.read_config(config)
        self.model, self.normalize = model.get_model_normalize_from_config(
            model_config, pretrained=False)
        util.load_weights(self.model, model_pth)
        self.model = self.model.to(device)
        self.model.eval()
Exemple #4
0
def build_facenet_model(latent_space=512):
    mtcnn = fp.MTCNN(device=torch.device("cuda"))
    facenet = fp.InceptionResnetV1(pretrained='vggface2').eval()
    for p in facenet.parameters():
        p.requires_grad = False

    facenet = facenet.cuda()

    fc = nn.Sequential(*[
        #        nn.Linear(512, 512),
        #        nn.ReLU(),
        #        nn.Linear(512, 512),
        #        nn.ReLU(),
        #        nn.Linear(512, 512),
        #        nn.ReLU(),
        #        nn.Linear(512, 512),
        #        nn.ReLU(),
        nn.Linear(512, latent_space)
    ])

    fc.train()
    fc = fc.cuda()

    return mtcnn, facenet, fc
def runFacenet():
    mtcnn = fp.MTCNN()
    resnet = fp.InceptionResnetV1(pretrained='casia-webface').eval()

    return mtcnn, resnet
Exemple #6
0
There should be no delay as a result of getting the faces from the model.
Tested with OpenCV
"""

import torch
import joblib
# import numpy as np
import pandas as pd
from utils import features_training as ftrain

import facenet_pytorch as facenet
from torch.utils.data import DataLoader
from torchvision import datasets

net = facenet.InceptionResnetV1(pretrained='vggface2').eval()
mtcnn = facenet.MTCNN(image_size=260)
path = "data/train"


def collate_fn(x):
    return x[0]


def unpack_loader(loader, mtcnn, p=False):
    faces = []
    classes = []
    probs = []
    for x, y in loader:
        face, prob = mtcnn(x, return_prob=True)
        if p:
            print(