Shortcuts

mmedit.evaluation.functional

Package Contents

Classes

InceptionV3

Pretrained InceptionV3 network returning feature maps.

Functions

gauss_gradient(img, sigma)

Gaussian gradient.

disable_gpu_fuser_on_pt19()

On PyTorch 1.9 a CUDA fuser bug prevents the Inception JIT model to run.

load_inception(inception_args, metric)

Load Inception Model from given inception_args and metric.

prepare_inception_feat(→ dict)

Prepare inception feature for the input metric.

prepare_vgg_feat(→ numpy.ndarray)

Prepare vgg feature for the input metric.

class mmedit.evaluation.functional.InceptionV3(output_blocks=[DEFAULT_BLOCK_INDEX], resize_input=True, normalize_input=True, requires_grad=False, use_fid_inception=True, load_fid_inception=True)[源代码]

Bases: torch.nn.Module

Pretrained InceptionV3 network returning feature maps.

DEFAULT_BLOCK_INDEX = 3
BLOCK_INDEX_BY_DIM
forward(inp)

Get Inception feature maps.

参数

inp (torch.Tensor) – Input tensor of shape Bx3xHxW. Values are expected to be in range (0, 1)

返回

Corresponding to the selected output block, sorted ascending by index.

返回类型

list(torch.Tensor)

mmedit.evaluation.functional.gauss_gradient(img, sigma)[源代码]

Gaussian gradient.

From https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/ submissions/8060/versions/2/previews/gaussgradient/gaussgradient.m/ index.html

参数
  • img (np.ndarray) – Input image.

  • sigma (float) – Standard deviation of the gaussian kernel.

返回

Gaussian gradient of input img.

返回类型

np.ndarray

mmedit.evaluation.functional.disable_gpu_fuser_on_pt19()[源代码]

On PyTorch 1.9 a CUDA fuser bug prevents the Inception JIT model to run.

Refers to:

https://github.com/GaParmar/clean-fid/blob/5e1e84cdea9654b9ac7189306dfa4057ea2213d8/cleanfid/inception_torchscript.py#L9 # noqa https://github.com/GaParmar/clean-fid/issues/5 https://github.com/pytorch/pytorch/issues/64062

mmedit.evaluation.functional.load_inception(inception_args, metric)[源代码]

Load Inception Model from given inception_args and metric.

This function would try to load Inception under the guidance of ‘type’ given in inception_args, if not given, we would try best to load Tero’s ones. In detailly, we would first try to load the model from disk with the given ‘inception_path’, and then try to download the checkpoint from ‘inception_url’. If both method are failed, pytorch version of Inception would be loaded.

参数
  • inception_args (dict) – Keyword args for inception net.

  • metric (string) – Metric to use the Inception. This argument would influence the pytorch’s Inception loading.

返回

Loaded Inception model. style (string): The version of the loaded Inception.

返回类型

model (torch.nn.Module)

mmedit.evaluation.functional.prepare_inception_feat(dataloader: torch.utils.data.dataloader.DataLoader, metric: mmengine.evaluator.BaseMetric, data_preprocessor: Optional[torch.nn.Module] = None, capture_mean_cov: bool = False, capture_all: bool = False) dict[源代码]

Prepare inception feature for the input metric.

  • If metric.inception_pkl is an online path, try to download and load it. If cannot download or load, corresponding error will be raised.

  • If metric.inception_pkl is local path and file exists, try to load the file. If cannot load, corresponding error will be raised.

  • If metric.inception_pkl is local path and file not exists, we will extract the inception feature manually and save to ‘inception_pkl’.

  • If metric.inception_pkl is not defined, we will extrace the inception feature and save it to default cache dir with default name.

参数
  • datalaoder (Dataloader) – The dataloader of real images.

  • metric (BaseMetric) – The metric which needs inception features.

  • data_preprocessor (Optional[nn.Module]) – Data preprocessor of the module. Used to preprocess the real images. If not passed, real images will automatically normalized to [-1, 1]. Defaults to None.

  • capture_mean_cov (bool) – Whether save the mean and covariance of inception feature. Defaults to False.

  • capture_all (bool) – Whether save the raw inception feature. If true, it will take a lot of time to save the inception feature. Defaults to False.

返回

Dict contains inception feature.

返回类型

dict

mmedit.evaluation.functional.prepare_vgg_feat(dataloader: torch.utils.data.dataloader.DataLoader, metric: mmengine.evaluator.BaseMetric, data_preprocessor: Optional[torch.nn.Module] = None, auto_save=True) numpy.ndarray[源代码]

Prepare vgg feature for the input metric.

  • If metric.vgg_pkl is an online path, try to download and load it. If cannot download or load, corresponding error will be raised.

  • If metric.vgg_pkl is local path and file exists, try to load the file. If cannot load, corresponding error will be raised.

  • If metric.vgg_pkl is local path and file not exists, we will extract the vgg feature manually and save to ‘vgg_pkl’.

  • If metric.vgg_pkl is not defined, we will extrace the vgg feature and save it to default cache dir with default name.

参数
  • datalaoder (Dataloader) – The dataloader of real images.

  • metric (BaseMetric) – The metric which needs vgg features.

  • data_preprocessor (Optional[nn.Module]) – Data preprocessor of the module. Used to preprocess the real images. If not passed, real images will automatically normalized to [-1, 1]. Defaults to None.

  • Returns – np.ndarray: Loaded vgg feature.

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.