def __init__(self, num_class: int, strides: List[int], anchors: List[List[int]], **kwargs): super(YOLOv3TargetGenerator, self).__init__(**kwargs) self._num_classes = num_class self._strides = strides self._anchors = anchors self._item_len = 4 + 1 + num_class self.bbox2center = BBoxCornerToCenter(axis=-1, split=True) self.bbox2corner = BBoxCenterToCorner(axis=-1, split=False)
def __init__(self, features, scales, ratios, classes, roi_size, train_patterns, stride=32, rpn_channel=1024, num_sample=128, pos_iou_thresh=0.5, neg_iou_thresh_high=0.5, neg_iou_thresh_low=0.0, pos_ratio=0.25, nms_thresh=0.3, nms_topk=400, post_nms=100): #super from rcnn super(LHRCNN, self).__init__() self.stride = stride self._max_batch = 1 # currently only support batch size = 1 self._max_roi = 100000 # maximum allowed ROIs self.num_class = len(classes) self._target_generator = set([RCNNTargetGenerator(self.num_class)]) self.k, _ = roi_size self.CT = 10 #--------RCNN parms-------- self.train_patterns = train_patterns self.nms_thresh = nms_thresh self.nms_topk = nms_topk self.post_nms = post_nms #-------nn init------------ with self.name_scope(): #-------ligth head rcnn setting------- self.rpn = RPN(rpn_channel, stride, scales=scales, ratios=ratios) self.sampler = RCNNTargetSampler(num_sample, pos_iou_thresh, neg_iou_thresh_high, neg_iou_thresh_low, pos_ratio) self.group_conv = Group_Conv(10 * self.k * self.k) #-------rcnn setting--------------- self.box_to_center = BBoxCornerToCenter() self.box_decoder = NormalizedBoxCenterDecoder() self.cls_decoder = MultiPerClassDecoder(num_class=self.num_class + 1) self.features = features self.share = nn.Dense(1024, activation='relu', weight_initializer=mx.init.Normal(0.01)) self.clf = nn.Dense(self.num_class + 1, weight_initializer=mx.init.Normal(0.01)) self.reg = nn.Dense(self.num_class * 4, weight_initializer=mx.init.Normal(0.01))
def __init__(self, features, top_features, classes, short, max_size, train_patterns=None, nms_thresh=0.3, nms_topk=400, post_nms=100, roi_mode='align', roi_size=(14, 14), stride=16, clip=None, rpn_channel=1024, base_size=16, scales=(0.5, 1, 2), ratios=(8, 16, 32), alloc_size=(128, 128), rpn_nms_thresh=0.5, rpn_train_pre_nms=12000, rpn_train_post_nms=2000, rpn_test_pre_nms=6000, rpn_test_post_nms=300, rpn_min_size=16, num_sample=128, pos_iou_thresh=0.5, pos_ratio=0.25): super(FasterRCNN, self).__init__() self.classes = classes self.num_classes = len(classes) self.short = short self.max_size = max_size self.train_patterns = train_patterns self.nms_thresh = nms_thresh self.nms_topk = nms_topk self.post_nms = post_nms self._max_batch = 1 self._num_sample = num_sample self._rpn_test_post_nms = rpn_test_post_nms # return cls_target, box_target, box_mask self._target_generater = {RCNNTargetGenerator(self.num_classes)} self._roi_mode = roi_mode.lower() self._roi_size = roi_size self._stride = stride with self.name_scope(): self.features = features self.top_features = top_features self.global_avg_pool = nn.GlobalAvgPool2D() self.class_predictor = nn.Dense( self.num_classes+1, weight_initializer=mx.init.Normal(0.01)) self.box_predictor = nn.Dense( self.num_classes*4, weight_initializer=mx.init.Normal(0.01)) # reconstruct valid labels self.cls_decoder = MultiPerClassDecoder(num_class=self.num_classes+1) # (xmin, ymin, xmax, ymax) -> (x, y, h, w) self.box_to_center = BBoxCornerToCenter() # reconstructed bounding boxes self.box_decoder = NormalizedBoxCenterDecoder(clip=clip) # self.rpn = RPN( channels=rpn_channel, stride=stride, base_size=base_size, scales=scales, ratios=ratios, alloc_size=alloc_size, clip=clip, nms_thresh=rpn_nms_thresh, train_pre_nms=rpn_train_pre_nms, train_post_nms=rpn_train_post_nms, test_pre_nms=rpn_test_pre_nms, test_post_nms=rpn_test_post_nms, min_size=rpn_min_size) self.sampler = RCNNTargetSampler( num_image=self._max_batch, num_proposal=rpn_train_post_nms, num_sample=num_sample, pos_iou_thresh=pos_iou_thresh, pos_ratio=pos_ratio)
def __init__(self, num_class: int, strides: List[int], anchors: List[List[int]], **kwargs): super(YOLOv3TargetGenerator, self).__init__(**kwargs) self._num_classes = num_class self._strides = strides self._anchors = anchors self._item_len = 4 + 1 + num_class self.bbox2center = BBoxCornerToCenter(axis=-1, split=True) self.bbox2corner = BBoxCenterToCorner(axis=-1, split=False) alloc_size = (128, 128) grid_x = np.arange(alloc_size[1]) grid_y = np.arange(alloc_size[0]) grid_x, grid_y = np.meshgrid(grid_x, grid_y) offsets = np.concatenate((grid_x[:, :, np.newaxis], grid_y[:, :, np.newaxis]), axis=-1) offsets = np.expand_dims(np.expand_dims(offsets, axis=0), axis=0) self._offsets = nd.array(offsets)
def __init__(self, backbone_cfg, neck_cfg, head_cfg, num_class: int, strides: List[int], anchors: List[List[List[int]]], **kwargs): if 'prefix' not in kwargs: kwargs['prefix'] = self.__class__.__name__.lower() + '_' super().__init__(**kwargs) backbone = build_backbone(backbone_cfg) neck = build_neck(neck_cfg) head = build_head(head_cfg) with self.name_scope(): self.backbone = backbone self.neck = neck self.head = head self._num_classes = num_class self._strides = strides self._anchors = anchors self._item_len = 4 + 1 + num_class self.bbox2center = BBoxCornerToCenter(axis=-1, split=True) self.bbox2corner = BBoxCenterToCorner(axis=-1, split=False)
def __init__(self, num_class, **kwargs): super(YOLOV3PrefetchTargetGenerator, self).__init__(**kwargs) self._num_class = num_class self.bbox2center = BBoxCornerToCenter(axis=-1, split=True) self.bbox2corner = BBoxCenterToCorner(axis=-1, split=False)