def select_det_ids(boxes,scores,nms_keep_ids,score_thresh,max_dets): if nms_keep_ids is None: nms_keep_ids = np.arange(0,scores.shape[0]) nms_keep_ids = nms_keep_ids.astype('int') # Select non max suppressed dets nms_scores = scores[nms_keep_ids] nms_boxes = boxes[nms_keep_ids] # Select dets above a score_thresh and which have area > 1 nms_ids_above_thresh = np.nonzero(nms_scores > score_thresh)[0] nms_ids = [] for i in range(min(nms_ids_above_thresh.shape[0],max_dets)): area = compute_area(nms_boxes[i],invalid=-1) if area > 1: nms_ids.append(i) # If no dets satisfy previous criterion select the highest ranking one with area > 1 if len(nms_ids)==0: for i in range(nms_keep_ids.shape[0]): area = compute_area(nms_boxes[i],invalid=-1) if area > 1: nms_ids = [i] break # Convert nms ids to box ids nms_ids = np.array(nms_ids,dtype=np.int32) try: ids = nms_keep_ids[nms_ids] except: import pdb; pdb.set_trace() return ids
def assign_pose(human_box, pose_boxes, pose_keypoints, num_keypoints): max_idx = -1 max_frac_inside = 0.7 found_match = False for i, pose_box in enumerate(pose_boxes): iou, intersection, union = compute_iou(human_box, pose_box,True) pose_area = compute_area(pose_box) frac_inside = intersection / pose_area if frac_inside > max_frac_inside: max_frac_inside = frac_inside max_idx = i found_match = True if max_idx == -1: keypoints = np.zeros([num_keypoints,3]) else: keypoints = pose_keypoints[max_idx] return keypoints, found_match