pyEdgeEval.common.binary_label package

Submodules

pyEdgeEval.common.binary_label.calculate_metrics module

pyEdgeEval.common.binary_label.calculate_metrics.calculate_metrics(eval_single, thresholds, samples, nproc=8)[source]

Main function to calculate boundary metrics

Parameters
  • eval_single (Callable) – function that takes samples (dict) as input

  • thresholds (int, float, list, np.ndarray) – thresholds used for evaluation

  • samples (dict) – list of dicts containing file paths and evaluation parameters

  • nproc – integer that specifies the number of processes to spawn

Returns

dict of results

pyEdgeEval.common.binary_label.evaluate_boundaries module

pyEdgeEval.common.binary_label.evaluate_boundaries.evaluate_boundaries_threshold(thresholds: ndarray, pred: ndarray, gt: ndarray, max_dist: float = 0.0075, apply_thinning: bool = True, apply_nms: bool = False, nms_kwargs={'half_prec': False, 'm': 1.01, 'r': 1, 's': 5})[source]

Evaluate the accuracy of a predicted boundary and a range of thresholds

  • Single GT

Parameters
  • thresholds – a 1D array specifying the thresholds

  • pred – the predicted boundaries as a (H,W) floating point array where each pixel represents the strength of the predicted boundary

  • gts – list of ground truth boundary, as returned by the load_boundary or boundary methods

  • max_dist – (default=0.02) maximum distance parameter used for determining pixel matches. This value is multiplied by the length of the diagonal of the image to get the threshold used for matching pixels.

  • apply_thinning – (default=True) if True, apply morphologial thinning to the predicted boundaries before evaluation

  • apply_nms – (default=False) apply a fast nms preprocess

  • nms_kwargs – arguments for nms process

Returns

tuple (count_r, sum_r, count_p, sum_p, thresholds) where each

of the first four entries are arrays that can be used to compute recall and precision at each threshold with: ` recall = count_r / (sum_r + (sum_r == 0)) precision = count_p / (sum_p + (sum_p == 0)) `

pyEdgeEval.common.binary_label.evaluate_boundaries.evaluate_boundaries_threshold_multiple_gts(thresholds: ndarray, pred: ndarray, gts: ndarray, max_dist: float = 0.0075, apply_thinning: bool = True, apply_nms: bool = False, nms_kwargs={'half_prec': False, 'm': 1.01, 'r': 1, 's': 5})[source]

Evaluate the accuracy of a predicted boundary and a range of thresholds

  • Assumes that there are multiple GTs

Parameters
  • thresholds – a 1D array specifying the thresholds

  • pred – the predicted boundaries as a (H,W) floating point array where each pixel represents the strength of the predicted boundary

  • gts – list of ground truth boundary, as returned by the load_boundary or boundary methods

  • max_dist – (default=0.02) maximum distance parameter used for determining pixel matches. This value is multiplied by the length of the diagonal of the image to get the threshold used for matching pixels.

  • apply_thinning – (default=True) if True, apply morphologial thinning to the predicted boundaries before evaluation

  • apply_nms – (default=False) apply a fast nms preprocess

  • nms_kwargs – arguments for nms process

Returns

tuple (count_r, sum_r, count_p, sum_p, thresholds) where each

of the first four entries are arrays that can be used to compute recall and precision at each threshold with: ` recall = count_r / (sum_r + (sum_r == 0)) precision = count_p / (sum_p + (sum_p == 0)) `

pyEdgeEval.common.binary_label.io module

pyEdgeEval.common.binary_label.io.save_sample_metrics(root_dir: str, sample_metrics, file_name: str = 'eval_bdry_img.txt')[source]
pyEdgeEval.common.binary_label.io.save_threshold_metrics(root_dir: str, threshold_metrics, file_name: str = 'eval_bdry_thr.txt')[source]
pyEdgeEval.common.binary_label.io.save_overall_metric(root_dir: str, overall_metric, file_name: str = 'eval_bdry.txt')[source]
pyEdgeEval.common.binary_label.io.save_results(root: str, sample_metrics, threshold_metrics, overall_metric)[source]

Save results

