File size: 4,380 Bytes
128e4f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import argparse
import sys, os
import numpy as np

import project_subpath
from backend.InferenceConfig import InferenceConfig

from detection_to_tracks import main as track

current_dir = os.path.dirname(os.path.realpath(__file__))
pardir = os.path.dirname(current_dir)
sys.path.append(os.path.join(pardir, "../caltech-fish-counting/"))
from evaluate import evaluate

class Object(object):
    pass

def main(args):
    """
    Perform tracking on a directory of raw detections, saves the tracks, and runs the 'evaluate' script from the 'caltech-fish-counting' repo
    Args:
        detection_dir (str): path to raw detection directory
        weights (str): path to weights
        conf_threshold (float): confidence cutoff for detection filtering
        nms_iou (float): non-maximum suppression IOU threshold
        min_length (float): minimum length of fish in meters in order to count
        max_length (float): maximum length of fish in meters in order to count. Disable with 0
        min_travel (float): minimum travel distance in meters of track in order to count
        max_age (int): aximum time between detections before a fish is forgotten by the tracker
        min_hits (int): minimum length of track in frames in order to count
        associativity (str): string representation of tracking method with corresponding hyperparameters separated by ':'
        verbose (bool): disable or enable logging
    """

    infer_args = Object()
    infer_args.detections = args.detection_dir
    infer_args.metadata = "../frames/metadata"
    infer_args.output = "../frames/result_testing"
    infer_args.tracker = 'tracker'
    infer_args.location = 'kenai-val'

    config = InferenceConfig(
        conf_thresh=float(args.conf_threshold),
        nms_iou=float(args.nms_iou),
        min_hits=int(args.min_hits),
        max_age=int(args.max_age),
        min_length=float(args.min_length),
        max_length=float(args.max_length),
        min_travel=float(args.min_travel),
    )

    config.enable_tracker_from_string(args.associativity)

    print("verbose", args.verbose)

    track(infer_args, config=config, verbose=args.verbose)

    result = evaluate(infer_args.output, "../frames/MOT", "../frames/metadata", infer_args.tracker, True, location=infer_args.location)
    metrics = result['MotChallenge2DBox']['tracker']['COMBINED_SEQ']['pedestrian']
    print('HOTA:', np.mean(metrics['HOTA']['HOTA'])*100)
    print('MOTA:', metrics['CLEAR']['MOTA']*100)
    print('IDF1:', metrics['Identity']['IDF1']*100)
    print('nMAE:', metrics['nMAE']['nMAE']*100)
    print('misscounts:', str(metrics['nMAE']['nMAE_numer']) + "/" + str(metrics['nMAE']['nMAE_denom']))
    return result


def argument_parser():
    default = InferenceConfig()
    parser = argparse.ArgumentParser()
    parser.add_argument("--detection_dir", default="../frames/detection_storage", help="Path to raw detection directory")
    parser.add_argument("--weights", default=default.weights,               help="Path to weights")
    parser.add_argument("--conf_threshold", default=default.conf_thresh,    help="Confidence cutoff for detection filtering")
    parser.add_argument("--nms_iou", default=default.nms_iou,               help="Non-maximum Suppression IOU threshold")
    parser.add_argument("--min_length", default=default.min_length,         help="Minimum length of fish in meters in order to count")
    parser.add_argument("--max_length", default=default.max_length,         help="Maximum length of fish in meters in order to count. Disable with 0")
    parser.add_argument("--min_travel", default=default.min_travel,         help="Minimum travel distance in meters of track in order to count.")
    parser.add_argument("--max_age", default=default.max_age,               help="Maximum time between detections before a fish is forgotten by the tracker")
    parser.add_argument("--min_hits", default=default.min_hits,             help="Minimum length of track in frames in order to count")
    parser.add_argument("--associativity", default='',                      help="String representation of tracking method with corresponding hyperparameters separated by ':'")
    parser.add_argument("--verbose", action='store_true',                   help="Disable or enable logging")
    return parser

if __name__ == "__main__":
    args = argument_parser().parse_args()
    main(args)