Shortcuts

mmedit.evaluation.metrics

Package Contents

Classes

ConnectivityError

Connectivity error for evaluating alpha matte prediction.

Equivariance

Metric for generative metrics. Except for the preparation phase

FrechetInceptionDistance

FID metric. In this metric, we calculate the distance between real

TransFID

FID metric. In this metric, we calculate the distance between real

GradientError

Gradient error for evaluating alpha matte prediction.

InceptionScore

IS (Inception Score) metric. The images are split into groups, and the

TransIS

IS (Inception Score) metric. The images are split into groups, and the

MAE

Mean Absolute Error metric for image.

MattingMSE

Mean Squared Error metric for image matting.

MultiScaleStructureSimilarity

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

MSE

Mean Squared Error metric for image.

NIQE

Calculate NIQE (Natural Image Quality Evaluator) metric.

PerceptualPathLength

Perceptual path length.

PrecisionAndRecall

Improved Precision and recall metric.

PSNR

Peak Signal-to-Noise Ratio.

SAD

Sum of Absolute Differences metric for image matting.

SNR

Signal-to-Noise Ratio.

SSIM

Calculate SSIM (structural similarity).

SlicedWassersteinDistance

SWD (Sliced Wasserstein distance) metric. We calculate the SWD of two

Functions

niqe

psnr(img1, img2[, crop_border, input_order, ...])

Calculate PSNR (Peak Signal-to-Noise Ratio).

snr(gt, pred[, crop_border, input_order, convert_to, ...])

Calculate PSNR (Peak Signal-to-Noise Ratio).

ssim(img1, img2[, crop_border, input_order, ...])

Calculate SSIM (structural similarity).

class mmedit.evaluation.metrics.ConnectivityError(step=0.1, norm_constant=1000, **kwargs)[源代码]

Bases: mmengine.evaluator.BaseMetric

Connectivity error for evaluating alpha matte prediction.

备注

Current implementation assume image / alpha / trimap array in numpy format and with pixel value ranging from 0 to 255.

备注

pred_alpha should be masked by trimap before passing into this metric

参数
  • step (float) – Step of threshold when computing intersection between alpha and pred_alpha. Default to 0.1 .

  • norm_const (int) – Divide the result to reduce its magnitude. Default to 1000.

Default prefix: ‘’

Metrics:
  • ConnectivityError (float): Connectivity Error

