示例#1
0
 def get_sequence_list(self):
     file_path = self.env_settings.oxuva_list
     with open(file_path, "r") as f:
         tasks = oxuva.load_dataset_tasks_csv(f)
     self.tasks = tasks
     return SequenceList(
         [self._construct_sequence(s) for s in tasks.keys()])
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    _add_arguments(parser)
    args = parser.parse_args()
    logging.basicConfig(level=getattr(logging, args.loglevel.upper()))

    tasks_file = os.path.join(DATA_DIR, 'tasks', args.data + '.csv')
    images_dir = os.path.join(DATA_DIR, 'images', args.data)
    predictions_dir = os.path.join('predictions', args.data, args.tracker)
    output_dir = os.path.join('visualize', args.data, args.tracker)
    if not os.path.exists(output_dir):
        os.makedirs(output_dir, 0o755)

    with open(tasks_file, 'r') as fp:
        tasks = oxuva.load_dataset_tasks_csv(fp)

    for i, (key, task) in enumerate(sorted(tasks.items())):
        vid, obj = key
        logger.info('task %d/%d: (%s, %s)', i + 1, len(tasks), vid, obj)
        video_file = os.path.join(output_dir, '{}_{}.mp4'.format(vid, obj))
        if os.path.exists(video_file):
            logger.debug('skip %s %s: already exists', vid, obj)
            continue
        try:
            predictions_file = os.path.join(predictions_dir,
                                            '{}_{}.csv'.format(vid, obj))
            with open(predictions_file, 'r') as fp:
                predictions = oxuva.load_predictions_csv(fp)
            image_file_func = lambda t: os.path.join(images_dir, vid,
                                                     '{:06d}.jpeg'.format(t))
            output_file = os.path.join(output_dir,
                                       '{}_{}.mp4'.format(vid, obj))
            _visualize_video(task, predictions, image_file_func, output_file)
        except (IOError, subprocess.CalledProcessError) as ex:
            logger.warning('could not visualize %s %s: %s', vid, obj, ex)
示例#3
0
 def __init__(self, root_dir, subset="test"):
     super().__init__()
     self.root_dir = root_dir
     self.subset = subset
     task_file = os.path.join(root_dir, "tasks", subset + ".csv")
     with open(task_file) as f:
         import oxuva
         self._tasks = oxuva.load_dataset_tasks_csv(f)
     self.seq_names = [t[0] + "___" + t[1] for t in self._tasks]
示例#4
0
文件: track.py 项目: willtwr/iSiam-TF
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('data_dir')
    parser.add_argument('predictions_dir')
    parser.add_argument('--data', default='dev')
    parser.add_argument('--verbose', '-v', action='store_true')
    parser.add_argument('--tracker', default='TLD')
    global args
    args = parser.parse_args()

    tracker_id = 'cv' + args.tracker
    tracker_preds_dir = os.path.join(args.predictions_dir, args.data, tracker_id)
    if not os.path.exists(tracker_preds_dir):
        os.makedirs(tracker_preds_dir, 0755)

    tasks_file = os.path.join(args.data_dir, 'tasks', args.data + '.csv')
    with open(tasks_file, 'r') as fp:
        tasks = oxuva.load_dataset_tasks_csv(fp)
    # tracks_file = os.path.join(args.data_dir, 'annotations', args.data + '.csv')
    # with open(tracks_file, 'r') as fp:
    #     tracks = oxuva.load_annotations_csv(fp)
    # tasks = {key: oxuva.make_task_from_track(track) for key, track in tracks.items()}

    imfile = lambda vid, t: os.path.join(
        args.data_dir, 'images', args.data, vid, '{:06d}.jpeg'.format(t))

    tracker = Tracker(tracker_type=args.tracker)
    
    for key, task in tasks.items():
        vid, obj = key
        if args.verbose:
            print(vid, obj)
        preds_file = os.path.join(tracker_preds_dir, '{}_{}.csv'.format(vid, obj))
        if os.path.exists(preds_file):
            continue

        tracker.init(imfile(vid, task.init_time), task.init_rect)
        preds = oxuva.SparseTimeSeries()
        start = time.time()
        for t in range(task.init_time + 1, task.last_time + 1):
            preds[t] = tracker.next(imfile(vid, t))
        dur_sec = time.time() - start
        if args.verbose:
            fps = (task.last_time - task.init_time + 1) / dur_sec
            print('fps {:.3g}'.format(fps))

        tmp_preds_file = os.path.join(tracker_preds_dir, '{}_{}.csv.tmp'.format(vid, obj))
        with open(tmp_preds_file, 'w') as fp:
            oxuva.dump_predictions_csv(vid, obj, preds, fp)
        os.rename(tmp_preds_file, preds_file)
