GradientError¶
- class mmeval.metrics.GradientError(sigma: float = 1.4, norm_const: int = 1000, **kwargs)[source]¶
Gradient error for evaluating alpha matte prediction.
- Parameters
sigma (float) – Standard deviation of the gaussian kernel. Defaults to 1.4 .
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 GradientError >>> import numpy as np >>> >>> gradient_error = GradientError() >>> np.random.seed(0) >>> pred_alpha = np.random.randn(32, 32).astype('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 >>> gradient_error(pred_alpha, gt_alpha, trimap) {'gradient_error': ...}
- add(pred_alphas: Sequence[numpy.ndarray], gt_alphas: Sequence[numpy.ndarray], trimaps: Sequence[numpy.ndarray]) → None[source]¶
Add GradientError 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 GradientError metric.
- Parameters
results (List) – A list that consisting the GradientError score. This list has already been synced across all ranks.
- Returns
The computed GradientError metric. The keys are the names of the metrics, and the values are corresponding results.
- Return type
Dict[str, float]