def __init__(self, device, input_size=None, num_classes=2, trainable=False, conf_thresh=0.05, nms_thresh=0.2, anchor_size=None, hr=False): super(YOLOv2slim, self).__init__() self.device = device self.input_size = input_size self.num_classes = num_classes self.trainable = trainable self.conf_thresh = conf_thresh self.nms_thresh = nms_thresh self.anchor_size = torch.tensor(anchor_size) self.anchor_number = len(anchor_size) self.stride = 32 self.grid_cell, self.all_anchor_wh = self.create_grid(input_size) self.scale = np.array([[[input_size[1], input_size[0], input_size[1], input_size[0]]]]) self.scale_torch = torch.tensor(self.scale.copy(), device=device).float() # backbone darknet-tiny self.backbone = darknet_tiny(pretrained=trainable, hr=hr) # detection head self.convsets_1 = nn.Sequential( SPP(), Conv2d(512*4, 256, 1, leakyReLU=True), Conv2d(256, 512, 3, 1, leakyReLU=True) ) self.route_layer = Conv2d(256, 32, 1, leakyReLU=True) self.reorg = reorg_layer(stride=2) self.convsets_2 = Conv2d(640, 512, 3, 1, leakyReLU=True) # prediction layer self.pred_ = nn.Conv2d(512, self.anchor_number*(1 + 4 + self.num_classes), 1)
def __init__(self, device, input_size=None, num_classes=20, trainable=False, conf_thresh=0.001, nms_thresh=0.5, anchor_size=None, hr=False): super(myYOLOv2, self).__init__() self.device = device self.input_size = input_size self.num_classes = num_classes self.trainable = trainable self.conf_thresh = conf_thresh self.nms_thresh = nms_thresh self.anchor_size = torch.tensor(anchor_size) self.anchor_number = len(anchor_size) self.stride = 32 self.grid_cell, self.all_anchor_wh = self.create_grid() self.scale = np.array( [[input_size[1], input_size[0], input_size[1], input_size[0]]]) self.scale_torch = torch.tensor(self.scale.copy(), device=device).float() # backbone darknet-19 self.backbone = darknet19(pretrained=trainable, hr=hr) # detection head self.convsets_1 = nn.Sequential( Conv2d(1024, 1024, 3, 1, leakyReLU=True), Conv2d(1024, 1024, 3, 1, leakyReLU=True)) # self.route_alyer = nn.Sequential( # Conv2d(512, 64, 1, leakyReLU=True), # Conv2d(64, 256, 3, padding=1, stride=2, leakyReLU=True) # ) self.route_layer = Conv2d(512, 64, 1, leakyReLU=True) self.reorg = reorg_layer(stride=2) self.convsets_2 = Conv2d(1280, 1024, 3, 1, leakyReLU=True) # prediction layer self.pred = nn.Conv2d(1024, self.anchor_number * (1 + 4 + self.num_classes), 1)
def __init__(self, device, input_size=None, num_classes=20, trainable=False, conf_thresh=0.001, nms_thresh=0.6, anchor_size=None): super(YOLOv2R50, self).__init__() self.device = device self.input_size = input_size self.num_classes = num_classes self.trainable = trainable self.conf_thresh = conf_thresh self.nms_thresh = nms_thresh self.anchor_size = torch.tensor(anchor_size) self.num_anchors = len(anchor_size) self.stride = 32 self.grid_cell, self.all_anchor_wh = self.create_grid(input_size) # 主干网络:resnet50 self.backbone = resnet50(pretrained=trainable) # 检测头 self.convsets_1 = nn.Sequential(Conv(2048, 1024, k=1), Conv(1024, 1024, k=3, p=1), Conv(1024, 1024, k=3, p=1)) # 融合高分辨率的特征信息 self.route_layer = Conv(1024, 128, k=1) self.reorg = reorg_layer(stride=2) # 检测头 self.convsets_2 = Conv(1024 + 128 * 4, 1024, k=3, p=1) # 预测曾 self.pred = nn.Conv2d(1024, self.num_anchors * (1 + 4 + self.num_classes), 1)
def __init__(self, device, input_size=None, num_classes=20, trainable=False, conf_thresh=0.001, nms_thresh=0.5, anchor_size=None, hr=False): super(YOLOv2D19, self).__init__() self.device = device self.input_size = input_size self.num_classes = num_classes self.trainable = trainable self.conf_thresh = conf_thresh self.nms_thresh = nms_thresh self.anchor_size = torch.tensor(anchor_size) self.num_anchors = len(anchor_size) self.stride = 32 self.grid_cell, self.all_anchor_wh = self.create_grid(input_size) # backbone darknet-19 self.backbone = darknet19(pretrained=trainable, hr=hr) # detection head self.convsets_1 = nn.Sequential(Conv(1024, 1024, k=3, p=1), Conv(1024, 1024, k=3, p=1)) self.route_layer = Conv(512, 64, k=1) self.reorg = reorg_layer(stride=2) self.convsets_2 = Conv(1280, 1024, k=3, p=1) # prediction layer self.pred = nn.Conv2d(1024, self.num_anchors * (1 + 4 + self.num_classes), kernel_size=1)