(bbox, bbox_delta, im_info=None)
return transformed_bbox.transpose(1, 2)
:param bbox: [num_boxes, 4]
        :param bbox_delta: [num_boxes, (4 * num_reg_classes - 1)]
        :param im_info: [1, 3] -> [[height, width, scale]]
        :return: transformed_bbox: [num_boxes, 4, num_reg_classes]
def bbox_transform(bbox, bbox_delta, im_info=None):
        """

        :param bbox: [num_boxes, 4]
        :param bbox_delta: [num_boxes, (4 * num_reg_classes - 1)]
        :param im_info: [1, 3] -> [[height, width, scale]]
        :return: transformed_bbox: [num_boxes, 4, num_reg_classes]
        """

        xmin, ymin, xmax, ymax = bbox[:, 0], bbox[:, 1], bbox[:, 2], bbox[:, 3]

        bbox_width = xmax - xmin + 1.0
        bbox_height = ymax - ymin + 1.0
        center_x = xmin + 0.5 * bbox_width
        center_y = ymin + 0.5 * bbox_height

        dx, dy, dw, dh = bbox_delta[:, 0::4],bbox_delta[:, 1::4], bbox_delta[:, 2::4], bbox_delta[:, 3::4]

        dx = dx / config.network.bbox_reg_weights[0]
        dy = dy / config.network.bbox_reg_weights[1]
        dw = dw / config.network.bbox_reg_weights[2]
        dh = dh / config.network.bbox_reg_weights[3]

        transformed_center_x = center_x.view(-1, 1) + bbox_width.view(-1, 1) * dx
        transformed_center_y = center_y.view(-1, 1) + bbox_height.view(-1, 1) * dy
        transformed_width = bbox_width.view(-1, 1) * dw.exp()
        transformed_height = bbox_height.view(-1, 1) * dh.exp()

        w_offset = 0.5 * transformed_width
        h_offset = 0.5 * transformed_height
        transformed_xmin = transformed_center_x - w_offset
        transformed_ymin = transformed_center_y - h_offset
        transformed_xmax = transformed_center_x + w_offset - 1
        transformed_ymax = transformed_center_y + h_offset - 1

        # transformed_bbox = torch.cat([transformed_xmin, transformed_ymin, transformed_xmax, transformed_ymax], dim=1)
        transformed_bbox = torch.zeros_like(bbox_delta)
        transformed_bbox[:, 0::4] = transformed_xmin
        transformed_bbox[:, 1::4] = transformed_ymin
        transformed_bbox[:, 2::4] = transformed_xmax
        transformed_bbox[:, 3::4] = transformed_ymax
        # [num_boxes, num_reg_classes - 1, 4]
        transformed_bbox = transformed_bbox.view((transformed_bbox.shape[0], -1, 4))


        if im_info is not None:
            # [1, 2]
            im_wh = torch.from_numpy(im_info[0, [1, 0]] - 1.0).to(transformed_bbox.device, non_blocking=True)
            # [1, 1, 4]
            im_wh = im_wh.repeat(1, 2).unsqueeze(0)
            transformed_bbox = torch.min(transformed_bbox, im_wh)
            transformed_bbox = torch.max(transformed_bbox, torch.zeros_like(transformed_bbox))

        return transformed_bbox.transpose(1, 2)
def bbox_transform ( bbox , bbox_delta , im_info = None ) : xmin , ymin , xmax , ymax = bbox [ : , 0 ] , bbox [ : , 1 ] , bbox [ : , 2 ] , bbox [ : , 3 ] bbox_width = xmax - xmin + 1.0 bbox_height = ymax - ymin + 1.0 center_x = xmin + 0.5 * bbox_width center_y = ymin + 0.5 * bbox_height dx , dy , dw , dh = bbox_delta [ : , 0 : : 4 ] , bbox_delta [ : , 1 : : 4 ] , bbox_delta [ : , 2 : : 4 ] , bbox_delta [ : , 3 : : 4 ] dx = dx / config . network . bbox_reg_weights [ 0 ] dy = dy / config . network . bbox_reg_weights [ 1 ] dw = dw / config . network . bbox_reg_weights [ 2 ] dh = dh / config . network . bbox_reg_weights [ 3 ] transformed_center_x = center_x . view ( - 1 , 1 ) + bbox_width . view ( - 1 , 1 ) * dx transformed_center_y = center_y . view ( - 1 , 1 ) + bbox_height . view ( - 1 , 1 ) * dy transformed_width = bbox_width . view ( - 1 , 1 ) * dw . exp ( ) transformed_height = bbox_height . view ( - 1 , 1 ) * dh . exp ( ) w_offset = 0.5 * transformed_width h_offset = 0.5 * transformed_height transformed_xmin = transformed_center_x - w_offset transformed_ymin = transformed_center_y - h_offset transformed_xmax = transformed_center_x + w_offset - 1 transformed_ymax = transformed_center_y + h_offset - 1 # transformed_bbox = torch.cat([transformed_xmin, transformed_ymin, transformed_xmax, transformed_ymax], dim=1) transformed_bbox = torch . zeros_like ( bbox_delta ) transformed_bbox [ : , 0 : : 4 ] = transformed_xmin transformed_bbox [ : , 1 : : 4 ] = transformed_ymin transformed_bbox [ : , 2 : : 4 ] = transformed_xmax transformed_bbox [ : , 3 : : 4 ] = transformed_ymax # [num_boxes, num_reg_classes - 1, 4] transformed_bbox = transformed_bbox . view ( ( transformed_bbox . shape [ 0 ] , - 1 , 4 ) ) if im_info is not None : # [1, 2] im_wh = torch . from_numpy ( im_info [ 0 , [ 1 , 0 ] ] - 1.0 ) . to ( transformed_bbox . device , non_blocking = True ) # [1, 1, 4] im_wh = im_wh . repeat ( 1 , 2 ) . unsqueeze ( 0 ) transformed_bbox = torch . min ( transformed_bbox , im_wh ) transformed_bbox = torch . max ( transformed_bbox , torch . zeros_like ( transformed_bbox ) ) return transformed_bbox . transpose ( 1 , 2 )