pyEdgeEval.common.binary_label.visualize module

Try to mimic the original MATLAB PR Curves Reference: https://github.com/xwjabc/hed/blob/master/eval/edges/edgesEvalPlot.m

pyEdgeEval.common.binary_label.visualize.plot_pr_curve(algs, names=None, colors=None, plot_human: bool = True, save_path=None)[source]

Module contents

pyEdgeEval.common.binary_label.calculate_metrics(eval_single, thresholds, samples, nproc=8)[source]

Main function to calculate boundary metrics

Parameters
  • eval_single (Callable) – function that takes samples (dict) as input

  • thresholds (int, float, list, np.ndarray) – thresholds used for evaluation

  • samples (dict) – list of dicts containing file paths and evaluation parameters

  • nproc – integer that specifies the number of processes to spawn

Returns

dict of results

pyEdgeEval.common.binary_label.evaluate_boundaries_threshold(thresholds: ndarray, pred: ndarray, gt: ndarray, max_dist: float = 0.0075, apply_thinning: bool = True, apply_nms: bool = False, nms_kwargs={'half_prec': False, 'm': 1.01, 'r': 1, 's': 5})[source]

Evaluate the accuracy of a predicted boundary and a range of thresholds

  • Single GT

Parameters
  • thresholds – a 1D array specifying the thresholds

  • pred – the predicted boundaries as a (H,W) floating point array where each pixel represents the strength of the predicted boundary

  • gts – list of ground truth boundary, as returned by the load_boundary or boundary methods

  • max_dist – (default=0.02) maximum distance parameter used for determining pixel matches. This value is multiplied by the length of the diagonal of the image to get the threshold used for matching pixels.

  • apply_thinning – (default=True) if True, apply morphologial thinning to the predicted boundaries before evaluation

  • apply_nms – (default=False) apply a fast nms preprocess

  • nms_kwargs – arguments for nms process

Returns

tuple (count_r, sum_r, count_p, sum_p, thresholds) where each

of the first four entries are arrays that can be used to compute recall and precision at each threshold with: ` recall = count_r / (sum_r + (sum_r == 0)) precision = count_p / (sum_p + (sum_p == 0)) `

pyEdgeEval.common.binary_label.evaluate_boundaries_threshold_multiple_gts(thresholds: ndarray, pred: ndarray, gts: ndarray, max_dist: float = 0.0075, apply_thinning: bool = True, apply_nms: bool = False, nms_kwargs={'half_prec': False, 'm': 1.01, 'r': 1, 's': 5})[source]

Evaluate the accuracy of a predicted boundary and a range of thresholds

  • Assumes that there are multiple GTs

Parameters
  • thresholds – a 1D array specifying the thresholds

  • pred – the predicted boundaries as a (H,W) floating point array where each pixel represents the strength of the predicted boundary

  • gts – list of ground truth boundary, as returned by the load_boundary or boundary methods

  • max_dist – (default=0.02) maximum distance parameter used for determining pixel matches. This value is multiplied by the length of the diagonal of the image to get the threshold used for matching pixels.

  • apply_thinning – (default=True) if True, apply morphologial thinning to the predicted boundaries before evaluation

  • apply_nms – (default=False) apply a fast nms preprocess

  • nms_kwargs – arguments for nms process

Returns

tuple (count_r, sum_r, count_p, sum_p, thresholds) where each

of the first four entries are arrays that can be used to compute recall and precision at each threshold with: ` recall = count_r / (sum_r + (sum_r == 0)) precision = count_p / (sum_p + (sum_p == 0)) `

pyEdgeEval.common.binary_label.save_results(root: str, sample_metrics, threshold_metrics, overall_metric)[source]

Save results

pyEdgeEval.common.binary_label.save_sample_metrics(root_dir: str, sample_metrics, file_name: str = 'eval_bdry_img.txt')[source]
pyEdgeEval.common.binary_label.save_threshold_metrics(root_dir: str, threshold_metrics, file_name: str = 'eval_bdry_thr.txt')[source]
pyEdgeEval.common.binary_label.save_overall_metric(root_dir: str, overall_metric, file_name: str = 'eval_bdry.txt')[source]