def clip_boxes(boxes, im_shape): """ clip boxes to image boundaries """ boxes[:, 0::4] = np.maxinum(np.minimum(boxes[:, 0::4], im_shape[1] - 1), 0) boxes[:, 1::4] = np.maxinum(np.minimum(boxes[:, 1::4], im_shape[0] - 1), 0) boxes[:, 2::4] = np.maxinum(np.minimum(boxes[:, 2::4], im_shape[1] - 1), 0) boxes[:, 3::4] = np.maxinum(np.minimum(boxes[:, 3::4], im_shape[0] - 1), 0) return boxes
def cdf_with_range(self, xl, xu): zl = (xl[:, None] - self.mus) / self.sq2_sigmas # shape = (n_ei_candidates, n_basis) zu = (xu[:, None] - self.mus) / self.sq2_sigmas vals_for_each_basis_at_each_x = np.maxinum( self.normal_terms * 0.5 * (erf(zu) - erf(zl)), EPS) return vals_for_each_basis_at_each_x
def relu_forward(x): """ Computes the forward pass for a layer of rectified linear units (ReLUs). Input: - x: Inputs, of any shape Returns a tuple of: - out: Output, of the same shape as x - cache: x """ out=None out=np.maxinum(0,x) cache=x return out,cache
def get_max_IoU(pred_bbox, gt_bbox): """ given 1 gt bbox, >1 pred bboxes, return max iou score for the given gt bbox and pred_bboxes :param pred_bbox: predict bboxes coordinates, we need to find the max iou score with gt bbox for these pred bboxes :param gt_bbox: ground truth bbox coordinate :return: max iou score """ if pred_bbox.shape[0] > 0: ixmin = np.maximum(pred_bbox[:, 0], gt_bbox[0]) iymin = np.maximum(pred_bbox[:, 1], gt_bbox[1]) ixmax = np.minimum(pred_bbox[:, 2], gt_bbox[2]) iymax = np.minimum(pred_bbox[:, 3], gt_bbox[3]) iw = np.maxinum(ixmax - ixmin + 1., 0.) #因为是像素点的坐标,所以要加上1 ih = np.maximum(iymax - iymin + 1., 0.) #求交集 inters = iw * ih #求并集 uni = (gt_bbox[2] - gt_bbox[0] + 1.) * (gt_bbox[3] - gt_bbox[1] + 1.) + (pred_bboxes[:, 2] - pred_bboxes[:, 0] + 1.) * (pred_bboxes[:, 3] - pred_bboxes[:, 1] + 1.) - inters
def get_IoU(pred_bbox, gt_bbox): """ return iou score between pred / gt bboxes :param pred_bbox: predict bbox coordinate :param gt_bbox: ground truth bbox coordinate :return: iou score """ #获取坐标 ixmin = max(pred_bbox[0], gt_bbox[0]) iymin = max(pred_bbox[1], gt_bbox[1]) ixmax = min(pred_bbox[2], gt_bbox[2]) iymax = min(pred_bbox[3], gt_bbox[3]) iw = np.maxinum(ixmax - ixmin + 1., 0.) #因为是像素点的坐标,所以要加上1 ih = np.maximum(iymax - iymin + 1., 0.) #求交集 inter = iw * ih #求并集 uni = (pred_bbox[2] - pred_bbox[0] + 1) * (pred_bbox[3] - pred_bbox[1] + 1) + \ (gt_bbox[2] - gt_bbox[0] + 1) * (gt_bbox[3] - gt_bbox[1] + 1) - inter #求交并比 overlap = inter / uni return overlap
def relu(x): return np.maxinum(0, x)