def main(): opts = parse_args() mkdir2(opts.vis_dir) db = COCO(opts.annot_path) class_names = [c['name'] for c in db.dataset['categories']] seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] seq = 'f1008c18-e76e-3c24-adcc-da9858fac145' sid = seqs.index(seq) frame_list = [img for img in db.imgs.values() if img['sid'] == sid] results = pickle.load(open(join(opts.result_dir, seq + '.pkl'), 'rb')) results_parsed = results['results_parsed'] img = frame_list[153] result = results_parsed[15] bboxes, scores, labels, masks = result[:4] idx = [16] bboxes = bboxes[idx] scores = scores[idx] labels = labels[idx] masks = masks[idx] img_path = join(opts.data_root, seq_dirs[sid], img['name']) I = imread(img_path).copy() vis_path = join(opts.vis_dir, 'teaser.jpg') if opts.overwrite or not isfile(vis_path): vis_det( I, bboxes, labels, class_names, masks, None, out_scale=opts.vis_scale, out_file=vis_path, )
def main(): opts = parse_args() out_dir = mkdir2(opts.out_dir) if opts.out_dir else opts.result_dir vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) class_names = [c['name'] for c in db.dataset['categories']] n_class = len(class_names) coco_mapping = None if opts.no_class_mapping else db.dataset.get( 'coco_mapping', None) if coco_mapping is not None: coco_mapping = np.asarray(coco_mapping) seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] results_ccf = [] in_time = 0 miss = 0 mismatch = 0 print('Pairing the output with the ground truth') for sid, seq in enumerate(tqdm(seqs)): frame_list = [img for img in db.imgs.values() if img['sid'] == sid] results = pickle.load(open(join(opts.result_dir, seq + '.pkl'), 'rb')) # use raw results when possible in case we change class subset during evaluation if opts.use_parsed: results_parsed = results['results_parsed'] else: results_raw = results.get('results_raw', None) if results_raw is None: results_parsed = results['results_parsed'] timestamps = results['timestamps'] input_fidx = results['input_fidx'] tidx_p1 = 0 for ii, img in enumerate(frame_list): # pred, gt association by time t = (ii - opts.eta) / opts.fps while tidx_p1 < len(timestamps) and timestamps[tidx_p1] <= t: tidx_p1 += 1 if tidx_p1 == 0: # no output miss += 1 bboxes, scores, labels = [], [], [] masks, tracks = None, None else: tidx = tidx_p1 - 1 ifidx = input_fidx[tidx] in_time += int(ii == ifidx) mismatch += ii - ifidx if opts.use_parsed or results_raw is None: result = results_parsed[tidx] bboxes, scores, labels, masks = result[:4] if len(result) > 4: tracks = result[4] else: tracks = None else: result = results_raw[tidx] bboxes, scores, labels, masks = \ parse_det_result(result, coco_mapping, n_class) tracks = None if vis_out: img_path = join(opts.data_root, seq_dirs[sid], img['name']) I = imread(img_path) vis_path = join(opts.vis_dir, seq, img['name'][:-3] + 'jpg') if opts.overwrite or not isfile(vis_path): if tracks is None: vis_det( I, bboxes, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path, ) else: vis_track( I, bboxes, tracks, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path, ) # convert to coco fmt n = len(bboxes) if n: bboxes_ltwh = ltrb2ltwh(bboxes) for i in range(n): result_dict = { 'image_id': img['id'], 'bbox': bboxes_ltwh[i], 'score': scores[i], 'category_id': labels[i], } if masks is not None: result_dict['segmentation'] = masks[i] results_ccf.append(result_dict) out_path = join(out_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) out_path = join(out_dir, 'eval_assoc.pkl') if opts.overwrite or not isfile(out_path): pickle.dump({ 'miss': miss, 'in_time': in_time, 'mismatch': mismatch, }, open(out_path, 'wb')) if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(out_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if opts.eval_mask: print('Evaluating instance segmentation') eval_summary = eval_ccf(db, results_ccf, iou_type='segm') out_path = join(out_dir, 'eval_summary_mask.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}" --fps {opts.fps}')
masks.append(ann['segmentation']) else: masks = None labels.append(ann['category_id']) if show_track: tracks.append(ann['track']) aidx += 1 if bboxes: bboxes = np.array(bboxes) bboxes[:, 2:] += bboxes[:, :2] out_path = join(out_dir_seq, img_name[:-3] + 'jpg') if show_track: vis_track(I, bboxes, tracks, labels, class_names, masks, out_scale=out_scale, out_file=out_path) else: vis_det(I, bboxes, labels, class_names, masks, out_scale=out_scale, out_file=out_path)
def main(): assert torch.cuda.device_count( ) == 1 # mmdet only supports single GPU testing opts = parse_args() mkdir2(opts.out_dir) vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) class_names = [c['name'] for c in db.dataset['categories']] n_class = len(class_names) coco_mapping = None if opts.no_class_mapping else db.dataset.get( 'coco_mapping', None) if coco_mapping is not None: coco_mapping = np.asarray(coco_mapping) seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] model = init_detector(opts) results_raw = [] # image based, all 80 COCO classes results_ccf = [] # instance based for iid, img in tqdm(db.imgs.items()): img_name = img['name'] sid = img['sid'] seq_name = seqs[sid] img_path = join(opts.data_root, seq_dirs[sid], img_name) I = imread(img_path) result = inference_detector(model, I, gpu_pre=not opts.cpu_pre) results_raw.append(result) bboxes, scores, labels, masks = \ parse_det_result(result, coco_mapping, n_class) if vis_out: vis_path = join(opts.vis_dir, seq_name, img_name[:-3] + 'jpg') if opts.overwrite or not isfile(vis_path): vis_det(I, bboxes, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path) # convert to coco fmt n = len(bboxes) if n: ltrb2ltwh_(bboxes) for i in range(n): result_dict = { 'image_id': iid, 'bbox': bboxes[i], 'score': scores[i], 'category_id': labels[i], } if masks is not None: result_dict['segmentation'] = masks[i] results_ccf.append(result_dict) out_path = join(opts.out_dir, 'results_raw.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_raw, open(out_path, 'wb')) out_path = join(opts.out_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(opts.out_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if opts.eval_mask: print('Evaluating instance segmentation') eval_summary = eval_ccf(db, results_ccf, iou_type='segm') out_path = join(opts.out_dir, 'eval_summary_mask.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}"')
def main(): opts = parse_args() mkdir2(opts.out_dir) vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) class_names = [c['name'] for c in db.dataset['categories']] seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] box_ccf = pickle.load(open(opts.box_ccf_path, 'rb')) mask_ccf = pickle.load(open(opts.mask_ccf_path, 'rb')) box_end_idx = 0 mask_end_idx = 0 results_ccf = [] # instance based for iid, img in tqdm(db.imgs.items()): img_name = img['name'] sid = img['sid'] seq_name = seqs[sid] box_start_idx = box_end_idx while box_start_idx < len(box_ccf) and box_ccf[box_start_idx]['image_id'] < img['id']: box_start_idx += 1 box_end_idx = box_start_idx while box_end_idx < len(box_ccf) and box_ccf[box_end_idx]['image_id'] == img['id']: box_end_idx += 1 box_dets = box_ccf[box_start_idx:box_end_idx] mask_start_idx = mask_end_idx while mask_start_idx < len(mask_ccf) and mask_ccf[mask_start_idx]['image_id'] < img['id']: mask_start_idx += 1 mask_end_idx = mask_start_idx while mask_end_idx < len(mask_ccf) and mask_ccf[mask_end_idx]['image_id'] == img['id']: mask_end_idx += 1 mask_dets = mask_ccf[mask_start_idx:mask_end_idx] if len(box_dets) == 0: bboxes1, scores1, labels1, masks1 = [], [], [], None elif len(mask_dets) == 0: bboxes1 = np.array([d['bbox'] for d in box_dets]) scores1 = np.array([d['score'] for d in box_dets]) labels1 = np.array([d['category_id'] for d in box_dets]) masks1 = np.array([d['segmentation'] for d in box_dets]) else: # the slow version, but works with out of order ccf results # dets = [r for r in box_ccf if r['image_id'] == img['id']] bboxes1 = np.array([d['bbox'] for d in box_dets]) scores1 = np.array([d['score'] for d in box_dets]) labels1 = np.array([d['category_id'] for d in box_dets]) masks1 = np.array([d['segmentation'] for d in box_dets]) bboxes2 = np.array([d['bbox'] for d in mask_dets]) scores2 = np.array([d['score'] for d in mask_dets]) labels2 = np.array([d['category_id'] for d in mask_dets]) masks2 = np.array([d['segmentation'] for d in mask_dets]) score_argsort = np.argsort(scores1)[::-1] bboxes1 = bboxes1[score_argsort] scores1 = scores1[score_argsort] labels1 = labels1[score_argsort] masks1 = masks1[score_argsort] score_argsort = np.argsort(scores2)[::-1] bboxes2 = bboxes2[score_argsort] scores2 = scores2[score_argsort] labels2 = labels2[score_argsort] masks2 = masks2[score_argsort] order1, order2, n_matched12, _, _ = iou_assoc( bboxes1, labels1, np.arange(len(bboxes1)), 0, bboxes2, labels2, opts.match_iou_th, no_unmatched1=False, ) bboxes1 = bboxes1[order1] scores1 = scores1[order1] labels1 = labels1[order1] masks1 = masks1[order1] bboxes2 = bboxes2[order2] scores2 = scores2[order2] labels2 = labels2[order2] masks2 = masks2[order2] mask1_fix = warp_mask_to_box( masks2[:n_matched12], bboxes2[:n_matched12], bboxes1[:n_matched12] ) masks1 = np.concatenate((mask1_fix, masks1[n_matched12:])) if vis_out: img_path = join(opts.data_root, seq_dirs[sid], img_name) I = imread(img_path) vis_path = join(opts.vis_dir, seq_name, img_name[:-3] + 'jpg') bboxes = ltwh2ltrb(bboxes1) if len(bboxes1) else [] if opts.overwrite or not isfile(vis_path): vis_det( I, bboxes, labels1, class_names, masks1, scores1, out_scale=opts.vis_scale, out_file=vis_path ) n = len(bboxes1) for i in range(n): result_dict = { 'image_id': iid, 'bbox': bboxes1[i], 'score': scores1[i], 'category_id': labels1[i], } if masks1 is not None: result_dict['segmentation'] = masks1[i] results_ccf.append(result_dict) out_path = join(opts.out_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(opts.out_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if opts.eval_mask: print('Evaluating instance segmentation') eval_summary = eval_ccf(db, results_ccf, iou_type='segm') out_path = join(opts.out_dir, 'eval_summary_mask.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}"')
def main(): assert torch.cuda.device_count() == 1 # mmdet only supports single GPU testing opts = parse_args() mkdir2(opts.out_dir) vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) n_class = len(db.cats) seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] if 'KMOTS' in opts.data_root: class_mapping = coco2kmots class_names = kmots_classes elif 'ArgoVerse' in opts.data_root: class_mapping = coco2av class_names = av_classes else: raise Exception('Unknown dataset') config = mmcv.Config.fromfile(opts.config) if opts.in_scale is not None: config.data.test.img_scale = opts.in_scale # mainly for SSD config.data.test.resize_keep_ratio = True if opts.no_mask: if 'mask_head' in config.model: config.model['mask_head'] = None model = init_detector(config, opts.weights) model.eval() results_ccf = [] for iid, img in tqdm(db.imgs.items()): img_name = img['name'] sid = img['sid'] seq_name = seqs[sid] img_path = join(opts.data_root, seq_dirs[sid], img_name) I = mmcv.imread(img_path) if iid % opts.det_stride == 0: result = inference_detector(model, I) bboxes, scores, labels, masks = parse_mmdet_result(result, class_mapping, n_class) if len(bboxes): bboxes_ltwh = bboxes.copy() # convert to coco fmt bboxes_ltwh[:, 2:] -= bboxes_ltwh[:, :2] bboxes_ltwh = bboxes_ltwh.tolist() else: bboxes_ltwh = [] if vis_out: vis_path = join(opts.vis_dir, seq_name, img_name[:-3] + 'jpg') if opts.overwrite or not isfile(vis_path): vis_det( I, bboxes, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path ) for i in range(len(bboxes_ltwh)): result_dict = { 'image_id': iid, 'bbox': bboxes_ltwh[i], 'score': scores[i], 'category_id': labels[i], } if masks is not None: result_dict['segmentation'] = masks[i] results_ccf.append(result_dict) out_path = join(opts.out_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(opts.out_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}"')
def main(): assert torch.cuda.device_count( ) == 1 # mmdet only supports single GPU testing opts = parse_args() mkdir2(opts.out_dir) vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) class_names = [c['name'] for c in db.dataset['categories']] n_class = len(class_names) coco_mapping = None if opts.no_class_mapping else db.dataset.get( 'coco_mapping', None) if coco_mapping is not None: coco_mapping = np.asarray(coco_mapping) seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] model = init_detector(opts) if opts.weights_base is not None: # for distillation purpose load_checkpoint(model, opts.weights_base) if opts.cpu_pre: img_transform = ImageTransform( size_divisor=model.cfg.data.test.size_divisor, **model.cfg.img_norm_cfg) else: img_transform = ImageTransformGPU( size_divisor=model.cfg.data.test.size_divisor, **model.cfg.img_norm_cfg) device = next(model.parameters()).device # model device n_history = model.cfg.data.train.n_history if opts.n_history is None else opts.n_history n_future = model.cfg.data.train.n_future if opts.n_future is None else opts.n_future results_ccf = [] # instance based runtime_all = [] for sid, seq in enumerate(tqdm(seqs)): # print(seq) frame_list = [img for img in db.imgs.values() if img['sid'] == sid] n_frame = len(frame_list) # load all frames in advance frames = [] for img in frame_list: img_path = join(opts.data_root, seq_dirs[sid], img['name']) frames.append(imread(img_path)) with torch.no_grad(): preprocessed = [] for i in range(n_history): data = _prepare_data(frames[i], img_transform, model.cfg, device) preprocessed.append(data) for ii in range(n_history, n_frame - n_future): # target frame iid = frame_list[ii + n_future]['id'] img_name = frame_list[ii + n_future]['name'] I = frames[ii + n_future] t_start = perf_counter() # input frame data = _prepare_data(frames[ii], img_transform, model.cfg, device) # if n_history == 0: # data_merge = data # # print(data['img']) # # print(data['img'][0].shape) # # print(data['img'][0][0][0][300][300:305]) # # import sys # # sys.exit() # else: preprocessed.append(data) # print(preprocessed[0]['img'][0].data_ptr()) # print(preprocessed[2]['img'][0].data_ptr()) # print(torch.all(preprocessed[0]['img'][0] == preprocessed[2]['img'][0])) imgs = [d['img'][0] for d in preprocessed] imgs = torch.cat(imgs, 0) imgs = imgs.unsqueeze(0) data_merge = { 'img': [imgs], 'img_meta': data['img_meta'], } # print(data_merge['img'][0][0][2][0][300][300:305]) # import sys # sys.exit() result = model(return_loss=False, rescale=True, numpy_res=True, **data_merge) bboxes, scores, labels, masks = \ parse_det_result(result, coco_mapping, n_class) # if ii == 2: # print(ii, scores) # import sys # sys.exit() # if n_history != 0: del preprocessed[0] t_end = perf_counter() runtime_all.append(t_end - t_start) if vis_out: vis_path = join(opts.vis_dir, seq, img_name[:-3] + 'jpg') if opts.overwrite or not isfile(vis_path): vis_det(I, bboxes, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path) # convert to coco fmt n = len(bboxes) if n: bboxes[:, 2:] -= bboxes[:, :2] for i in range(n): result_dict = { 'image_id': iid, 'bbox': bboxes[i], 'score': scores[i], 'category_id': labels[i], } if masks is not None: result_dict['segmentation'] = masks[i] results_ccf.append(result_dict) out_path = join(opts.out_dir, 'time_info.pkl') if opts.overwrite or not isfile(out_path): pickle.dump({ 'runtime_all': runtime_all, 'n_total': len(runtime_all), }, open(out_path, 'wb')) # convert to ms for display s2ms = lambda x: 1e3 * x print_stats(runtime_all, 'Runtime (ms)', cvt=s2ms) out_path = join(opts.out_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(opts.out_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}"')
def main(): opts = parse_args() mkdir2(opts.out_dir) vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) class_names = [c['name'] for c in db.dataset['categories']] assert class_names[5] == 'truck' assert class_names[2] == 'car' seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] in_ccf = pickle.load(open(join(opts.in_dir, 'results_ccf.pkl'), 'rb')) results_ccf = [] i_start = 0 for sid, seq in enumerate(tqdm(seqs)): # if seq != '5ab2697b-6e3e-3454-a36a-aba2c6f27818': # continue frame_list = [img for img in db.imgs.values() if img['sid'] == sid] for ii, img in enumerate(frame_list): iid = img['id'] i_end = i_start while i_end < len(in_ccf) and in_ccf[i_end]['image_id'] == iid: i_end += 1 dets = in_ccf[i_start:i_end] i_start = i_end # dets = [r for r in in_ccf if r['image_id'] == img['id']] bboxes = np.array([d['bbox'] for d in dets]) labels = np.array([d['category_id'] for d in dets]) scores = np.array([d['score'] for d in dets]) with_mask = len(dets) and 'segmentation' in dets[0] if with_mask: masks = np.array([d['segmentation'] for d in dets]) score_argsort = np.argsort(scores)[::-1] bboxes = bboxes[score_argsort] scores = scores[score_argsort] labels = labels[score_argsort] if with_mask: masks = masks[score_argsort] remove_idx = remove_car_for_pickup(bboxes, labels, scores) bboxes = np.delete(bboxes, remove_idx, 0) labels = np.delete(labels, remove_idx, 0) scores = np.delete(scores, remove_idx, 0) if with_mask: masks = np.delete(masks, remove_idx, 0) n = len(bboxes) for i in range(n): result_dict = { 'image_id': img['id'], 'bbox': bboxes[i], 'score': scores[i], 'category_id': labels[i], } if with_mask: result_dict['segmentation'] = masks[i] results_ccf.append(result_dict) if vis_out: img_path = join(opts.data_root, seq_dirs[sid], img['name']) I = imread(img_path) vis_path = join(opts.vis_dir, seq, img['name'][:-3] + 'jpg') bboxes_ltrb = bboxes.copy() if len(bboxes_ltrb): bboxes_ltrb[:, 2:] += bboxes_ltrb[:, :2] if opts.overwrite or not isfile(vis_path): vis_det(I, bboxes_ltrb, labels, class_names, masks if with_mask else None, scores, out_scale=opts.vis_scale, out_file=vis_path) out_path = join(opts.out_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(opts.out_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}" --fps 30')
def main(): opts = parse_args() vis_out = bool(opts.vis_dir) if vis_out: mkdir2(opts.vis_dir) db = COCO(opts.annot_path) seqs = db.dataset['sequences'] seq_dirs = db.dataset['seq_dirs'] class_names = [c['name'] for c in db.dataset['categories']] n_class = len(class_names) print('Merging results') results_ccf = [] in_time = 0 miss = 0 shifts = 0 for sid, seq in enumerate(tqdm(seqs)): frame_list = [img for img in db.imgs.values() if img['sid'] == sid] results, timestamps, input_fidx, _ = pickle.load(open(join(opts.result_dir, seq + '.pkl'), 'rb')) tidx_p1 = 0 for i, img in enumerate(frame_list): # pred, gt association by time if vis_out: img_path = join(opts.data_root, seq_dirs[sid], img['name']) I = mmcv.imread(img_path) vis_path = join(opts.vis_dir, seq, img['name'][:-3] + 'jpg') t = (i + 1)/opts.fps while tidx_p1 < len(timestamps) and timestamps[tidx_p1] <= t: tidx_p1 += 1 if tidx_p1 == 0: # no output miss += 1 if vis_out: if opts.vis_scale != 1: I = mmcv.imrescale(I, opts.vis_scale, interpolation='bilinear') mmcv.imwrite(I, vis_path) continue tidx = tidx_p1 - 1 result = results[tidx] ifidx = input_fidx[tidx] in_time += int(i == ifidx) shifts += i - ifidx bboxes = result['bboxes'] scores = result['scores'] labels = result['labels'] masks = result['masks'] if 'masks' in result else None tracks = result['tracks'] if 'tracks' in result else None if vis_out: if opts.overwrite or not isfile(vis_path): if tracks is None: vis_det( I, bboxes, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path, score_th=0, ) else: vis_track( I, bboxes, tracks, labels, class_names, masks, scores, out_scale=opts.vis_scale, out_file=vis_path, score_th=0, ) # convert to coco fmt bboxes_ltwh = bboxes.copy() if len(bboxes_ltwh): bboxes_ltwh[:, 2:] -= bboxes_ltwh[:, :2] bboxes_ltwh = bboxes_ltwh.tolist() for j in range(len(bboxes_ltwh)): result_dict = { 'image_id': img['id'], 'bbox': bboxes_ltwh[j], 'score': scores[j], 'category_id': labels[j], } if masks is not None: result_dict['segmentation'] = masks[j] results_ccf.append(result_dict) out_path = join(opts.result_dir, 'results_ccf.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(results_ccf, open(out_path, 'wb')) out_path = join(opts.result_dir, 'time_extra.txt') if opts.overwrite or not isfile(out_path): np.savetxt(out_path, [miss, in_time, shifts], fmt='%d') if not opts.no_eval: eval_summary = eval_ccf(db, results_ccf) out_path = join(opts.result_dir, 'eval_summary.pkl') if opts.overwrite or not isfile(out_path): pickle.dump(eval_summary, open(out_path, 'wb')) if vis_out: print(f'python vis/make_videos.py "{opts.vis_dir}" --fps {opts.fps}')