Shortcuts

MeanSquaredError

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

Mean Squared Error metric for image.

Formula: mean((a-b)^2).

Parameters

**kwargs – Keyword parameters passed to BaseMetric.

Examples

>>> from mmeval import MeanSquaredError as MSE
>>> import numpy as np
>>>
>>> mse = MSE()
>>> gts = np.random.randint(0, 255, size=(3, 32, 32))
>>> preds = np.random.randint(0, 255, size=(3, 32, 32))
>>> mse(preds, gts)  
{'mse': ...}

Calculate MeanSquaredError between 2 images with mask:

>>> img1 = np.ones((32, 32, 3))
>>> img2 = np.ones((32, 32, 3)) * 2
>>> mask = np.ones((32, 32, 3)) * 2
>>> mask[:16] *= 0
>>> MSE.compute_mse(img1, img2, mask)
0.000015378700496
add(predictions: Sequence[numpy.ndarray], groundtruths: Sequence[numpy.ndarray], masks: Optional[Sequence[numpy.ndarray]] = None)None[source]

Add MeanSquaredError score of batch to self._results

Parameters
  • predictions (Sequence[np.ndarray]) – Predictions of the model.

  • groundtruths (Sequence[np.ndarray]) – The ground truth images.

  • masks (Sequence[np.ndarray], optional) – Mask images.

compute_metric(results: List[numpy.float32])Dict[str, float][source]

Compute the MeanSquaredError metric.

This method would be invoked in BaseMetric.compute after distributed synchronization.

Parameters

results (List[np.float32]) – A list that consisting the MeanSquaredError score. This list has already been synced across all ranks.

Returns

The computed MeanSquaredError metric.

Return type

Dict[str, float]

static compute_mse(prediction: numpy.ndarray, groundtruth: numpy.ndarray, mask: Optional[numpy.ndarray] = None)numpy.float32[source]

Calculate MeanSquaredError (Mean Squared Error).

Parameters
  • prediction (np.ndarray) – Images with range [0, 255].

  • groundtruth (np.ndarray) – Images with range [0, 255].

  • mask (np.ndarray, optional) – Mask of evaluation.

Returns

MeanSquaredError result.

Return type

np.float32

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.