Shortcuts

mmedit.evaluation.metrics.ms_ssim

Module Contents

Classes

MultiScaleStructureSimilarity

MS-SSIM (Multi-Scale Structure Similarity) metric.

Functions

_f_special_gauss(size, sigma)

Return a circular symmetric gaussian kernel.

_hox_downsample(img)

Downsample images with factor equal to 0.5.

_ssim_for_multi_scale(img1, img2[, max_val, ...])

Calculate SSIM (structural similarity) and contrast sensitivity.

ms_ssim(→ numpy.ndarray)

Calculate MS-SSIM (multi-scale structural similarity).

mmedit.evaluation.metrics.ms_ssim._f_special_gauss(size, sigma)[源代码]

Return a circular symmetric gaussian kernel.

Ref: https://github.com/tkarras/progressive_growing_of_gans/blob/master/metrics/ms_ssim.py # noqa

参数
  • size (int) – Size of Gaussian kernel.

  • sigma (float) – Standard deviation for Gaussian blur kernel.

返回

Gaussian kernel.

返回类型

ndarray

mmedit.evaluation.metrics.ms_ssim._hox_downsample(img)[源代码]

Downsample images with factor equal to 0.5.

Ref: https://github.com/tkarras/progressive_growing_of_gans/blob/master/metrics/ms_ssim.py # noqa

参数

img (ndarray) – Images with order “NHWC”.

返回

Downsampled images with order “NHWC”.

返回类型

ndarray

mmedit.evaluation.metrics.ms_ssim._ssim_for_multi_scale(img1, img2, max_val=255, filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03)[源代码]

Calculate SSIM (structural similarity) and contrast sensitivity.

Ref: Image quality assessment: From error visibility to structural similarity.

The results are the same as that of the official released MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/.

For three-channel images, SSIM is calculated for each channel and then averaged.

This function attempts to match the functionality of ssim_index_new.m by Zhou Wang: http://www.cns.nyu.edu/~lcv/ssim/msssim.zip

参数
  • img1 (ndarray) – Images with range [0, 255] and order “NHWC”.

  • img2 (ndarray) – Images with range [0, 255] and order “NHWC”.

  • max_val (int) – the dynamic range of the images (i.e., the difference between the maximum the and minimum allowed values). Default to 255.

  • filter_size (int) – Size of blur kernel to use (will be reduced for small images). Default to 11.

  • filter_sigma (float) – Standard deviation for Gaussian blur kernel (will be reduced for small images). Default to 1.5.

  • k1 (float) – Constant used to maintain stability in the SSIM calculation (0.01 in the original paper). Default to 0.01.

  • k2 (float) – Constant used to maintain stability in the SSIM calculation (0.03 in the original paper). Default to 0.03.

返回

Pair containing the mean SSIM and contrast sensitivity between img1 and img2.

返回类型

tuple

mmedit.evaluation.metrics.ms_ssim.ms_ssim(img1, img2, max_val=255, filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03, weights=None, reduce_mean=True) numpy.ndarray[源代码]

Calculate MS-SSIM (multi-scale structural similarity).

Ref: This function implements Multi-Scale Structural Similarity (MS-SSIM) Image Quality Assessment according to Zhou Wang’s paper, “Multi-scale structural similarity for image quality assessment” (2003). Link: https://ece.uwaterloo.ca/~z70wang/publications/msssim.pdf

Author’s MATLAB implementation: http://www.cns.nyu.edu/~lcv/ssim/msssim.zip

PGGAN’s implementation: https://github.com/tkarras/progressive_growing_of_gans/blob/master/metrics/ms_ssim.py

参数
  • img1 (ndarray) – Images with range [0, 255] and order “NHWC”.

  • img2 (ndarray) – Images with range [0, 255] and order “NHWC”.

  • max_val (int) – the dynamic range of the images (i.e., the difference between the maximum the and minimum allowed values). Default to 255.

  • filter_size (int) – Size of blur kernel to use (will be reduced for small images). Default to 11.

  • filter_sigma (float) – Standard deviation for Gaussian blur kernel (will be reduced for small images). Default to 1.5.

  • k1 (float) – Constant used to maintain stability in the SSIM calculation (0.01 in the original paper). Default to 0.01.

  • k2 (float) – Constant used to maintain stability in the SSIM calculation (0.03 in the original paper). Default to 0.03.

  • weights (list) – List of weights for each level; if none, use five levels and the weights from the original paper. Default to None.

返回

MS-SSIM score between img1 and img2.

返回类型

np.ndarray

class mmedit.evaluation.metrics.ms_ssim.MultiScaleStructureSimilarity(fake_nums: int, fake_key: Optional[str] = None, need_cond_input: bool = False, sample_model: str = 'ema', collect_device: str = 'cpu', prefix: Optional[str] = None)[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric

MS-SSIM (Multi-Scale Structure Similarity) metric.

Ref: https://github.com/tkarras/progressive_growing_of_gans/blob/master/metrics/ms_ssim.py # noqa

参数
  • fake_nums (int) – Numbers of the generated image need for the metric.

  • fake_key (Optional[str]) – Key for get fake images of the output dict. Defaults to None.

  • real_key (Optional[str]) – Key for get real images from the input dict. Defaults to ‘img’.

  • need_cond_input (bool) – If true, the sampler will return the conditional input randomly sampled from the original dataset. This require the dataset implement get_data_info and field gt_label must be contained in the return value of get_data_info. Noted that, for unconditional models, set need_cond_input as True may influence the result of evaluation results since the conditional inputs are sampled from the dataset distribution; otherwise will be sampled from the uniform distribution. Defaults to False.

  • sample_model (str) – Sampling mode for the generative model. Support ‘orig’ and ‘ema’. Defaults to ‘ema’.

  • collect_device (str, optional) – Device name used for collecting results from different ranks during distributed training. Must be ‘cpu’ or ‘gpu’. Defaults to ‘cpu’.

  • prefix (str, optional) – The prefix that will be added in the metric names to disambiguate homonymous metrics of different evaluators. If prefix is not provided in the argument, self.default_prefix will be used instead. Defaults to None.

name = 'MS-SSIM'[源代码]
process(data_batch: dict, data_samples: Sequence[dict]) None[源代码]

Feed data to the metric.

参数
  • data_batch (dict) – Real images from dataloader. Do not be used in this metric.

  • data_samples (Sequence[dict]) – Generated images.

_collect_target_results(target: str) Optional[list][源代码]

Collected results for MS-SSIM metric. Size of self.fake_results in MS-SSIM does not relay on self.fake_nums but self.num_pairs.

参数

target (str) – Target results to collect.

返回

The collected results.

返回类型

Optional[list]

compute_metrics(results_fake: List)[源代码]

Computed the result of MS-SSIM.

返回

Calculated MS-SSIM result.

返回类型

dict

Read the Docs v: latest
Versions
master
latest
stable
zyh-doc-notfound-extend
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.