Shortcuts

mmagic.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 mmagic.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)[source]

Bases: torch.nn.Module

Pretrained InceptionV3 network returning feature maps.

DEFAULT_BLOCK_INDEX = 3
BLOCK_INDEX_BY_DIM
forward(inp)[source]

Get Inception feature maps.

Parameters

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

Returns

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

Return type

list(torch.Tensor)

mmagic.evaluation.functional.gauss_gradient(img, sigma)[source]

Gaussian gradient.

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

Parameters
  • img (np.ndarray) – Input image.

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

Returns

Gaussian gradient of input img.

Return type

np.ndarray

mmagic.evaluation.functional.disable_gpu_fuser_on_pt19()[source]

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

mmagic.evaluation.functional.load_inception(inception_args, metric)[source]

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 detail, 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.

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

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

Returns

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

Return type

model (torch.nn.Module)

mmagic.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[source]

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 extract the inception feature and save it to default cache dir with default name.

Parameters
  • dataloader (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.

Returns

Dict contains inception feature.

Return type

dict

mmagic.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[source]

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 extract the vgg feature and save it to default cache dir with default name.

Parameters
  • dataloader (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
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.