def main():
    # runs = 5
    runs = 1
    score_thr = 0.3

    once_flag = True
    choice = 4

    tracker = "fstar"
    rst_name = "oxuva_000"
    base_dir = "/data/home/v-hongyuan/projects/lt_tracking/test/tracking_results_bak/"

    file_path = "/data/home/v-had/github/long-term-tracking-benchmark/dataset/tasks/test.csv"
    dataset_path = "/data/home/v-had/github/long-term-tracking-benchmark/dataset/images/test"

    save_base_dir = "./fstar_oxuva/"
    with open(file_path, "r") as f: tasks = oxuva.load_dataset_tasks_csv(f)

    for i in range(runs):
        if once_flag and i > 0: break
        if once_flag: i = choice
        print("Generating {}_0{:02d}".format(rst_name, i))
        # rst_dir = os.path.join(base_dir, tracker, "{}_0{:02d}".format(rst_name, i))
        rst_dir = os.path.join(base_dir, tracker, rst_name)
        # save_dir = os.path.join(save_base_dir, "{}_0{:02d}_thr_{}".format(rst_name, i, score_thr)).replace('.', '_')
        save_dir = save_base_dir
        if not os.path.exists(save_dir): os.mkdir(save_dir)
        keys = tasks.keys()
        for key in keys:
            vid, obj = key
            b_file = os.path.join(rst_dir, "{}_{}.txt".format(vid, obj))
            s_file = os.path.join(rst_dir, "{}_{}_score.txt".format(vid, obj))
            bbox, scores = [], []
            with open(b_file, "r") as f:
                for line in f:
                    anno = line.split("\t")
                    anno[-1] = anno[-1].split("\n")[0]
                    anno = [float(x) for x in anno]
                    bbox.append(anno)
            with open(s_file, "r") as f:
                for idx, line in enumerate(f):
                    if idx == 0: continue
                    anno = line.split("\n")[0]
                    scores.append(float(anno))

            im_path = os.path.join(dataset_path, "{}".format(vid), "000000.jpeg")
            im = cv2.imread(im_path)
            im_height, im_width = im.shape[0], im.shape[1]

            preds = oxuva.SparseTimeSeries()
            for idx, score in enumerate(scores):
                rect = np.array(bbox[idx])
                rect = rect_from_opencv(rect, imsize_hw=(im_height, im_width))
                if score > score_thr:
                    preds[idx] = oxuva.make_prediction(present=True, score=score, **rect)
                else:
                    preds[idx] = oxuva.make_prediction(present=False, score=0)

            pred_file_path = os.path.join(save_dir, "{}_{}.csv".format(vid, obj))
            with open(pred_file_path, 'w') as fp:
                oxuva.dump_predictions_csv(vid, obj, preds, fp)
示例#6
0
def _load_tasks(fname):
    logger.debug('load tasks without annotations from "%s"', fname)
    with open(fname, 'r') as fp:
        return oxuva.load_dataset_tasks_csv(fp)
示例#7
0
def main():
    tracker_id = 'siamrp_lt'
    tracker_preds_dir = os.path.join(FLAGS.predictions_dir, FLAGS.data,
                                     tracker_id)
    if not os.path.exists(tracker_preds_dir):
        os.makedirs(tracker_preds_dir, 0o0755)

    tasks_file = os.path.join(FLAGS.data_dir, 'tasks', FLAGS.data + '.csv')
    with open(tasks_file, 'r') as fp:
        tasks = oxuva.load_dataset_tasks_csv(fp)
    # tracks_file = os.path.join(args.data_dir, 'annotations', args.data + '.csv')
    # with open(tracks_file, 'r') as fp:
    #     tracks = oxuva.load_annotations_csv(fp)
    # tasks = {key: oxuva.make_task_from_track(track) for key, track in tracks.items()}

    imfile = lambda vid, t: os.path.join(FLAGS.data_dir, 'images', FLAGS.data,
                                         vid, '{:06d}.jpeg'.format(t))

    for key, task in tasks.items():
        vid, obj = key
        if FLAGS.verbose:
            print(vid, obj)
        preds_file = os.path.join(tracker_preds_dir,
                                  '{}_{}.csv'.format(vid, obj))
        if os.path.exists(preds_file):
            continue

        im = cv2.imread(imfile(vid, task.init_time), cv2.IMREAD_COLOR)
        im_shape = np.shape(im)

        print(task.init_rect)
        print(im_shape)

        region = {
            'x':
            int(task.init_rect['xmin'] * im_shape[1]),
            'y':
            int(task.init_rect['ymin'] * im_shape[0]),
            'width':
            int((task.init_rect['xmax'] - task.init_rect['xmin']) *
                im_shape[1]),
            'height':
            int((task.init_rect['ymax'] - task.init_rect['ymin']) *
                im_shape[0])
        }

        tracker = SiamRP_LT(image=im, region=region)
        preds = oxuva.SparseTimeSeries()
        start = time.time()
        for t in range(task.init_time + 1, task.last_time + 1):
            im = cv2.imread(imfile(vid, t), cv2.IMREAD_COLOR)
            preds[t] = tracker.track(im)
        dur_sec = time.time() - start
        if FLAGS.verbose:
            fps = (task.last_time - task.init_time + 1) / dur_sec
            print('fps {:.3g}'.format(fps))

        tmp_preds_file = os.path.join(tracker_preds_dir,
                                      '{}_{}.csv.tmp'.format(vid, obj))
        with open(tmp_preds_file, 'w') as fp:
            oxuva.dump_predictions_csv(vid, obj, preds, fp)
        os.rename(tmp_preds_file, preds_file)