Skip to content

thresholdfilter

thresholdfilter

Module for ThresholdFilter

Classes

ThresholdFilter

Bases: PredictionFilter

Removes all predictions lower than score_threshold

Functions
filter
filter(prediction_array_xywh)

Filters the prediction in array according to given filter conditions Args: prediction_array_xywh: prediction array in format [y,x,width,height]

Returns:

  • ndarray

    filtered prediction array

Source code in niceml/utilities/boundingboxes/filtering/thresholdfilter.py
def filter(self, prediction_array_xywh: np.ndarray) -> np.ndarray:
    """
    Filters the prediction in array according to given filter conditions
    Args:
        prediction_array_xywh: prediction array in format [y,x,width,height]

    Returns:
        filtered prediction array
    """
    scores = prediction_array_xywh[
        :, self.coordinates_count : self.coordinates_count + self.output_class_count
    ]
    max_vals = np.max(scores, axis=1)
    filtered_array = prediction_array_xywh[max_vals >= self.score_threshold, :]
    if (
        self.max_output_count is None
        or filtered_array.shape[0] <= self.max_output_count
    ):
        return filtered_array
    max_vals = max_vals[max_vals >= self.score_threshold]
    sorted_scores_idxes = max_vals.argsort()[::-1][: self.max_output_count]
    return filtered_array[sorted_scores_idxes, :]