mmdet/datasets/coco_orientation.py
def _parse_ann_info(self, img_info, ann_info):
        """Parse bbox and mask annotation.

        Args:
            ann_info (list[dict]): Annotation info of an image.
            with_mask (bool): Whether to parse mask annotations.

        Returns:
            dict: A dict containing the following keys: bboxes, bboxes_ignore,\
                labels, masks, seg_map. "masks" are raw annotations and not \
                decoded into binary masks.
        """
        gt_bboxes = []
        gt_labels = []
        gt_bboxes_ignore = []
        gt_masks_ann = []

        gt_orientations = []
        orientation_kernel_len = 72
        sigma = 4.0

        for i, ann in enumerate(ann_info):
            if ann.get('ignore', False):
                continue
            x1, y1, w, h = ann['bbox']
            inter_w = max(0, min(x1 + w, img_info['width']) - max(x1, 0))
            inter_h = max(0, min(y1 + h, img_info['height']) - max(y1, 0))
            if inter_w * inter_h == 0:
                continue
            if ann['area'] <= 0 or w < 1 or h < 1:
                continue
            if ann['category_id'] not in self.cat_ids:
                continue
            bbox = [x1, y1, x1 + w, y1 + h]
            orientation_label = int(ann['orientation']) // 5
            if ann.get('iscrowd', False):
                gt_bboxes_ignore.append(bbox)
            else:
                gt_bboxes.append(bbox)
                gt_labels.append(self.cat2label[ann['category_id']])
                gt_masks_ann.append(ann.get('segmentation', None))
                
                gaussian_kernel = 6 * int(sigma) + 1
                ret = np.zeros((orientation_kernel_len), dtype='float32')
                kernel = signal.gaussian(gaussian_kernel, sigma)
                mid_point = int(gaussian_kernel / 2)
                for j in range(-mid_point, mid_point + 1):
                    idx = (orientation_label + j + orientation_kernel_len) % orientation_kernel_len
                    ret[idx] = kernel[j + mid_point]
                ret = ret/ret.sum()
                gt_orientations.append(ret)
        
        if gt_bboxes:
            gt_bboxes = np.array(gt_bboxes, dtype=np.float32)
            gt_labels = np.array(gt_labels, dtype=np.int64)
            gt_orientations = np.array(gt_orientations, dtype=np.float32)
        else:
            gt_bboxes = np.zeros((0, 4), dtype=np.float32)
            gt_labels = np.array([], dtype=np.int64)
            gt_orientations = np.array([], dtype=np.float32)

        if gt_bboxes_ignore:
            gt_bboxes_ignore = np.array(gt_bboxes_ignore, dtype=np.float32)
        else:
            gt_bboxes_ignore = np.zeros((0, 4), dtype=np.float32)

        seg_map = img_info['filename'].replace('jpg', 'png')

        ann = dict(
            bboxes=gt_bboxes,
            labels=gt_labels,
            bboxes_ignore=gt_bboxes_ignore,
            masks=gt_masks_ann,
            seg_map=seg_map,
            orientations=gt_orientations)

        return ann
Parse bbox and mask annotation.

        Args:
            ann_info (list[dict]): Annotation info of an image.
            with_mask (bool): Whether to parse mask annotations.

        Returns:
            dict: A dict containing the following keys: bboxes, bboxes_ignore,\
                labels, masks, seg_map. "masks" are raw annotations and not \
                decoded into binary masks.
        
Parse bbox and mask annotation.
Parse bbox and mask annotation .
def _parse_ann_info(self, img_info, ann_info):
        gt_bboxes = []
        gt_labels = []
        gt_bboxes_ignore = []
        gt_masks_ann = []
        gt_orientations = []
        orientation_kernel_len = 72
        sigma = 4.0
        for i, ann in enumerate(ann_info):
            if ann.get('ignore', False):
                continue
            x1, y1, w, h = ann['bbox']
            inter_w = max(0, min(x1 + w, img_info['width']) - max(x1, 0))
            inter_h = max(0, min(y1 + h, img_info['height']) - max(y1, 0))
            if inter_w * inter_h == 0:
                continue
            if ann['area'] <= 0 or w < 1 or h < 1:
                continue
            if ann['category_id'] not in self.cat_ids:
                continue
            bbox = [x1, y1, x1 + w, y1 + h]
            orientation_label = int(ann['orientation']) // 5
            if ann.get('iscrowd', False):
                gt_bboxes_ignore.append(bbox)
            else:
                gt_bboxes.append(bbox)
                gt_labels.append(self.cat2label[ann['category_id']])
                gt_masks_ann.append(ann.get('segmentation', None))
                gaussian_kernel = 6 * int(sigma) + 1
                ret = np.zeros((orientation_kernel_len), dtype='float32')
                kernel = signal.gaussian(gaussian_kernel, sigma)
                mid_point = int(gaussian_kernel / 2)
                for j in range(-mid_point, mid_point + 1):
                    idx = (orientation_label + j + orientation_kernel_len) % orientation_kernel_len
                    ret[idx] = kernel[j + mid_point]
                ret = ret/ret.sum()
                gt_orientations.append(ret)
        if gt_bboxes:
            gt_bboxes = np.array(gt_bboxes, dtype=np.float32)
            gt_labels = np.array(gt_labels, dtype=np.int64)
            gt_orientations = np.array(gt_orientations, dtype=np.float32)
        else:
            gt_bboxes = np.zeros((0, 4), dtype=np.float32)
            gt_labels = np.array([], dtype=np.int64)
            gt_orientations = np.array([], dtype=np.float32)
        if gt_bboxes_ignore:
            gt_bboxes_ignore = np.array(gt_bboxes_ignore, dtype=np.float32)
        else:
            gt_bboxes_ignore = np.zeros((0, 4), dtype=np.float32)
        seg_map = img_info['filename'].replace('jpg', 'png')
        ann = dict(
            bboxes=gt_bboxes,
            labels=gt_labels,
            bboxes_ignore=gt_bboxes_ignore,
            masks=gt_masks_ann,
            seg_map=seg_map,
            orientations=gt_orientations)
        return ann
