compute_score_running_avg

ketos.neural_networks.dev_utils.detection.compute_score_running_avg(scores, window_size)[source]

This function calculates the running average of a given list of scores, over a defined window size.

Each element i in the output represents the running average of the elements in the scores from position i - window_size//2 to i + window_size//2.

This function pads the scores with the edge values of input to calculate the average for the edges.

Args:
scores: list or numpy array

A 1D, 2D or 3D sequence of numerical scores.

window_size: int

The size of the window in frames to compute the running average. Must be an odd integer

Returns:
numpy array

A sequence of running averages, with the same length as the input.

Example:

>>> compute_score_running_avg([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)
array([1.33333333, 2.        , 3.        , 4.        , 5.        ,
       6.        , 7.        , 8.        , 9.        , 9.66666667])
>>> compute_score_running_avg([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], 3)
array([[1.33333333, 1.33333333],
       [2.        , 2.        ],
       [3.        , 3.        ],
       [4.        , 4.        ],
       [4.66666667, 4.66666667]])
>>> np.random.seed(0)
>>> scores = np.random.rand(6, 4)
>>> compute_score_running_avg(scores, 3)
array([[0.50709394, 0.69209095, 0.54770465, 0.66051312],
       [0.64537702, 0.58150833, 0.61069188, 0.6551837 ],
       [0.65178737, 0.65164409, 0.43344944, 0.50259907],
       [0.51730857, 0.713886  , 0.54697262, 0.49534546],
       [0.52229377, 0.85245835, 0.43689072, 0.57922354],
       [0.65915169, 0.81031232, 0.56703849, 0.81035683]])