pyEdgeEval.common.multi_label package

Submodules

pyEdgeEval.common.multi_label.calculate_metrics module

pyEdgeEval.common.multi_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

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

  • samples (dict) – list of dicts containing sample info

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

Returns

dict of metrics

pyEdgeEval.common.multi_label.edge_decoding module

Decoding functions for multi-label edges

pyEdgeEval.common.multi_label.edge_decoding.binary_multilabel_decoding(edge_path: str, h: int, w: int, num_classes: int)[source]

Load binary file to edge map

  • Assumes that the input file is a 32-bit array

  • The saved file does not have shape information

  • output type is uint32

TODO: currently not used (deprecated)

pyEdgeEval.common.multi_label.edge_decoding.load_scaled_edge(edge_path: str, scale: float)[source]

Load edge from file and scale it

Returns

edge – PIL.Image.Image (height, width): tuple of int

pyEdgeEval.common.multi_label.edge_decoding.decode_png(edge: Image, num_classes: int)[source]

Decode png format Image into multi-label edge

pyEdgeEval.common.multi_label.edge_decoding.decode_tif(edge: Image, num_classes: int)[source]

Decode tif format Image into multi-label edge

pyEdgeEval.common.multi_label.edge_encoding module

Encoding functions for multi-label edges

  • default: encodes into binary format

  • RGB: encodes into binary format that is compatible with image fs

pyEdgeEval.common.multi_label.edge_encoding.default_multilabel_encoding(edges: ndarray)[source]

Encode multi-label edges to binary format

For now we use uint32 as the base (PIL can save uint32). Therefore, we can save at most 32 classes.

However, RGB encoding is efficient unless you need more classes.

pyEdgeEval.common.multi_label.edge_encoding.rgb_multilabel_encoding(edges: ndarray)[source]

Encode multi-label edges to RGB format

Each channel is 8-bit, so the RGB format can encode the edges into 24-bit (maximum of 24 classes).

This format is useful for training data where edges need to be transformed (compatible with various 3-channel augmentations).

pyEdgeEval.common.multi_label.evaluate_boundaries module

pyEdgeEval.common.multi_label.evaluate_boundaries.evaluate_boundaries_threshold(thresholds: ndarray, pred: ndarray, gt: ndarray, gt_seg: Optional[ndarray] = None, max_dist: float = 0.02, apply_thinning: bool = True, kill_internal: bool = False, skip_if_nonexistent: bool = False, 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

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

  • gt – ground truth boundary, as returned by the load_boundary or boundary methods

  • gt_seg – ground truth segmentation data needed for kill_internal

  • 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

  • kill_internal – (default=True) remove countors inside the segmentation mask

  • skip_if_nonexistent – (default=True) this will skip the evaluation and disregards all false positives if there are no boundaries in the GT

  • 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)) `

NOTE: compared to BSDS500, we don’t have multiple GTs

pyEdgeEval.common.multi_label.io module

pyEdgeEval.common.multi_label.io.save_sample_metrics(root_dir: str, sample_metrics, file_name: str = 'eval_bdry_img.txt')[source]
pyEdgeEval.common.multi_label.io.save_threshold_metrics(root_dir: str, threshold_metrics, file_name: str = 'eval_bdry_thr.txt')[source]
pyEdgeEval.common.multi_label.io.save_overall_metric(root_dir: str, overall_metric, file_name: str = 'eval_bdry.txt')[source]
pyEdgeEval.common.multi_label.io.save_pretty_metrics(root_dir: str, class_table, summary_table, file_name: str = 'results.txt')[source]
pyEdgeEval.common.multi_label.io.save_category_results(root: str, category: int, sample_metrics, threshold_metrics, overall_metric)[source]

Save per-category results

pyEdgeEval.common.multi_label.options module

pyEdgeEval.common.multi_label.options.kill_internal_prediction(pred: ndarray, gt: ndarray, seg: ndarray, max_dist: float = 0.02) ndarray[source]

Remove predicted pixels inside boundaries

NOTE: the distance transform may differ from MATLAB implementation NOTE: might not work correctly when using instance sensitive boundaries

Module contents

pyEdgeEval.common.multi_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

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

  • samples (dict) – list of dicts containing sample info

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

Returns

dict of metrics

pyEdgeEval.common.multi_label.evaluate_boundaries_threshold(thresholds: ndarray, pred: ndarray, gt: ndarray, gt_seg: Optional[ndarray] = None, max_dist: float = 0.02, apply_thinning: bool = True, kill_internal: bool = False, skip_if_nonexistent: bool = False, 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

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

  • gt – ground truth boundary, as returned by the load_boundary or boundary methods

  • gt_seg – ground truth segmentation data needed for kill_internal

  • 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

  • kill_internal – (default=True) remove countors inside the segmentation mask

  • skip_if_nonexistent – (default=True) this will skip the evaluation and disregards all false positives if there are no boundaries in the GT

  • 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)) `

NOTE: compared to BSDS500, we don’t have multiple GTs

pyEdgeEval.common.multi_label.binary_multilabel_decoding(edge_path: str, h: int, w: int, num_classes: int)[source]

Load binary file to edge map

  • Assumes that the input file is a 32-bit array

  • The saved file does not have shape information

  • output type is uint32

TODO: currently not used (deprecated)

pyEdgeEval.common.multi_label.load_scaled_edge(edge_path: str, scale: float)[source]

Load edge from file and scale it

Returns

edge – PIL.Image.Image (height, width): tuple of int

pyEdgeEval.common.multi_label.decode_png(edge: Image, num_classes: int)[source]

Decode png format Image into multi-label edge

pyEdgeEval.common.multi_label.decode_tif(edge: Image, num_classes: int)[source]

Decode tif format Image into multi-label edge

pyEdgeEval.common.multi_label.default_multilabel_encoding(edges: ndarray)[source]

Encode multi-label edges to binary format

For now we use uint32 as the base (PIL can save uint32). Therefore, we can save at most 32 classes.

However, RGB encoding is efficient unless you need more classes.

pyEdgeEval.common.multi_label.rgb_multilabel_encoding(edges: ndarray)[source]

Encode multi-label edges to RGB format

Each channel is 8-bit, so the RGB format can encode the edges into 24-bit (maximum of 24 classes).

This format is useful for training data where edges need to be transformed (compatible with various 3-channel augmentations).

pyEdgeEval.common.multi_label.save_category_results(root: str, category: int, sample_metrics, threshold_metrics, overall_metric)[source]

Save per-category results

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