예제 #1
0
def track_and_save(det_path, output, save_feature, sort_kwargs):

    detections = np.load(det_path)

    #['image_id', 'category','bb_left', 'bb_top', 'bb_width', 'bb_height', 'conf'] features 512

    categories = np.unique(detections[:, 1].astype(int))

    id_gen = itertools.count(1)
    unique_track_ids = defaultdict(lambda: next(id_gen))

    all_results = []
    #th = 32 ** 2
    for category in categories:
        mask = detections[:, 1].astype(int) == category
        det = detections[mask]

        results = deep_sort_app.run(
            det, **sort_kwargs
        )  #image_id, track_id, bb_left, bb_top, bb_width, bb_height, score, feature
        if len(results) == 0:
            continue

        results = np.array(results).reshape(len(results), -1)
        track_ids = np.array(
            [unique_track_ids[(x, category)] for x in results[:, 1]])
        category_res = np.ones((results.shape[0]), dtype=np.float32) * category
        results_save = np.hstack((results[:, 0:1], track_ids[:, np.newaxis],
                                  results[:, 2:7], category_res[:,
                                                                np.newaxis]))
        if save_feature:
            results_save = np.hstack((results_save, results[:, 7:]))
        all_results.append(results_save)

    all_results = np.concatenate(
        all_results, axis=0
    )  #image_id, track_id, bb_left, bb_top, bb_width, bb_height, score, category
    output.parent.mkdir(exist_ok=True, parents=True)
    np.save(output, all_results)
예제 #2
0
        , default=.3, type=float)
    parser.add_argument(
        "--max-age", help="Maximum number of frames a track will be propogated without a detection ", type=int, default=30)
    parser.add_argument("--track-subset-file", help="much the same as the visualization script, this file should be the frame IDs you want tracked, one per line of a file", default=None)
    parser.add_argument("--dont-display", help="use the visualization", action="store_true", default=False)
    parser.add_argument("--dont-use-unmatched", help="don't use unmatched, low-confidence, and NMS-suppressed detections", action="store_false", default=True) # This is really use-unmatched
    parser.add_argument("--tracker-type", help="which tracker to use, currently 'deep-sort', 'flow-matcher', 'flow-tracker'", type=str, default="deep-sort")
    parser.add_argument("--vis-method", help="pick how to visualize the resultant tracks: `show-all`, `one-track`, `one-gt'", type=str, default="one-track")
    parser.add_argument("--flow-dir", help="Where the flows are located", type=str, default="--flow dir should have been set")
    parser.add_argument("--update-kf", help="update the kalman filter to keep the probablilty mass small", action="store_true", default=False)
    parser.add_argument("--update-hit", help="update hit so tracks don't die until they leave the scence", action="store_true", default=False)
    return parser.parse_args()

if __name__ == "__main__":

    #tools.pdb_on_ctrl_c()
    args = parse_args()

    os.makedirs(args.output_dir, exist_ok=True)
    sequences = os.listdir(args.mot_dir)
    for sequence in sequences:
        print("Running sequence %s" % sequence)
        sequence_dir = os.path.join(args.mot_dir, sequence)
        detection_file = os.path.join(args.detection_dir, "%s.npy" % sequence)
        output_file = os.path.join(args.output_dir, "%s.txt" % sequence)
        video_output_file = os.path.join(args.output_dir, "{}_video.avi".format(sequence))
        deep_sort_app.run(
            sequence_dir, detection_file, output_file, args.min_confidence,
            args.nms_max_overlap, args.min_detection_height,
            args.max_cosine_distance, args.nn_budget, display=(not args.dont_display), stock=args.stock, track_class=args.track_class, max_age=args.max_age, min_iou_overlap=args.min_iou_overlap, track_subset_file=args.track_subset_file, use_unmatched=args.dont_use_unmatched, video_output_file=video_output_file, tracker_type=args.tracker_type, vis_method=args.vis_method, argv=sys.argv, flow_dir=args.flow_dir, update_hit=args.update_hit, update_kf=args.update_kf)
    parser.add_argument(
        "--min_detection_height", help="Threshold on the detection bounding "
        "box height. Detections with height smaller than this value are "
        "disregarded", default=0, type=int)
    parser.add_argument(
        "--nms_max_overlap",  help="Non-maxima suppression threshold: Maximum "
        "detection overlap.", default=1.0, type=float)
    parser.add_argument(
        "--max_cosine_distance", help="Gating threshold for cosine distance "
        "metric (object appearance).", type=float, default=0.2)
    parser.add_argument(
        "--nn_budget", help="Maximum size of the appearance descriptors "
        "gallery. If None, no budget is enforced.", type=int, default=100)
    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()

    os.makedirs(args.output_dir, exist_ok=True)
    sequences = os.listdir(args.mot_dir)
    for sequence in sequences:
        print("Running sequence %s" % sequence)
        sequence_dir = os.path.join(args.mot_dir, sequence)
        detection_file = os.path.join(args.detection_dir, "%s.npy" % sequence)
        output_file = os.path.join(args.output_dir, "%s.txt" % sequence)
        deep_sort_app.run(
            sequence_dir, detection_file, output_file, args.min_confidence,
            args.nms_max_overlap, args.min_detection_height,
            args.max_cosine_distance, args.nn_budget, display=False)