Esempio n. 1
0
 def __init__(self):
     # Global parameters
     self.threshold = float(os.getenv('DET_THRESH', 0.6))
     self.max_size = parse_size(os.getenv('MAX_SIZE'))
     self.return_face_data = tobool(os.getenv('DEF_RETURN_FACE_DATA',
                                              False))
     self.extract_embedding = tobool(
         os.getenv('DEF_EXTRACT_EMBEDDING', True))
     self.extract_ga = tobool(os.getenv('DEF_EXTRACT_GA', False))
     self.api_ver = os.getenv('DEF_API_VER', "1")
Esempio n. 2
0
    def __init__(self):
        self.backend_name = os.getenv('INFERENCE_BACKEND', 'trt')
        self.device = os.getenv("DEVICE", 'cuda')
        self.rec_name = os.getenv("REC_NAME", "arcface_r100_v1")
        self.rec_batch_size = int(os.getenv('REC_BATCH_SIZE', 1))
        self.det_name = os.getenv("DET_NAME", "retinaface_mnet025_v2")
        self.ga_name = os.getenv("GA_NAME", "genderage_v1")
        self.fp16 = tobool(os.getenv('FORCE_FP16', False))
        self.ga_ignore = tobool(os.getenv('GA_IGNORE', False))
        self.rec_ignore = tobool(os.getenv('REC_IGNORE', False))

        if self.rec_ignore:
            self.rec_name = None
        if self.ga_ignore:
            self.ga_name = None
Esempio n. 3
0
def prepare_models(root_dir: str = '/models'):
    backend_name = os.getenv('INFERENCE_BACKEND', 'trt')
    rec_name = os.getenv("REC_NAME", "arcface_r100_v1")
    rec_batch_size = int(os.getenv("REC_BATCH_SIZE", 1))
    det_name = os.getenv("DET_NAME", "retinaface_mnet025_v2")
    ga_name = os.getenv("GA_NAME", "genderage_v1")

    force_fp16 = tobool(os.getenv('FORCE_FP16', True))  #False

    max_size = parse_size(os.getenv('MAX_SIZE'))

    if max_size is None:
        max_size = [640, 640]

    config = Configs(models_dir=root_dir)

    for model in [rec_name, det_name, ga_name]:
        batch_size = 1
        if model in [
                'arcface_r100_v1', 'r50-arcface-msfdrop75',
                'r100-arcface-msfdrop75', 'glint360k_r100FC_1.0',
                'glint360k_r100FC_0.1'
        ]:
            batch_size = rec_batch_size
        logging.info(f"Preparing '{model}' model...")

        prepare_backend(model_name=model,
                        backend_name=backend_name,
                        im_size=max_size,
                        force_fp16=force_fp16,
                        max_batch_size=batch_size,
                        config=config)
Esempio n. 4
0
 def __init__(self):
     self.backend_name = os.getenv('INFERENCE_BACKEND', 'onnx')
     self.device = os.getenv("DEVICE", 'cuda')
     self.det_name = os.getenv("DET_NAME", "scrfd_10g_gnkps")
     self.rec_name = toNone(os.getenv("REC_NAME", "glintr100"))
     self.ga_name = toNone(os.getenv("GA_NAME", None))
     self.mask_detector = toNone(os.getenv("MASK_DETECTOR", None))
     self.rec_batch_size = int(os.getenv('REC_BATCH_SIZE', 1))
     self.det_batch_size = int(os.getenv('DET_BATCH_SIZE', 1))
     self.fp16 = tobool(os.getenv('FORCE_FP16', False))
     self.triton_uri = os.getenv("TRITON_URI", None)
Esempio n. 5
0

__version__ = "0.5"

# TODO Refactor reading variables
dir_path = os.path.dirname(os.path.realpath(__file__))

port = os.environ.get('PORT', 18080)

device = os.environ.get("DEVICE", 'cuda')

rec_name = os.environ.get("REC_NAME", "arcface_r100_v1")
det_name = os.environ.get("DET_NAME", "retinaface_mnet025_v2")
ga_name = os.environ.get("GA_NAME", "genderage_v1")

ga_ignore = tobool(os.environ.get('GA_IGNORE', False))
rec_ignore = tobool(os.environ.get('REC_IGNORE', False))

if rec_ignore:
    rec_name = None
if ga_ignore:
    ga_name = None

# Global parameters
max_size = parse_size(os.environ.get('MAX_SIZE'))
return_face_data = tobool(os.environ.get('DEF_RETURN_FACE_DATA', False))
extract_embedding = tobool(os.environ.get('DEF_EXTRACT_EMBEDDING', True))
extract_ga = tobool(os.environ.get('DEF_EXTRACT_GA', False))
api_ver = os.environ.get('DEF_API_VER', "1")

import os
from typing import Dict
import time
import traceback
import logging
import base64
import numpy as np
import cv2
import httpx
from modules.utils.helpers import tobool

from turbojpeg import TurboJPEG

if tobool(os.getenv('USE_NVJPEG', False)):
    try:
        from nvjpeg import NvJpeg

        jpeg = NvJpeg()
        print('Using nvJPEG for JPEG decoding')
    except:
        print('Using TurboJPEG for JPEG decoding')
        jpeg = TurboJPEG()
else:
    jpeg = TurboJPEG()

headers = {
    'User-Agent':
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}

client = httpx.AsyncClient(headers=headers)