Retinaface代码参考:https://blog.csdn.net/weixin_44791964/article/details/106214657
Arcface代码参考:https://blog.csdn.net/ssunshining/article/details/109613807
更改Retinaface.py中的detect_image的返回值如下:
import cv2
import numpy as np
import colorsys
import os
import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
from PIL import Image,ImageFont, ImageDraw
from torch.autograd import Variable
from retinaface_pytorch.nets.retinaface import RetinaFace
from retinaface_pytorch.utils.config import cfg_mnet,cfg_re50
from retinaface_pytorch.utils.anchors import Anchors
from retinaface_pytorch.utils.box_utils import decode, decode_landm, non_max_suppression
def preprocess_input(image):
image -= np.array((104, 117, 123),np.float32)
return image
class Retinaface(object):
_defaults = {
"model_path": 'model_data/Retinaface_mobilenet0.25.pth',
"confidence": 0.5,
"backbone": "mobilenet",
"cuda": True
}
@classmethod
def get_defaults(cls, n):
if n in cls._defaults:
return cls._defaults[n]
else:
return "Unrecognized attribute name '" + n + "'"
#---------------------------------------------------#
# 初始化Retinaface
#---------------------------------------------------#
def __init__(self, **kwargs):
self.__dict__.update(self._defaults)
if self.backbone == "mobilenet":
self.cfg = cfg_mnet
else:
self.cfg = cfg_re50
self.generate()
#---------------------------------------------------#
# 获得所有的分类
#---------------------------------------------------#
def generate(self):
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
self.net = RetinaFace(cfg=self.cfg, phase='eval').eval()
# 加快模型训练的效率
print('Loading weights into state dict...')
state_dict = torch.load(self.model_path)
self.net.load_state_dict(state_dict)
if self.cuda:
self.net = nn.DataParallel(self.net)
self.net = self.net.cuda()
print('Finished!')

博客提供了Retinaface和Arcface的代码参考链接,分别为https://blog.csdn.net/weixin_44791964/article/details/106214657和https://blog.csdn.net/ssunshining/article/details/109613807,还提及要更改Retinaface.py中detect_image的返回值,涉及Retinaface与Arcface结合。

483

被折叠的 条评论
为什么被折叠?



