def gen_detection_results(video_id, score_tp): if len(score_tp[0].shape) == 3: rel_prop = np.squeeze(score_tp[0], 0) else: rel_prop = score_tp[0] # standardize regression scores reg_scores = score_tp[3] if reg_scores is None: reg_scores = np.zeros((len(rel_prop), num_class, 2), dtype=np.float32) reg_scores = reg_scores.reshape((-1, num_class, 2)) if top_k <= 0 and cls_score_dict is None: combined_scores = softmax(score_tp[1])[:, 1:] * np.exp(score_tp[2]) for i in range(num_class): loc_scores = reg_scores[:, i, 0][:, None] dur_scores = reg_scores[:, i, 1][:, None] try: dataset_detections[i][video_id] = np.concatenate(( rel_prop, combined_scores[:, i][:, None], loc_scores, dur_scores), axis=1) except: print(i, rel_prop.shape, combined_scores.shape, reg_scores.shape) raise elif cls_score_dict is None: combined_scores = softmax(score_tp[1][:, 1:]) * np.exp(score_tp[2]) keep_idx = np.argsort(combined_scores.ravel())[-top_k:] for k in keep_idx: cls = k % num_class prop_idx = k // num_class if video_id not in dataset_detections[cls]: dataset_detections[cls][video_id] = np.array([ [rel_prop[prop_idx, 0], rel_prop[prop_idx, 1], combined_scores[prop_idx, cls], reg_scores[prop_idx, cls, 0], reg_scores[prop_idx, cls, 1]] ]) else: dataset_detections[cls][video_id] = np.vstack( [dataset_detections[cls][video_id], [rel_prop[prop_idx, 0], rel_prop[prop_idx, 1], combined_scores[prop_idx, cls], reg_scores[prop_idx, cls, 0], reg_scores[prop_idx, cls, 1]]]) else: if softmax_bf: combined_scores = softmax(score_tp[1])[:, 1:] * np.exp(score_tp[2]) else: combined_scores = score_tp[1][:, 1:] * np.exp(score_tp[2]) video_cls_score = cls_score_dict[os.path.splitext(os.path.basename(video_id))[0]] for video_cls in np.argsort(video_cls_score,)[-args.cls_top_k:]: loc_scores = reg_scores[:, video_cls, 0][:, None] dur_scores = reg_scores[:, video_cls, 1][:, None] try: dataset_detections[video_cls][video_id] = np.concatenate(( rel_prop, combined_scores[:, video_cls][:, None], loc_scores, dur_scores), axis=1) except: print(video_cls, rel_prop.shape, combined_scores.shape, reg_scores.shape, loc_scores.shape, dur_scores.shape) raise
def gen_detection_results(video_id, score_tp): if len(score_tp[0].shape) == 3: rel_prop = np.squeeze(score_tp[0], 0) else: rel_prop = score_tp[0] # standardize regression scores reg_scores = score_tp[3] if reg_scores is None: reg_scores = np.zeros((len(rel_prop), num_class, 2), dtype=np.float32) reg_scores = reg_scores.reshape((-1, num_class, 2)) combined_scores = softmax(score_tp[1].squeeze()[:, :]) combined_scores = combined_scores[:, 1:] combined_scores = combined_scores * np.exp(score_tp[2].squeeze()) keep_idx = np.argsort(combined_scores.ravel())[-top_k:] for k in keep_idx: cls = k % num_class prop_idx = k // num_class if video_id not in dataset_detections[cls]: dataset_detections[cls][video_id] = np.array([[ rel_prop[prop_idx, 0], rel_prop[prop_idx, 1], combined_scores[prop_idx, cls], reg_scores[prop_idx, cls, 0], reg_scores[prop_idx, cls, 1] ]]) else: dataset_detections[cls][video_id] = np.vstack([ dataset_detections[cls][video_id], [ rel_prop[prop_idx, 0], rel_prop[prop_idx, 1], combined_scores[prop_idx, cls], reg_scores[prop_idx, cls, 0], reg_scores[prop_idx, cls, 1] ] ])
def gen_detection_results(video_id, score_tp): if len(score_tp[0].shape) == 3: rel_prop = np.squeeze(score_tp[0], 0) else: rel_prop = score_tp[0] # standardize regression scores reg_scores = score_tp[3] if reg_scores is None: reg_scores = np.zeros((len(rel_prop), num_class, 2), dtype=np.float32) reg_scores = reg_scores.reshape((-1, num_class, 2)) if cls_score_dict is None: combined_scores = softmax(score_tp[1][:, :]) combined_scores = combined_scores[:, 1:] else: combined_scores = softmax(cls_score_dict[video_id][1])[:, 1:] if combined_scores.shape[1] < score_tp[2].shape[1]: combined_scores = np.concatenate( (combined_scores, np.zeros([ len(combined_scores), score_tp[2].shape[1] - combined_scores.shape[1] ])), axis=1) elif combined_scores.shape[1] > score_tp[2].shape[1]: combined_scores = combined_scores[:, :score_tp[2].shape[1]] if not args.no_comp: combined_scores = combined_scores * np.exp(score_tp[2]) keep_idx = np.argsort(combined_scores.ravel())[-top_k:] # pdb.set_trace() delete_short = args.min_length is not None if delete_short: print('delete short proposals') duration = dataset.video_dict[video_id].num_frames / 6 prop_duration = duration * (rel_prop[:, 1] - rel_prop[:, 0]) non_short_prop_idx = np.where(prop_duration <= args.min_length)[0] keep_idx = [ x for x in keep_idx if x // num_class in non_short_prop_idx ] # keep_prop_num = len({x//num_class for x in keep_idx}) for k in keep_idx: cls = k % num_class prop_idx = k // num_class if video_id not in dataset_detections[cls]: dataset_detections[cls][video_id] = np.array([[ rel_prop[prop_idx, 0], rel_prop[prop_idx, 1], combined_scores[prop_idx, cls], reg_scores[prop_idx, cls, 0], reg_scores[prop_idx, cls, 1] ]]) else: dataset_detections[cls][video_id] = np.vstack([ dataset_detections[cls][video_id], [ rel_prop[prop_idx, 0], rel_prop[prop_idx, 1], combined_scores[prop_idx, cls], reg_scores[prop_idx, cls, 0], reg_scores[prop_idx, cls, 1] ] ]) return len(keep_idx)