Shortcuts

MattingMeanSquaredError

class mmeval.metrics.MattingMeanSquaredError(**kwargs)[source]

Mean Squared Error metric for image matting.

This metric computes the per-pixel squared error average across all pixels. i.e. mean((a-b)^2)

Parameters

**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 MattingMeanSquaredError as MattingMSE
>>> import numpy as np
>>>
>>> matting_mse = MattingMSE()
>>> 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
>>> matting_mse(pred_alpha, gt_alpha, trimap)  
{'matting_mse': ...}
add(pred_alphas: Sequence[numpy.ndarray], gt_alphas: Sequence[numpy.ndarray], trimaps: Sequence[numpy.ndarray])None[source]

Add MattingMeanSquaredError 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 MattingMeanSquaredError metric.

Parameters

results (List) – A list that consisting the MattingMeanSquaredError score. This list has already been synced across all ranks.

Returns

The computed MattingMeanSquaredError metric. The keys are the names of the metrics, and the values are corresponding results.

Return type

Dict[str, float]

Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.