process(data_batch: Sequence[dict], data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (Sequence[dict]) – A batch of data from the dataloader.

  • predictions (Sequence[dict]) – A batch of outputs from the model.

compute_metrics(results: List)

Compute the metrics from processed results.

参数

results (dict) – The processed results of each batch.

返回

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

返回类型

Dict

class mmedit.evaluation.metrics.Equivariance(fake_nums: int, real_nums: int = 0, fake_key: Optional[str] = None, real_key: Optional[str] = 'img', need_cond_input: bool = False, sample_mode: str = 'ema', sample_kwargs: dict = dict(), collect_device: str = 'cpu', prefix: Optional[str] = None, eq_cfg=dict())[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric

Metric for generative metrics. Except for the preparation phase (prepare()), generative metrics do not need extra real images.

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

  • real_nums (int) – Numbers of the real image need for the metric. If -1 is passed means all images from the dataset is need. Defaults to 0.

  • 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) – 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.

  • sample_kwargs (dict) – Sampling arguments for model test.

name = 'Equivariance'
process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

get_metric_sampler(model: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader, metrics: List[mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric])

Get sampler for generative metrics. Returns a dummy iterator, whose return value of each iteration is a dict containing batch size and sample mode to generate images.

参数
  • model (nn.Module) – Model to evaluate.

  • dataloader (DataLoader) – Dataloader for real images. Used to get batch size during generate fake images.

  • metrics (List['GenerativeMetric']) – Metrics with the same sampler mode.

返回

Sampler for generative metrics.

返回类型

dummy_iterator

compute_metrics(results) dict

Compute the metrics from processed results.

参数

results (list) – The processed results of each batch.

返回

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

返回类型

dict

_collect_target_results(target: str) Optional[list]

Collect function for Eq metric. This function support collect results typing as Dict[List[Tensor]]`.

参数

target (str) – Target results to collect.

返回

The collected results.

返回类型

Optional[list]

class mmedit.evaluation.metrics.FrechetInceptionDistance(fake_nums: int, real_nums: int = - 1, inception_style='StyleGAN', inception_path: Optional[str] = None, inception_pkl: Optional[str] = None, fake_key: Optional[str] = None, real_key: Optional[str] = 'img', need_cond_input: bool = False, sample_model: str = 'orig', collect_device: str = 'cpu', prefix: Optional[str] = None, sample_kwargs: dict = dict())[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric

FID metric. In this metric, we calculate the distance between real distributions and fake distributions. The distributions are modeled by the real samples and fake samples, respectively. Inception_v3 is adopted as the feature extractor, which is widely used in StyleGAN and BigGAN.

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

  • real_nums (int) – Numbers of the real images need for the metric. If -1 is passed, means all real images in the dataset will be used. Defaults to -1.

  • inception_style (str) – The target inception style want to load. If the given style cannot be loaded successful, will attempt to load a valid one. Defaults to ‘StyleGAN’.

  • inception_path (str, optional) – Path the the pretrain Inception network. Defaults to None.

  • inception_pkl (str, optional) – Path to reference inception pickle file. If None, the statistical value of real distribution will be calculated at running time. Defaults to None.

  • 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 ‘orig’.

  • 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 = 'FID'
prepare(module: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader) None

Preparing inception feature for the real images.

参数
  • module (nn.Module) – The model to evaluate.

  • dataloader (DataLoader) – The dataloader for real images.

_load_inception(inception_style: str, inception_path: Optional[str]) Tuple[torch.nn.Module, str]

Load inception and return the successful loaded style.

参数
  • inception_style (str) – Target style of Inception network want to load.

  • inception_path (Optional[str]) – The path to the inception.

返回

The actually loaded inception network and

corresponding style.

返回类型

Tuple[nn.Module, str]

forward_inception(image: torch.Tensor) torch.Tensor

Feed image to inception network and get the output feature.

参数

image (Tensor) – Image tensor fed to the Inception network.

返回

Image feature extracted from inception.

返回类型

Tensor

process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

static _calc_fid(sample_mean: numpy.ndarray, sample_cov: numpy.ndarray, real_mean: numpy.ndarray, real_cov: numpy.ndarray, eps: float = 1e-06) Tuple[float]

Refer to the implementation from:

https://github.com/rosinality/stylegan2-pytorch/blob/master/fid.py#L34

compute_metrics(fake_results: list) dict

Compulate the result of FID metric.

参数

fake_results (list) – List of image feature of fake images.

返回

A dict of the computed FID metric and its mean and

covariance.

返回类型

dict

class mmedit.evaluation.metrics.TransFID(fake_nums: int, real_nums: int = - 1, inception_style='StyleGAN', inception_path: Optional[str] = None, inception_pkl: Optional[str] = None, fake_key: Optional[str] = None, real_key: Optional[str] = 'img', sample_model: str = 'ema', collect_device: str = 'cpu', prefix: Optional[str] = None)[源代码]

Bases: FrechetInceptionDistance

FID metric. In this metric, we calculate the distance between real distributions and fake distributions. The distributions are modeled by the real samples and fake samples, respectively. Inception_v3 is adopted as the feature extractor, which is widely used in StyleGAN and BigGAN.

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

  • real_nums (int) – Numbers of the real images need for the metric. If -1 is passed, means all real images in the dataset will be used. Defaults to -1.

  • inception_style (str) – The target inception style want to load. If the given style cannot be loaded successful, will attempt to load a valid one. Defaults to ‘StyleGAN’.

  • inception_path (str, optional) – Path the the pretrain Inception network. Defaults to None.

  • inception_pkl (str, optional) – Path to reference inception pickle file. If None, the statistical value of real distribution will be calculated at running time. Defaults to None.

  • 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 ‘orig’.

  • 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.

get_metric_sampler(model: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader, metrics: List[mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric]) torch.utils.data.dataloader.DataLoader

Get sampler for normal metrics. Directly returns the dataloader.

参数
  • model (nn.Module) – Model to evaluate.

  • dataloader (DataLoader) – Dataloader for real images.

  • metrics (List['GenMetric']) – Metrics with the same sample mode.

返回

Default sampler for normal metrics.

返回类型

DataLoader

process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

class mmedit.evaluation.metrics.GradientError(sigma=1.4, norm_constant=1000, **kwargs)[源代码]

Bases: mmengine.evaluator.BaseMetric

Gradient error for evaluating alpha matte prediction.

备注

Current implementation assume image / alpha / trimap array in numpy format and with pixel value ranging from 0 to 255.

备注

pred_alpha should be masked by trimap before passing into this metric

参数
  • 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 .

Default prefix: ‘’

Metrics:
  • GradientError (float): Gradient Error

process(data_batch: Sequence[dict], data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (Sequence[dict]) – A batch of data from the dataloader.

  • predictions (Sequence[dict]) – A batch of outputs from the model.

compute_metrics(results: List)

Compute the metrics from processed results.

参数

results (dict) – The processed results of each batch.

返回

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

返回类型

Dict

class mmedit.evaluation.metrics.InceptionScore(fake_nums: int = 50000.0, resize: bool = True, splits: int = 10, inception_style: str = 'StyleGAN', inception_path: Optional[str] = None, resize_method='bicubic', use_pillow_resize: bool = True, fake_key: Optional[str] = None, need_cond_input: bool = False, sample_model='orig', collect_device: str = 'cpu', prefix: str = None)[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric

IS (Inception Score) metric. The images are split into groups, and the inception score is calculated on each group of images, then the mean and standard deviation of the score is reported. The calculation of the inception score on a group of images involves first using the inception v3 model to calculate the conditional probability for each image (p(y|x)). The marginal probability is then calculated as the average of the conditional probabilities for the images in the group (p(y)). The KL divergence is then calculated for each image as the conditional probability multiplied by the log of the conditional probability minus the log of the marginal probability. The KL divergence is then summed over all images and averaged over all classes and the exponent of the result is calculated to give the final score.

Ref: https://github.com/sbarratt/inception-score-pytorch/blob/master/inception_score.py # noqa

Note that we highly recommend that users should download the Inception V3 script module from the following address. Then, the inception_pkl can be set with user’s local path. If not given, we will use the Inception V3 from pytorch model zoo. However, this may bring significant different in the final results.

Tero’s Inception V3: https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/metrics/inception-2015-12-05.pt # noqa

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

  • resize (bool, optional) – Whether resize image to 299x299. Defaults to True.

  • splits (int, optional) – The number of groups. Defaults to 10.

  • inception_style (str) – The target inception style want to load. If the given style cannot be loaded successful, will attempt to load a valid one. Defaults to ‘StyleGAN’.

  • inception_path (str, optional) – Path the the pretrain Inception network. Defaults to None.

  • resize_method (str) – Resize method. If resize is False, this will be ignored. Defaults to ‘bicubic’.

  • use_pil_resize (bool) – Whether use Bicubic interpolation with Pillow’s backend. If set as True, the evaluation process may be a little bit slow, but achieve a more accurate IS result. Defaults to False.

  • 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 ‘orig’.

  • 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 = 'IS'
pil_resize_method_mapping
prepare(module: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader) None

Prepare for the pre-calculating items of the metric. Defaults to do nothing.

参数
  • module (nn.Module) – Model to evaluate.

  • dataloader (DataLoader) – Dataloader for the real images.

_load_inception(inception_style: str, inception_path: Optional[str]) Tuple[torch.nn.Module, str]

Load pretrain model of inception network. :param inception_style: Target style of Inception network want to

load.

参数

inception_path (Optional[str]) – The path to the inception.

返回

The actually loaded inception network and

corresponding style.

返回类型

Tuple[nn.Module, str]

_preprocess(image: torch.Tensor) torch.Tensor

Preprocess image before pass to the Inception. Preprocess operations contain channel conversion and resize.

参数

image (Tensor) – Image tensor before preprocess.

返回

Image tensor after resize and channel conversion

(if need.)

返回类型

Tensor

process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

compute_metrics(fake_results: list) dict

Compute the results of Inception Score metric.

参数

fake_results (list) – List of image feature of fake images.

返回

A dict of the computed IS metric and its standard error

返回类型

dict

class mmedit.evaluation.metrics.TransIS(fake_nums: int = 50000, resize: bool = True, splits: int = 10, inception_style: str = 'StyleGAN', inception_path: Optional[str] = None, resize_method='bicubic', use_pillow_resize: bool = True, fake_key: Optional[str] = None, sample_model='ema', collect_device: str = 'cpu', prefix: str = None)[源代码]

Bases: InceptionScore

IS (Inception Score) metric. The images are split into groups, and the inception score is calculated on each group of images, then the mean and standard deviation of the score is reported. The calculation of the inception score on a group of images involves first using the inception v3 model to calculate the conditional probability for each image (p(y|x)). The marginal probability is then calculated as the average of the conditional probabilities for the images in the group (p(y)). The KL divergence is then calculated for each image as the conditional probability multiplied by the log of the conditional probability minus the log of the marginal probability. The KL divergence is then summed over all images and averaged over all classes and the exponent of the result is calculated to give the final score.

Ref: https://github.com/sbarratt/inception-score-pytorch/blob/master/inception_score.py # noqa

Note that we highly recommend that users should download the Inception V3 script module from the following address. Then, the inception_pkl can be set with user’s local path. If not given, we will use the Inception V3 from pytorch model zoo. However, this may bring significant different in the final results.

Tero’s Inception V3: https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/metrics/inception-2015-12-05.pt # noqa

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

  • resize (bool, optional) – Whether resize image to 299x299. Defaults to True.

  • splits (int, optional) – The number of groups. Defaults to 10.

  • inception_style (str) – The target inception style want to load. If the given style cannot be loaded successful, will attempt to load a valid one. Defaults to ‘StyleGAN’.

  • inception_path (str, optional) – Path the the pretrain Inception network. Defaults to None.

  • resize_method (str) – Resize method. If resize is False, this will be ignored. Defaults to ‘bicubic’.

  • use_pil_resize (bool) – Whether use Bicubic interpolation with Pillow’s backend. If set as True, the evaluation process may be a little bit slow, but achieve a more accurate IS result. Defaults to False.

  • 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’.

  • 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.

process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • predictions (Sequence[dict]) – A batch of outputs from the model.

get_metric_sampler(model: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader, metrics: List[mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric]) torch.utils.data.dataloader.DataLoader

Get sampler for normal metrics. Directly returns the dataloader.

参数
  • model (nn.Module) – Model to evaluate.

  • dataloader (DataLoader) – Dataloader for real images.

  • metrics (List['GenMetric']) – Metrics with the same sample mode.

返回

Default sampler for normal metrics.

返回类型

DataLoader

class mmedit.evaluation.metrics.MAE(gt_key: str = 'gt_img', pred_key: str = 'pred_img', mask_key: Optional[str] = None, scaling=1, device='cpu', collect_device: str = 'cpu', prefix: Optional[str] = None)[源代码]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Mean Absolute Error metric for image.

mean(abs(a-b))

参数
  • gt_key (str) – Key of ground-truth. Default: ‘gt_img’

  • pred_key (str) – Key of prediction. Default: ‘pred_img’

  • mask_key (str, optional) – Key of mask, if mask_key is None, calculate all regions. Default: None

  • collect_device (str) – 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. Default: None

Metrics:
  • MAE (float): Mean of Absolute Error

metric = 'MAE'
process_image(gt, pred, mask)

Process an image.

参数
  • gt (Tensor | np.ndarray) – GT image.

  • pred (Tensor | np.ndarray) – Pred image.

  • mask (Tensor | np.ndarray) – Mask of evaluation.

返回

MAE result.

返回类型

result (np.ndarray)

class mmedit.evaluation.metrics.MattingMSE(norm_const=1000, **kwargs)[源代码]

Bases: mmengine.evaluator.BaseMetric

Mean Squared Error metric for image matting.

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

备注

Current implementation assume image / alpha / trimap array in numpy format and with pixel value ranging from 0 to 255.

备注

pred_alpha should be masked by trimap before passing into this metric

Default prefix: ‘’

参数

norm_const (int) – Divide the result to reduce its magnitude. Default to 1000.

Metrics:
  • MattingMSE (float): Mean of Squared Error

default_prefix = ''
process(data_batch: Sequence[dict], data_samples: Sequence[dict]) None

Process one batch of data and predictions.

参数
  • data_batch (Sequence[dict]) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

compute_metrics(results: List)

Compute the metrics from processed results.

参数

results (dict) – The processed results of each batch.

返回

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

返回类型

Dict

class mmedit.evaluation.metrics.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

class mmedit.evaluation.metrics.MSE(gt_key: str = 'gt_img', pred_key: str = 'pred_img', mask_key: Optional[str] = None, scaling=1, device='cpu', collect_device: str = 'cpu', prefix: Optional[str] = None)[源代码]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Mean Squared Error metric for image.

mean((a-b)^2)

参数
  • gt_key (str) – Key of ground-truth. Default: ‘gt_img’

  • pred_key (str) – Key of prediction. Default: ‘pred_img’

  • mask_key (str, optional) – Key of mask, if mask_key is None, calculate all regions. Default: None

  • collect_device (str) – 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. Default: None

Metrics:
  • MSE (float): Mean of Squared Error

metric = 'MSE'
process_image(gt, pred, mask)

Process an image.

参数
  • gt (Torch | np.ndarray) – GT image.

  • pred (Torch | np.ndarray) – Pred image.

  • mask (Torch | np.ndarray) – Mask of evaluation.

返回

MSE result.

返回类型

result (np.ndarray)

class mmedit.evaluation.metrics.NIQE(key: str = 'pred_img', is_predicted: bool = True, collect_device: str = 'cpu', prefix: Optional[str] = None, crop_border=0, input_order='HWC', convert_to='gray')[源代码]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Calculate NIQE (Natural Image Quality Evaluator) metric.

Ref: Making a “Completely Blind” Image Quality Analyzer. This implementation could produce almost the same results as the official MATLAB codes: http://live.ece.utexas.edu/research/quality/niqe_release.zip

We use the official params estimated from the pristine dataset. We use the recommended block size (96, 96) without overlaps.

参数
  • key (str) – Key of image. Default: ‘pred_img’

  • is_predicted (bool) – If the image is predicted, it will be picked from predictions; otherwise, it will be picked from data_batch. Default: True

  • collect_device (str) – 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. Default: None

  • 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: ‘gray’.

Metrics:
  • NIQE (float): Natural Image Quality Evaluator

metric = 'NIQE'
process_image(gt, pred, mask) None

Process an image.

参数
  • gt (np.ndarray) – GT image.

  • pred (np.ndarray) – Pred image.

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

返回

NIQE result.

返回类型

result (np.ndarray)

mmedit.evaluation.metrics.niqe(img, crop_border, input_order='HWC', convert_to='y')

Calculate NIQE (Natural Image Quality Evaluator) metric.

Ref: Making a “Completely Blind” Image Quality Analyzer. This implementation could produce almost the same results as the official MATLAB codes: http://live.ece.utexas.edu/research/quality/niqe_release.zip

We use the official params estimated from the pristine dataset. We use the recommended block size (96, 96) without overlaps.

参数
  • img (np.ndarray) – Input image whose quality needs to be computed. The input image must be in range [0, 255] with float/int type. The input_order of image can be ‘HW’ or ‘HWC’ or ‘CHW’. (BGR order) If the input order is ‘HWC’ or ‘CHW’, it will be converted to gray or Y (of YCbCr) image according to the convert_to argument.

  • crop_border (int) – Cropped pixels in each edge of an image. These pixels are not involved in the metric calculation.

  • input_order (str) – Whether the input order is ‘HW’, ‘HWC’ or ‘CHW’. Default: ‘HWC’.

  • convert_to (str) – Whether converted to ‘y’ (of MATLAB YCbCr) or ‘gray’. Default: ‘y’.

返回

NIQE result.

返回类型

niqe_result (float)

class mmedit.evaluation.metrics.PerceptualPathLength(fake_nums: int, real_nums: int = 0, fake_key: Optional[str] = None, real_key: Optional[str] = 'img', need_cond_input: bool = False, sample_model: str = 'ema', collect_device: str = 'cpu', prefix: Optional[str] = None, crop=True, epsilon=0.0001, space='W', sampling='end', latent_dim=512)[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric

Perceptual path length.

Measure the difference between consecutive images (their VGG16 embeddings) when interpolating between two random inputs. Drastic changes mean that multiple features have changed together and that they might be entangled.

Ref: https://github.com/rosinality/stylegan2-pytorch/blob/master/ppl.py # noqa

参数
  • num_images (int) – The number of evaluated generated samples.

  • image_shape (tuple, optional) – Image shape in order “CHW”. Defaults to None.

  • crop (bool, optional) – Whether crop images. Defaults to True.

  • epsilon (float, optional) – Epsilon parameter for path sampling. Defaults to 1e-4.

  • space (str, optional) – Latent space. Defaults to ‘W’.

  • sampling (str, optional) – Sampling mode, whether sampling in full path or endpoints. Defaults to ‘end’.

  • latent_dim (int, optional) – Latent dimension of input noise. Defaults to 512.

  • 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.

SAMPLER_MODE = 'path'
process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

_compute_distance(images)

Feed data to the metric.

参数

images (Tensor) – Input tensor.

compute_metrics(fake_results: list) dict

Summarize the results.

返回

Summarized results.

返回类型

dict | list

get_metric_sampler(model: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader, metrics: list)

Get sampler for generative metrics. Returns a dummy iterator, whose return value of each iteration is a dict containing batch size and sample mode to generate images.

参数
  • model (nn.Module) – Model to evaluate.

  • dataloader (DataLoader) – Dataloader for real images. Used to get batch size during generate fake images.

  • metrics (list) – Metrics with the same sampler mode.

返回

Sampler for generative metrics.

返回类型

dummy_iterator

class mmedit.evaluation.metrics.PrecisionAndRecall(fake_nums, real_nums=- 1, k=3, fake_key: Optional[str] = None, real_key: Optional[str] = 'img', need_cond_input: bool = False, sample_model: str = 'ema', collect_device: str = 'cpu', prefix: Optional[str] = None, vgg16_script='work_dirs/cache/vgg16.pt', vgg16_pkl=None, row_batch_size=10000, col_batch_size=10000, auto_save=True)[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenerativeMetric

Improved Precision and recall metric.

In this metric, we draw real and generated samples respectively, and embed them into a high-dimensional feature space using a pre-trained classifier network. We use these features to estimate the corresponding manifold. We obtain the estimation by calculating pairwise Euclidean distances between all feature vectors in the set and, for each feature vector, construct a hypersphere with radius equal to the distance to its kth nearest neighbor. Together, these hyperspheres define a volume in the feature space that serves as an estimate of the true manifold. Precision is quantified by querying for each generated image whether the image is within the estimated manifold of real images. Symmetrically, recall is calculated by querying for each real image whether the image is within estimated manifold of generated image.

Ref: https://github.com/NVlabs/stylegan2-ada-pytorch/blob/main/metrics/precision_recall.py # noqa

Note that we highly recommend that users should download the vgg16 script module from the following address. Then, the vgg16_script can be set with user’s local path. If not given, we will use the vgg16 from pytorch model zoo. However, this may bring significant different in the final results.

Tero’s vgg16: https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/metrics/vgg16.pt

参数
  • num_images (int) – The number of evaluated generated samples.

  • image_shape (tuple) – Image shape in order “CHW”. Defaults to None.

  • num_real_need (int | None, optional) – The number of real images. Defaults to None.

  • full_dataset (bool, optional) – Whether to use full dataset for evaluation. Defaults to False.

  • k (int, optional) – Kth nearest parameter. Defaults to 3.

  • bgr2rgb (bool, optional) – Whether to change the order of image channel. Defaults to True.

  • vgg16_script (str, optional) – Path for the Tero’s vgg16 module. Defaults to ‘work_dirs/cache/vgg16.pt’.

  • row_batch_size (int, optional) – The batch size of row data. Defaults to 10000.

  • col_batch_size (int, optional) – The batch size of col data. Defaults to 10000.

  • auto_save (bool, optional) – Whether save vgg feature automatically.

  • 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.

name = 'PR'
_load_vgg(vgg16_script: Optional[str]) Tuple[torch.nn.Module, bool]

Load VGG network from the given path.

参数

vgg16_script – The path of script model of VGG network. If None, will load the pytorch version.

返回

The actually loaded VGG network and

corresponding style.

返回类型

Tuple[nn.Module, str]

extract_features(images)

Extracting image features.

参数

images (torch.Tensor) – Images tensor.

返回

Vgg16 features of input images.

返回类型

torch.Tensor

compute_metrics(results_fake) dict

compute_metrics.

返回

Summarized results.

返回类型

dict

process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

prepare(module: torch.nn.Module, dataloader: torch.utils.data.dataloader.DataLoader) None

Prepare for the pre-calculating items of the metric. Defaults to do nothing.

参数
  • module (nn.Module) – Model to evaluate.

  • dataloader (DataLoader) – Dataloader for the real images.

class mmedit.evaluation.metrics.PSNR(gt_key: str = 'gt_img', pred_key: str = 'pred_img', collect_device: str = 'cpu', prefix: Optional[str] = None, crop_border=0, input_order='CHW', convert_to=None)[源代码]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Peak Signal-to-Noise Ratio.

Ref: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

参数
  • gt_key (str) – Key of ground-truth. Default: ‘gt_img’

  • pred_key (str) – Key of prediction. Default: ‘pred_img’

  • collect_device (str) – 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. Default: None

  • 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: ‘CHW’.

  • 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.

Metrics:
  • PSNR (float): Peak Signal-to-Noise Ratio

metric = 'PSNR'
process_image(gt, pred, mask)

Process an image.

参数
  • gt (Torch | np.ndarray) – GT image.

  • pred (Torch | np.ndarray) – Pred image.

  • mask (Torch | np.ndarray) – Mask of evaluation.

返回

PSNR result.

返回类型

np.ndarray

mmedit.evaluation.metrics.psnr(img1, img2, crop_border=0, input_order='HWC', convert_to=None, channel_order='rgb')[源代码]

Calculate PSNR (Peak Signal-to-Noise Ratio).

Ref: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

参数
  • img1 (ndarray) – Images with range [0, 255].

  • img2 (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’.

返回

PSNR result.

返回类型

result (float)

class mmedit.evaluation.metrics.SAD(norm_const=1000, **kwargs)[源代码]

Bases: mmengine.evaluator.BaseMetric

Sum of Absolute Differences metric for image matting.

This metric compute per-pixel absolute difference and sum across all pixels. i.e. sum(abs(a-b)) / norm_const

备注

Current implementation assume image / alpha / trimap array in numpy format and with pixel value ranging from 0 to 255.

备注

pred_alpha should be masked by trimap before passing into this metric

Default prefix: ‘’

参数

norm_const (int) – Divide the result to reduce its magnitude. Default to 1000.

Metrics:
  • SAD (float): Sum of Absolute Differences

default_prefix = ''
process(data_batch: Sequence[dict], data_samples: Sequence[dict]) None

Process one batch of data and predictions.

参数
  • data_batch (Sequence[Tuple[Any, dict]]) – A batch of data from the dataloader.

  • predictions (Sequence[dict]) – A batch of outputs from the model.

compute_metrics(results: List)

Compute the metrics from processed results.

参数

results (dict) – The processed results of each batch.

返回

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

返回类型

Dict

class mmedit.evaluation.metrics.SNR(gt_key: str = 'gt_img', pred_key: str = 'pred_img', collect_device: str = 'cpu', prefix: Optional[str] = None, crop_border=0, input_order='CHW', convert_to=None)[源代码]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Signal-to-Noise Ratio.

Ref: https://en.wikipedia.org/wiki/Signal-to-noise_ratio

参数
  • gt_key (str) – Key of ground-truth. Default: ‘gt_img’

  • pred_key (str) – Key of prediction. Default: ‘pred_img’

  • collect_device (str) – 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. Default: None

  • crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the SNR calculation. Default: 0.

  • input_order (str) – Whether the input order is ‘HWC’ or ‘CHW’. Default: ‘CHW’.

  • 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.

Metrics:
  • SNR (float): Signal-to-Noise Ratio

metric = 'SNR'
process_image(gt, pred, mask)

Process an image.

参数
  • gt (Torch | np.ndarray) – GT image.

  • pred (Torch | np.ndarray) – Pred image.

  • mask (Torch | np.ndarray) – Mask of evaluation.

返回

SNR result.

返回类型

np.ndarray

mmedit.evaluation.metrics.snr(gt, pred, crop_border=0, input_order='HWC', convert_to=None, channel_order='rgb')[源代码]

Calculate PSNR (Peak Signal-to-Noise Ratio).

Ref: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio

参数
  • gt (ndarray) – Images with range [0, 255].

  • pred (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’.

返回

SNR result.

返回类型

float

class mmedit.evaluation.metrics.SSIM(gt_key: str = 'gt_img', pred_key: str = 'pred_img', collect_device: str = 'cpu', prefix: Optional[str] = None, crop_border=0, input_order='CHW', convert_to=None)[源代码]

Bases: mmedit.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric

Calculate SSIM (structural similarity).

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.

参数
  • gt_key (str) – Key of ground-truth. Default: ‘gt_img’

  • pred_key (str) – Key of prediction. Default: ‘pred_img’

  • collect_device (str) – 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. Default: None

  • 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.

Metrics:
  • SSIM (float): Structural similarity

metric = 'SSIM'
process_image(gt, pred, mask)

Process an image.

参数
  • gt (Torch | np.ndarray) – GT image.

  • pred (Torch | np.ndarray) – Pred image.

  • mask (Torch | np.ndarray) – Mask of evaluation.

返回

SSIM result.

返回类型

np.ndarray

mmedit.evaluation.metrics.ssim(img1, img2, crop_border=0, input_order='HWC', convert_to=None, channel_order='rgb')[源代码]

Calculate SSIM (structural similarity).

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.

参数
  • img1 (ndarray) – Images with range [0, 255].

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

  • crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the SSIM 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’

返回

SSIM result.

返回类型

float

class mmedit.evaluation.metrics.SlicedWassersteinDistance(fake_nums: int, image_shape: tuple, fake_key: Optional[str] = None, real_key: Optional[str] = 'img', sample_model: str = 'ema', collect_device: str = 'cpu', prefix: Optional[str] = None)[源代码]

Bases: mmedit.evaluation.metrics.base_gen_metric.GenMetric

SWD (Sliced Wasserstein distance) metric. We calculate the SWD of two sets of images in the following way. In every ‘feed’, we obtain the Laplacian pyramids of every images and extract patches from the Laplacian pyramids as descriptors. In ‘summary’, we normalize these descriptors along channel, and reshape them so that we can use these descriptors to represent the distribution of real/fake images. And we can calculate the sliced Wasserstein distance of the real and fake descriptors as the SWD of the real and fake images.

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

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

  • image_shape (tuple) – Image shape in order “CHW”.

  • 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’.

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

  • collect_device (str) – 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 = 'SWD'
process(data_batch: dict, data_samples: Sequence[dict]) None

Process one batch of data samples and predictions. The processed results should be stored in self.fake_results and self.real_results, which will be used to compute the metrics when all batches have been processed.

参数
  • data_batch (dict) – A batch of data from the dataloader.

  • data_samples (Sequence[dict]) – A batch of outputs from the model.

_collect_target_results(target: str) Optional[list]

Collect function for SWD metric. This function support collect results typing as List[List[Tensor]].

参数

target (str) – Target results to collect.

返回

The collected results.

返回类型

Optional[list]

compute_metrics(results_fake, results_real) dict

Compulate the result of SWD metric.

参数
  • fake_results (list) – List of image feature of fake images.

  • real_results (list) – List of image feature of real images.

返回

A dict of the computed SWD metric.

返回类型

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.