# Copyright 2022 Zilliz. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import sys import os from typing import NamedTuple, List from PIL import Image import torch from torchvision import transforms from pathlib import Path import numpy import towhee from towhee.operator import Operator from towhee.types.image_utils import to_pil from towhee._types import Image from timm.data import resolve_data_config from timm.data.transforms_factory import create_transform @register(output_schema=['bboxes', 'scores']) class Retinaface(Operator): """ Retinaface """ def __init__(self, framework: str = 'pytorch') -> None: super().__init__() sys.path.append(str(Path(__file__).parent)) from retinaface_impl import Model self.model = Model() @arg(1, to_image_color('RGB') ) def __call__(self, image: 'towhee._types.Image'): img = torch.FloatTensor(numpy.asarray(to_pil(image))) bboxes, keypoints = self.model(img) return bboxes[:,:4], bboxes[:,4]