retinaface
copied
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions
51 lines
1.6 KiB
51 lines
1.6 KiB
# 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
|
|
|
|
from towhee import register
|
|
from towhee.operator import Operator
|
|
from towhee.types.image_utils import to_pil
|
|
from towhee._types import Image
|
|
from towhee.types.arg import arg, to_image_color
|
|
|
|
|
|
@register(output_schema=['box', 'score'])
|
|
class Retinaface(Operator):
|
|
"""
|
|
Retinaface
|
|
"""
|
|
def __init__(self) -> 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, img: Image):
|
|
img = torch.FloatTensor(numpy.asarray(to_pil(img)))
|
|
bboxes, keypoints = self.model(img)
|
|
bboxes = bboxes.cpu().detach().numpy()
|
|
bl, sl = bboxes[:,:4].astype(int), bboxes[:,4]
|
|
rbboxes = [tuple(box) for box in bl]
|
|
return rbboxes, sl.tolist()
|
|
|