mmagic.evaluation.metrics.metrics_utils
¶
Module Contents¶
Functions¶
|
|
|
|
|
Fetch and check data from one item of data_batch and predictions. |
|
Average of key in results(list[dict]). |
|
Image transform. |
|
Obtain data of key from data_sample and converse data to device. |
- mmagic.evaluation.metrics.metrics_utils._fetch_data_and_check(data_samples)[source]¶
Fetch and check data from one item of data_batch and predictions.
- Parameters
data_batch (dict) – One item of data_batch.
predictions (dict) – One item of predictions.
- Returns
Pred_alpha data of predictions. ori_alpha (Tensor): Ori_alpha data of data_batch. ori_trimap (Tensor): Ori_trimap data of data_batch.
- Return type
pred_alpha (Tensor)
- mmagic.evaluation.metrics.metrics_utils.average(results, key)[source]¶
Average of key in results(list[dict]).
- Parameters
results (list[dict]) – A list of dict containing the necessary data.
key (str) – The key of target data.
- Returns
The average result.
- Return type
result
- mmagic.evaluation.metrics.metrics_utils.img_transform(img, crop_border=0, input_order='HWC', convert_to=None, channel_order='rgb')[source]¶
Image transform.
Ref: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
- Parameters
img (np.ndarray) – Images with range [0, 255].
crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the PSNR calculation. Default: 0.
input_order (str) – Whether the input order is ‘HWC’ or ‘CHW’. Default: ‘HWC’.
convert_to (str) – Whether to convert the images to other color models. If None, the images are not altered. When computing for ‘Y’, the images are assumed to be in BGR order. Options are ‘Y’ and None. Default: None.
channel_order (str) – The channel order of image. Default: ‘rgb’
- Returns
PSNR result.
- Return type
float
- mmagic.evaluation.metrics.metrics_utils.obtain_data(data_sample, key, device='cpu')[source]¶
Obtain data of key from data_sample and converse data to device. :param data_sample: A dict of data sample. :type data_sample: dict :param key: The key of data to obtain. :type key: str :param device: Which device the data will deploy. Default: ‘cpu’. :type device: str
- Returns
The data of key.
- Return type
result (Tensor | np.ndarray)