def __init__(self, in_channel=3, depth_multiples=0.33, width_multiples=0.50): super(YOLOv5Backbone, self).__init__() channel_64 = width_grow(64, width_multiples) channel_128 = width_grow(128, width_multiples) channel_256 = width_grow(256, width_multiples) channel_512 = width_grow(512, width_multiples) channel_1024 = width_grow(1024, width_multiples) self.out_channels = [channel_256, channel_512, channel_1024] self.stem = Focus(in_channel, channel_64, 3) self.layer1 = nn.Sequential( CBR(channel_64, channel_128, 3, 2), BottleNeckCSP(channel_128, channel_128, depth_grow(3, depth_multiples)) ) self.layer2 = nn.Sequential( CBR(channel_128, channel_256, 3, 2), BottleNeckCSP(channel_256, channel_256, depth_grow(9, depth_multiples)) ) self.layer3 = nn.Sequential( CBR(channel_256, channel_512, 3, 2), BottleNeckCSP(channel_512, channel_512, depth_grow(9, depth_multiples)) ) self.layer4 = nn.Sequential( CBR(channel_512, channel_1024, 3, 2), SPP(channel_1024, channel_1024, (5, 9, 13)), BottleNeckCSP(channel_1024, channel_1024, depth_grow(3, depth_multiples), shortcut=False) )
def __init__(self, **cfg): super(YOLOv4, self).__init__() self.cfg = {**default_cfg, **cfg} depth_multiples, width_multiples = model_scale(self.cfg['scale_name']) act_func = MemoryEfficientMish self.backbones = YOLOv4Backbone(self.cfg['in_channel'], depth_multiples, width_multiples, act=act_func) c2, c3, c4, c5 = self.backbones.out_channels self.neck = YOLOv4Neck(c2, c3, c4, c5, blocks=depth_grow(2, depth_multiples)) self.head = YOLOv4Head(c3, c4, c5, num_cls=self.cfg['num_cls'], strides=self.cfg['strides'], anchors=self.cfg['anchors']) self.loss = PedYOLOv5Loss(iou_weights=self.cfg['iou_weights'], obj_weights=self.cfg['obj_weights'], iou_ratio=self.cfg['iou_ratio'], iou_type=self.cfg['iou_type'])
def __init__(self, in_channel=3, depth_multiples=0.33, width_multiples=0.50, act=MemoryEfficientMish): super(YOLOv4Backbone, self).__init__() channel_32 = width_grow(32, width_multiples) channel_64 = width_grow(64, width_multiples) channel_128 = width_grow(128, width_multiples) channel_256 = width_grow(256, width_multiples) channel_512 = width_grow(512, width_multiples) channel_1024 = width_grow(1024, width_multiples) self.out_channels = [ channel_128, channel_256, channel_512, channel_1024 ] self.layer1 = nn.Sequential( CBR(in_channel, channel_32, 3, 1, act=act), CBR(channel_32, channel_64, 3, 2, act=act), BottleNeck(channel_64, channel_64, act=act)) self.layer2 = nn.Sequential( CBR(channel_64, channel_128, 3, 2, act=act), BottleNeckCSP(channel_128, channel_128, depth_grow(2, depth_multiples), act=act)) self.layer3 = nn.Sequential( CBR(channel_128, channel_256, 3, 2, act=act), BottleNeckCSP(channel_256, channel_256, depth_grow(8, depth_multiples), act=act)) self.layer4 = nn.Sequential( CBR(channel_256, channel_512, 3, 2, act=act), BottleNeckCSP(channel_512, channel_512, depth_grow(8, depth_multiples), act=act)) self.layer5 = nn.Sequential( CBR(channel_512, channel_1024, 3, 2, act=act), BottleNeckCSP(channel_1024, channel_1024, depth_grow(4, depth_multiples), act=act))
def __init__(self, **cfg): super(YOLOv5, self).__init__() self.cfg = {**default_cfg, **cfg} depth_multiples, width_multiples = model_scale(self.cfg['scale_name']) self.backbones = YOLOv5Backbone(self.cfg['in_channel'], depth_multiples, width_multiples) c3, c4, c5 = self.backbones.out_channels self.neck = YOLOv5Neck(c3, c4, c5, blocks=depth_grow(3, depth_multiples)) self.head = YOLOv5Head(c3, c4, c5, num_cls=self.cfg['num_cls'], strides=self.cfg['strides'], anchors=self.cfg['anchors']) self.loss = PedYOLOv5Loss()
def __init__(self, in_channel=3, depth_multiples=0.33, width_multiples=0.50, act=MemoryEfficientMish(), extra_len=3): super(YOLOV4BackBone, self).__init__() channel_32 = width_grow(32, width_multiples) channel_64 = width_grow(64, width_multiples) channel_128 = width_grow(128, width_multiples) channel_256 = width_grow(256, width_multiples) channel_512 = width_grow(512, width_multiples) channel_1024 = width_grow(1024, width_multiples) self.stem = nn.Sequential( CBR(in_channel, channel_32, 3, 1, act=act), CBR(channel_32, channel_64, 3, 2, act=act), BottleNeckCSP(channel_64, channel_64, depth_grow(1, depth_multiples), act=act), CBR(channel_64, channel_128, 3, 2, act=act), BottleNeckCSP(channel_128, channel_128, depth_grow(3, depth_multiples), act=act)) self.layer3 = nn.Sequential( CBR(channel_128, channel_256, 3, 2, act=act), BottleNeckCSP(channel_256, channel_256, depth_grow(15, depth_multiples), act=act)) self.layer4 = nn.Sequential( CBR(channel_256, channel_512, 3, 2, act=act), BottleNeckCSP(channel_512, channel_512, depth_grow(15, depth_multiples), act=act)) self.layer5 = nn.Sequential( CBR(channel_512, channel_1024, 3, 2, act=act), BottleNeckCSP(channel_1024, channel_1024, depth_grow(7, depth_multiples), act=act)) self.extra = list() for _ in range(extra_len - 3): self.extra.append( nn.Sequential( CBR(channel_1024, channel_1024, 3, 2, act=act), BottleNeckCSP(channel_1024, channel_1024, depth_grow(7, depth_multiples), act=act))) self.extra = None if len(self.extra) == 0 else nn.ModuleList( self.extra) self.output_channels = [channel_256, channel_512, channel_1024 ] + [channel_1024] * (extra_len - 3)
def __init__(self, **kwargs): super(YOLOV4, self).__init__() self.cfg = {**default_cfg, **kwargs} extra_len = len(self.cfg['strides']) assert extra_len >= 3 assert len(self.cfg['strides']) == len(self.cfg['anchors']) depth_multiples, width_multiples = model_scale(self.cfg['scale_name']) act = self.cfg['act'] self.backbones = YOLOV4BackBone(self.cfg['in_channel'], depth_multiples=depth_multiples, width_multiples=width_multiples, act=act, extra_len=extra_len) out_channels = self.backbones.output_channels self.neck = YOLOV4Neck(in_channels=out_channels, blocks=depth_grow(3, depth_multiples), k=self.cfg['k'], act=act) for m in self.modules(): t = type(m) if t is nn.Conv2d: pass # nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') elif t is nn.BatchNorm2d: m.eps = 1e-3 m.momentum = 0.03 elif t in [nn.LeakyReLU, nn.ReLU, nn.ReLU6]: m.inplace = True self.head = YOLOV4Head(in_channels=out_channels, num_cls=self.cfg['num_cls'], strides=self.cfg['strides'], anchors=self.cfg['anchors']) self.loss = YOLOv5Loss(ratio_thresh=self.cfg['ratio_thresh'], expansion_bias=self.cfg['expansion_bias'], layer_balance=self.cfg['balance'][extra_len], cls_pw=self.cfg['cls_pw'], obj_pw=self.cfg['obj_pw'], iou_type=self.cfg['iou_type'], coord_type=self.cfg['coord_type'], iou_ratio=self.cfg['iou_ratio'], iou_weights=self.cfg['iou_weights'], cls_weights=self.cfg['cls_weights'], obj_weights=self.cfg['obj_weights'])