def init_param(self, model_config):
        self.in_channels = model_config['din']
        self.post_nms_topN = model_config['post_nms_topN']
        self.pre_nms_topN = model_config['pre_nms_topN']
        self.nms_thresh = model_config['nms_thresh']
        self.use_score = model_config['use_score']
        # self.rpn_batch_size = model_config['rpn_batch_size']
        self.num_cls_samples = model_config['num_cls_samples']
        self.num_reg_samples = model_config['num_reg_samples']
        self.use_focal_loss = model_config['use_focal_loss']

        # sampler
        # self.sampler = HardNegativeSampler({"fg_fraction": 1.0})
        # self.sampler = BalancedSampler(model_config['sampler_config'])
        self.sampler = DetectionSampler({"fg_fraction": 1.0})

        # anchor generator
        self.anchor_generator = AnchorGenerator(
            model_config['anchor_generator_config'])
        self.num_anchors = self.anchor_generator.num_anchors
        self.nc_bbox_out = 4 * self.num_anchors
        self.nc_score_out = self.num_anchors * 2

        # target assigner
        self.target_assigner = TargetAssigner(
            model_config['target_assigner_config'])

        # bbox coder
        self.bbox_coder = self.target_assigner.bbox_coder

        self.use_iou = model_config.get('use_iou')
Пример #2
0
    def init_param(self, model_config):
        self.in_channels = model_config['din']
        self.post_nms_topN = model_config['post_nms_topN']
        self.pre_nms_topN = model_config['pre_nms_topN']
        self.nms_thresh = model_config['nms_thresh']
        self.use_score = model_config['use_score']
        self.rpn_batch_size = model_config['rpn_batch_size']
        self.use_focal_loss = model_config['use_focal_loss']
        self.iou_criterion = model_config['iou_criterion']
        self.use_iox = model_config['use_iox']
        self.theta = 1.0
        self.alpha = 0.6

        # sampler
        # self.sampler = HardNegativeSampler(model_config['sampler_config'])
        # self.sampler = BalancedSampler(model_config['sampler_config'])
        self.sampler = DetectionSampler(model_config['sampler_config'])

        # anchor generator
        self.anchor_generator = AnchorGenerator(
            model_config['anchor_generator_config'])
        self.num_anchors = self.anchor_generator.num_anchors
        self.nc_bbox_out = 4 * self.num_anchors
        self.nc_score_out = self.num_anchors * 2

        # target assigner
        self.target_assigner = LEDTargetAssigner(
            model_config['target_assigner_config'])

        # bbox coder
        self.bbox_coder = self.target_assigner.bbox_coder
Пример #3
0
    def init_param(self, model_config):
        self.outside_window_filter = model_config.get('outside_window_filter',
                                                      False)
        self.in_channels = model_config['din']
        self.post_nms_topN = model_config['post_nms_topN']
        self.pre_nms_topN = model_config['pre_nms_topN']
        self.nms_thresh = model_config['nms_thresh']
        self.use_score = model_config['use_score']
        self.rpn_batch_size = model_config['rpn_batch_size']
        self.use_focal_loss = model_config['use_focal_loss']
        self.clip_boxes = model_config.get('clip_boxes', True)

        # sampler
        # self.sampler = HardNegativeSampler(model_config['sampler_config'])
        # self.sampler = BalancedSampler(model_config['sampler_config'])
        self.sampler = DetectionSampler(model_config['sampler_config'])

        # anchor generator
        self.anchor_generator = AnchorGenerator(
            model_config['anchor_generator_config'])
        self.num_anchors = self.anchor_generator.num_anchors
        self.nc_bbox_out = 4 * self.num_anchors
        self.nc_score_out = self.num_anchors * 2

        # target assigner
        self.target_assigner = TargetAssigner(
            model_config['target_assigner_config'])

        # bbox coder
        self.bbox_coder = self.target_assigner.bbox_coder

        self.use_iou = model_config.get('use_iou')
Пример #4
0
def read_anchors():
    anchor_generator_config = {
        "base_anchor_size": 16,
        "scales": [4, 8, 16],
        "aspect_ratios": [0.5, 0.8, 1],
        "anchor_stride": [16, 16],
        "anchor_offset": [0, 0]
    }
    anchor_generator = AnchorGenerator(anchor_generator_config)

    anchors = anchor_generator.generate([[1, 1]])
    return anchors[0].cpu().numpy()
Пример #5
0
    def init_param(self, model_config):
        self.feature_extractor_config = model_config['feature_extractor_config']
        self.multibox_cfg = [3, 3, 3, 3, 3, 3]
        self.n_classes = len(model_config['classes'])
        self.sampler = DetectionSampler(model_config['sampler_config'])
        self.batch_size = model_config['batch_size']
        self.use_focal_loss = model_config['use_focal_loss']
        # self.multibox_cfg = model_config['multibox_config']

        self.target_assigner = TargetAssigner(
            model_config['target_assigner_config'])

        # import ipdb
        # ipdb.set_trace()
        self.anchor_generator = AnchorGenerator(
            model_config['anchor_generator_config'])

        self.bbox_coder = self.target_assigner.bbox_coder
Пример #6
0
import numpy as np
import sys
sys.path.append('.')
from core.anchor_generators.anchor_generator import AnchorGenerator
from lib.model.rpn.generate_anchors import generate_anchors
from utils.visualize import visualize_bbox, read_img, shift_bbox

anchor_generator_config = {
    "base_anchor_size": 1,
    "scales": [4],
    "aspect_ratios": [1],
    "anchor_stride": [16, 16],
    "anchor_offset": [0, 0]
}
anchor_generator = AnchorGenerator(anchor_generator_config)

anchors = anchor_generator.generate([[24, 80]])
# print(anchors)

expect_anchors = generate_anchors(
    base_size=anchor_generator_config['base_anchor_size'],
    ratios=np.array(anchor_generator_config['aspect_ratios']),
    scales=np.array(anchor_generator_config['scales']))

img = read_img('/data/object/training/image_2/000117.png')


def vis_help(anchors, expect_anchors):
    # shift_bbox(anchors, translation=(200, 200))
    # shift_bbox(expect_anchors, translation=(800, 200))