Validation¶
Provides classes and functions to validate tracks (Track).
The scores that are calculated and evaluated are defined in Score and ScoreMetrics.
-
class
Validator(truth_dw)[source]¶ Bases:
objectClass to validate
Trackobjects with truth data.It also has some helpers e.g. to check tracks for sanity and remove false positives.
-
__init__(truth_dw)[source]¶ Initialization of class attributes
Parameters: truth_dw ( DataWrapperTruth) – data wrapper with truth data
-
truth= None¶ DataWrapperTruth: theDataWrapperTruthwith truth data
-
remove_false_positives(tracks)[source]¶ Removes tracks with only false positives.
Parameters: tracks (iterable of Track) – iterable structure withTrackReturns: iterable structure with cleaned TrackReturn type: iterable of Track
-
sanity_check(tracks, cam_gap=True)[source]¶ Performs some sanity checks on tracks.
The following checks are performed:
- No duplicate ids in tracks.
- Only one detection per timestamp
- Every detection belongs to one track only
- No unknown detections
- If cam_gap is True a track only has detections from one camera
- Each track id is unique
Parameters: tracks ( listofTrack) – iterable structure withTrack.Keyword Arguments: cam_gap (bool) – flag indicating that a camera switch is a insurmountable gap Returns: tuple containing: Return type: tuple
-
validate(tracks, gap, gap_l=True, gap_r=True, cam_gap=True, val_score_fun=None, val_calc_id_fun=None, check=True)[source]¶ Validates the given
Trackwith truth data.The default score_fun is
validation_score_fun_all(). Use it as primer to implement your own.Parameters: Keyword Arguments: - gap_l (bool) – flag indicating to consider left gap in scoring
- gap_r (bool) – flag indicating consider right gap in scoring
- cam_gap (bool) – flag indicating that a camera switch is a insurmountable gap
- val_score_fun (
func) – function that takes aScoreMetricsand calculatesScore - check (bool) – flag indicating that sanity check should be performed
Returns: the scores for each
Trackas dictionary withScoreobjects and mapping {id => score}Return type:
-
score_track(track_truth, track_test, gap=0, gap_l=True, gap_r=True, cam_id=None)[source]¶ Scores the equality of two
Trackusing local alignment methods.Parameters: Keyword Arguments: - gap (int) – the gap the algorithm should be capable to overcome
- gap_l (bool) – flag indicating to consider left gap in scoring
- gap_r (bool) – flag indicating consider right gap in scoring
- cam_id (int) – limit the scores on one camera
Returns: ScoreMetricstuple with alignment informationReturn type:
-
-
validation_score_fun_all(metrics, gap=0)[source]¶ Scoring function that considers all ids and gaps and calculates the percentage of matches.
Note
Used as default implementation to calculate
Score.value.Parameters: metrics ( ScoreMetrics) –ScoreMetricsto calculate accumulated scoreKeyword Arguments: gap (int) – the gap the algorithm should be capable to overcome Returns: value between 0 (bad) and 1 (good) indicating how good the matching is considered Return type: float
-
convert_validated_to_pandas(validated_results)[source]¶ Converter to convert the result of a
Validatorto a Pandas DataFrame.Parameters: validated_results ( dictofScore) – a dictionary with Score tuples as valuesReturns: a Pandas Dataframe with the score information as columns Return type: pd.DataFrame
-
calc_fragments(dw_truth, gap, cam_gap=True)[source]¶ Calculates some information about the fragments in the truth data.
Parameters: - dw_truth (
DataWrapperTruth) –DataWrapperTruthobject - gap (int) – the gap the algorithm should be capable to overcome
Keyword Arguments: cam_gap (bool) – flag indicating that a camera switch is a insurmountable gap
Returns: tuple containing
Return type: - dw_truth (
-
track_statistics(tracks, scores, validator, gap, cam_gap=True)[source]¶ Calculates some statistics about tracks for validation.
Parameters: Keyword Arguments: cam_gap (bool) – flag indicating that a camera switch is a insurmountable gap
Returns: some metrics about tracks
Return type:
Visualization¶
Provides functions to visualize the validation of tracks.
Warning
The visualizations are not tested by the continuous integration server!
-
validate_plot(tracks, scores, validator, gap=0, cam_gap=True, metric_keys=None)[source]¶ Visualizes the validation of tracks.
- Arguments:
- tracks (list of
Track): Iterable with tracks to validate scores (dict orpd.Dataframe): Result ofValidator.validate()validator (Validator): Validator class to calculate track statistics - Keyword Arguments:
- gap (int): the gap the algorithm should be capable to overcome cam_gap (bool): flag indicating that a camera switch is a insurmountable gap metric_keys (list): Iterable with metric keys that should be shown.
- <<<<<<< HEAD
- Default is
['detections', 'fragments', 'tracks'].
Default is['detections', 'fragments' 'tracks', 'truth_ids'].>>>>>>> 7b6f08c50dd64fdf0248e0472874ef113bf30acf
- Returns:
- tuple: tuple containing figure and axes object from matplotlib
-
plot_fragments(scores, validator, gap, cam_gap=True, interval=5, max_x=None)[source]¶ Visualizes distribution of fragments.
:param scores (dict or
pd.Dataframe: Result ofValidator.validate():param validator: Validator class to calculate track statisticsKeyword Arguments: - gap (int) – the gap the algorithm should be capable to overcome
- cam_gap (bool) – flag indicating that a camera switch is a insurmountable gap
- interval (int) – the interval / size of bins in the histogram
- max_x (int) – upper limit for x axis
Returns: tuple containing figure and axes object from matplotlib
Return type: