import torch
import torch.nn as nn
import torchvision.models.detection.backbone_utils as backbone_utils
import torchvision.models._utils as _utils
import torch.nn.functional as F
from collections import OrderedDict
from layers.functions.prior_box import PriorBox
from models.net import MobileNetV1 as MobileNetV1
from models.net import FPN as FPN
from models.net import SSH as SSH
import numpy as np
def decode_fixed(loc, priors):
import torch import torch.nn as nn import torchvision.models.detection.backbone_utils as backbone_utils import torchvision.models._utils as _utils import torch.nn.functional as F from collections import OrderedDict from layers.functions.prior_box import PriorBox from models.net import MobileNetV1 as MobileNetV1 from models.net import FPN as FPN from models.net import SSH as SSH import numpy as np def decode_fixed(loc, priors):
print("decode_fixed,,,,,,,,,,,,,,,,,,,,,,,,,,")
def decode_landm(pre, priors, variances):
print("decode landmarks: ", ">>>>>>>>>>>>>>>>>>.")
class ClassHead(nn.Module): def init(self,inchannels=512,num_anchors=3): super(ClassHead,self).init() self.num_anchors = num_anchors self.conv1x1 = nn.Conv2d(inchannels,self.num_anchors*2,kernel_size=(1,1),stride=1,padding=0)
class BboxHead(nn.Module): def init(self,inchannels=512,num_anchors=3): super(BboxHead,self).init() self.conv1x1 = nn.Conv2d(inchannels,num_anchors*4,kernel_size=(1,1),stride=1,padding=0)
class LandmarkHead(nn.Module): def init(self,inchannels=512,num_anchors=3): super(LandmarkHead,self).init() self.conv1x1 = nn.Conv2d(inchannels,num_anchors*10,kernel_size=(1,1),stride=1,padding=0)
class RetinaFace(nn.Module): def init(self, cfg = None, phase = 'train'): """ :param cfg: Network related settings. :param phase: train or test. """ super(RetinaFace,self).init() self.phase = phase backbone = None if cfg['name'] == 'mobilenet0.25': backbone = MobileNetV1() if cfg['pretrain']: checkpoint = torch.load("./weights/mobilenetV1X0.25_pretrain.tar", map_location=torch.device('cpu')) from collections import OrderedDict new_state_dict = OrderedDict() for k, v in checkpoint['state_dict'].items(): name = k[7:] # remove module. new_state_dict[name] = v
load params