ConnectivityError¶
- class mmeval.metrics.ConnectivityError(step: float = 0.1, norm_const: int = 1000, **kwargs)[source]¶
Connectivity error for evaluating alpha matte prediction.
- Parameters
step (float) – Step of threshold when computing intersection between alpha and pred_alpha. Default to 0.1 .
norm_const (int) – Divide the result to reduce its magnitude. Defaults to 1000 .
**kwargs – Keyword parameters passed to
BaseMetric
.
Note
The current implementation assumes the image / alpha / trimap a numpy array with pixel values ranging from 0 to 255.
The pred_alpha should be masked by trimap before passing into this metric.
The trimap is the most commonly used prior knowledge. As the name implies, trimap is a ternary graph and each pixel takes one of {0, 128, 255}, representing the foreground, the unknown and the background respectively.
Examples
>>> from mmeval import ConnectivityError >>> import numpy as np >>> >>> connectivity_error = ConnectivityError() >>> pred_alpha = np.zeros((32, 32), dtype=np.uint8) >>> gt_alpha = np.ones((32, 32), dtype=np.uint8) * 255 >>> trimap = np.zeros((32, 32), dtype=np.uint8) >>> trimap[:16, :16] = 128 >>> trimap[16:, 16:] = 255 >>> connectivity_error(pred_alpha, gt_alpha, trimap) {'connectivity_error': ...}
- add(pred_alphas: Sequence[numpy.ndarray], gt_alphas: Sequence[numpy.ndarray], trimaps: Sequence[numpy.ndarray]) → None[source]¶
Add ConnectivityError score of batch to
self._results
- Parameters
pred_alphas (Sequence[np.ndarray]) – Predict the probability that pixels belong to the foreground.
gt_alphas (Sequence[np.ndarray]) – Probability that the actual pixel belongs to the foreground.
trimaps (Sequence[np.ndarray]) – Broadly speaking, the trimap consists of foreground and unknown region.
- compute_metric(results: List) → Dict[str, float][source]¶
Compute the ConnectivityError metric.
- Parameters
results (List) – A list that consisting the ConnectivityError score. This list has already been synced across all ranks.
- Returns
The computed ConnectivityError metric. The keys are the names of the metrics, and the values are corresponding results.
- Return type
Dict[str, float]