def _parse_ann_info ( self , img_info , ann_info ) : gt_bboxes = [ ] gt_labels = [ ] gt_bboxes_ignore = [ ] gt_masks_ann = [ ] gt_orientations = [ ] orientation_kernel_len = 72 sigma = 4.0 for i , ann in enumerate ( ann_info ) : if ann . get ( 'ignore' , False ) : continue x1 , y1 , w , h = ann [ 'bbox' ] inter_w = max ( 0 , min ( x1 + w , img_info [ 'width' ] ) - max ( x1 , 0 ) ) inter_h = max ( 0 , min ( y1 + h , img_info [ 'height' ] ) - max ( y1 , 0 ) ) if inter_w * inter_h == 0 : continue if ann [ 'area' ] <= 0 or w < 1 or h < 1 : continue if ann [ 'category_id' ] not in self . cat_ids : continue bbox = [ x1 , y1 , x1 + w , y1 + h ] orientation_label = int ( ann [ 'orientation' ] ) // 5 if ann . get ( 'iscrowd' , False ) : gt_bboxes_ignore . append ( bbox ) else : gt_bboxes . append ( bbox ) gt_labels . append ( self . cat2label [ ann [ 'category_id' ] ] ) gt_masks_ann . append ( ann . get ( 'segmentation' , None ) ) gaussian_kernel = 6 * int ( sigma ) + 1 ret = np . zeros ( ( orientation_kernel_len ) , dtype = 'float32' ) kernel = signal . gaussian ( gaussian_kernel , sigma ) mid_point = int ( gaussian_kernel / 2 ) for j in range ( - mid_point , mid_point + 1 ) : idx = ( orientation_label + j + orientation_kernel_len ) % orientation_kernel_len ret [ idx ] = kernel [ j + mid_point ] ret = ret / ret . sum ( ) gt_orientations . append ( ret ) if gt_bboxes : gt_bboxes = np . array ( gt_bboxes , dtype = np . float32 ) gt_labels = np . array ( gt_labels , dtype = np . int64 ) gt_orientations = np . array ( gt_orientations , dtype = np . float32 ) else : gt_bboxes = np . zeros ( ( 0 , 4 ) , dtype = np . float32 ) gt_labels = np . array ( [ ] , dtype = np . int64 ) gt_orientations = np . array ( [ ] , dtype = np . float32 ) if gt_bboxes_ignore : gt_bboxes_ignore = np . array ( gt_bboxes_ignore , dtype = np . float32 ) else : gt_bboxes_ignore = np . zeros ( ( 0 , 4 ) , dtype = np . float32 ) seg_map = img_info [ 'filename' ] . replace ( 'jpg' , 'png' ) ann = dict ( bboxes = gt_bboxes , labels = gt_labels , bboxes_ignore = gt_bboxes_ignore , masks = gt_masks_ann , seg_map = seg_map , orientations = gt_orientations ) return ann
Parse bbox and mask annotation.
Parse bbox and mask annotation .
"""Parse bbox and mask annotation.

        Args:
            ann_info (list[dict]): Annotation info of an image.
            with_mask (bool): Whether to parse mask annotations.

        Returns:
            dict: A dict containing the following keys: bboxes, bboxes_ignore,\
                labels, masks, seg_map. "masks" are raw annotations and not \
                decoded into binary masks.
        """
A dict containing the following keys: bboxes, bboxes_ignore,\
labels, masks, seg_map. "masks" are raw annotations and not \
decoded into binary masks.
A dict containing the following keys : bboxes bboxes_ignore \ labels masks seg_map . " masks " are raw annotations and not \ decoded into binary masks .
dict
self
img_info
ann_info
Annotation info of an image.
Annotation info of an image .
with_mask
Whether to parse mask annotations.
Whether to parse mask annotations .