def __init__(self, cfg): super(Darknet19, self).__init__() self.cfg = cfg net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] # darknet self.conv1s, c1 = _make_layers(3, net_cfgs[0:5]) self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) stride = 2 self.reorg = ReorgLayer(stride=2) # stride*stride times the channels of conv1s # cat [conv1s, conv3] self.conv4, c4 = _make_layers((c1 * (stride * stride) + c3), net_cfgs[7]) # linear out_channels = cfg['num_anchors'] * (cfg['num_classes'] + 5) self.conv5 = net_utils.Conv2d(c4, out_channels, 1, 1, relu=False)
def __init__(self): super(Darknet19, self).__init__() net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] # darknet self.conv1s, c1 = _make_layers(3, net_cfgs[0:5]) self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) stride = 2 # stride*stride times the channels of conv1s self.reorg = ReorgLayer(stride=2) # cat [conv1s, conv3] self.conv4, c4 = _make_layers((c1 * (stride * stride) + c3), net_cfgs[7]) self.feature_channel = c4
def __init__(self, data_name): super(Darknet19, self).__init__() net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] if data_name == 'voc': from cfgs import config_voc as cfg elif data_name == 'mscoco': from cfgs import config_coco as cfg elif data_name == 'open_image': from cfgs import config_open_image as cfg # darknet self.conv1s, c1 = _make_layers(3, net_cfgs[0:5]) self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) stride = 2 # stride*stride times the channels of conv1s self.reorg = ReorgLayer(stride=2) # cat [conv1s, conv3] self.conv4, c4 = _make_layers((c1 * (stride * stride) + c3), net_cfgs[7]) # linear out_channels = cfg.num_anchors * (cfg.num_classes + 5) self.conv5 = net_utils.Conv2d(c4, out_channels, 1, 1, relu=False) self.global_average_pool = nn.AvgPool2d((1, 1)) # train self.bbox_loss = None self.iou_loss = None self.cls_loss = None self.pool = Pool(processes=1) self.data_name = data_name self.cfg = cfg
def __init__(self, training=True): super(Darknet19, self).__init__() net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] # darknet self.conv1s, c1 = _make_layers(3, net_cfgs[0:5]) self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) stride = 2 # stride*stride times the channels of conv1s self.reorg = ReorgLayer(stride=2) # cat [conv1s, conv3] self.conv4, c4 = _make_layers((c1 * (stride * stride) + c3), net_cfgs[7]) # linear out_channels = cfg.num_anchors * (cfg.num_classes + 5) self.conv5 = net_utils.Conv2d(c4, out_channels, 1, 1, relu=False) self.global_average_pool = nn.AvgPool2d((1, 1)) # train self.bbox_loss = None self.iou_loss = None self.cls_loss = None self.pool = Pool(processes=10) ''' define a patch here ''' # training if training: self.patch = nn.Parameter(torch.rand(1, 3, cfg.img_w, cfg.img_h), requires_grad=True) # testing else: self.patch = cfg.patch.cuda()
def __init__(self): super(Darknet19, self).__init__() net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] # darknet self.conv1s, c1 = _make_layers( 3, net_cfgs[0:5]) # input_channels, the parameters of network # conv1 = 26 * 26 * 512 c1 = 512 self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # conv2 = 13 * 13 * 1024 c2 = 1024 # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) # conv3 = 13 * 13 * 1024 c3 = 1024 stride = 2 # stride*stride times the channels of conv1s self.reorg = ReorgLayer(stride=2) # cat [conv1s, conv3] self.conv4, c4 = _make_layers( (c1 * (stride * stride) + c3), net_cfgs[7]) # in_channels = 512 * 4 + 1024 = 3072 # conv4 = 13 * 13 * 1024, c4 = 1024 # linear out_channels = cfg.num_anchors * (cfg.num_classes + 5) # 5 * (20 + 5) self.conv5 = net_utils.Conv2d(c4, out_channels, 1, 1, relu=False) # 13 * 13 * out_channels self.global_average_pool = nn.AvgPool2d((1, 1)) # train self.bbox_loss = None self.iou_loss = None self.cls_loss = None self.pool = Pool(processes=10)
def __init__(self): super(Darknet19, self).__init__() net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] # darknet self.conv1s, c1 = _make_layers(3, net_cfgs[0:5]) self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) stride = 2 # stride*stride times the channels of conv1s self.reorg = ReorgLayer(stride=2) # cat [conv1s, conv3] self.conv4, c4 = _make_layers((c1 * (stride * stride) + c3), net_cfgs[7]) # linear out_channels = cfg.num_anchors * (cfg.num_classes + 5) self.conv5 = net_utils.Conv2d(c4, out_channels, 1, 1, relu=False) #new-back_layer self.conv_back = net_utils.Conv2d(out_channels, c4, 1, 1, relu=True) self.global_average_pool = nn.AvgPool2d((1, 1)) # train self.bbox_loss = None self.iou_loss = None self.cls_loss = None self.pool = Pool(processes=10)
def __init__(self): super(Darknet19, self).__init__() ''' 这个结构来源于paper我们将进行如下的论述 输入 bs 3 * 448* 448 conv 32 3*3 max pooling 224*224 conv 64 3*3 max pooling 112*112 128 3*3 64 1*1 128 3*3 max pooling 56*56 256 3*3 128 3*3 256 3*3 max pooling 28*28 512 3*3 256 1*1 512 3*3 256 1*1 512 3*3 --------------------->fine grain features 细粒度特征提取 maxpooling 14*14 1024 3*3 512 1*1 1024 3*3 512 1*1 1024 3*3 ______________ 1000 1*1 14*14 avgpool 1000*1*1 softmax 其实这个过程有点类似于vgg16,但是他的设计是漏斗状的 ''' ''' 上面的是darknet 的分类模型用于 imagenet 上的,这个模型,处理完了之后 根据论文的要求我们移除最后的分类框架,加入三个3*3的卷积 1024*3*3的核 ''' net_cfgs = [ # conv1s [(32, 3)], ['M', (64, 3)], ['M', (128, 3), (64, 1), (128, 3)], ['M', (256, 3), (128, 1), (256, 3)], ['M', (512, 3), (256, 1), (512, 3), (256, 1), (512, 3)], # conv2 ['M', (1024, 3), (512, 1), (1024, 3), (512, 1), (1024, 3)], # ------------ # conv3 [(1024, 3), (1024, 3)], # conv4 [(1024, 3)] ] # darknet # 这一部分是类于darknet 的操作 self.conv1s, c1 = _make_layers(3, net_cfgs[0:5]) self.conv2, c2 = _make_layers(c1, net_cfgs[5]) # --- self.conv3, c3 = _make_layers(c2, net_cfgs[6]) stride = 2 # stride*stride times the channels of conv1s #reorg 这个操作非常的有意思是细粒度特征处理层,他的方法是将胖的卷积层边瘦,具体看.so 文件的操作 self.reorg = ReorgLayer(stride=2) # cat [conv1s, conv3] self.conv4, c4 = _make_layers((c1*(stride*stride) + c3), net_cfgs[7]) # linear # 对于voc num_anchors =5 ,num_classes = 20 所以最后的输出层有125 个输出 out_channels = cfg.num_anchors * (cfg.num_classes + 5) #这是最后的回归层,是个非常有意思的东西 self.conv5 = net_utils.Conv2d(c4, out_channels, 1, 1, relu=False) self.global_average_pool = nn.AvgPool2d((1, 1)) # train self.bbox_loss = None self.iou_loss = None self.cls_loss = None self.pool = Pool(processes=10)