Shortcuts

mmedit.evaluation.functional.inception_utils

Module Contents

Functions

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.

_load_inception_from_path(inception_path)

Load inception from passed path.

_load_inception_from_url(→ torch.nn.Module)

Load Inception network from the give inception_url

_load_inception_torch(→ torch.nn.Module)

Load Inception network from PyTorch's model zoo.

get_inception_feat_cache_name_and_args(→ Tuple[str, dict])

Get the name and meta info of the inception feature cache file

get_vgg_feat_cache_name_and_args(→ Tuple[str, dict])

Get the name and meta info of the vgg feature cache file corresponding

prepare_inception_feat(→ dict)

Prepare inception feature for the input metric.

prepare_vgg_feat(→ numpy.ndarray)

Prepare vgg feature for the input metric.

Attributes

ALLOWED_INCEPTION

TERO_INCEPTION_URL

mmedit.evaluation.functional.inception_utils.ALLOWED_INCEPTION = ['StyleGAN', 'PyTorch'][源代码]
mmedit.evaluation.functional.inception_utils.TERO_INCEPTION_URL = 'https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/metrics/inception-2015-12-05.pt'[源代码]
mmedit.evaluation.functional.inception_utils.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.inception_utils.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.inception_utils._load_inception_from_path(inception_path)[源代码]

Load inception from passed path.

参数

inception_path (str) – The path of inception.

返回

The loaded inception.

返回类型

nn.Module

mmedit.evaluation.functional.inception_utils._load_inception_from_url(inception_url: str) torch.nn.Module[源代码]

Load Inception network from the give inception_url

mmedit.evaluation.functional.inception_utils._load_inception_torch(inception_args, metric) torch.nn.Module[源代码]

Load Inception network from PyTorch’s model zoo.

mmedit.evaluation.functional.inception_utils.get_inception_feat_cache_name_and_args(dataloader: torch.utils.data.dataloader.DataLoader, metric: mmengine.evaluator.BaseMetric, real_nums: int, capture_mean_cov: bool, capture_all: bool) Tuple[str, dict][源代码]

Get the name and meta info of the inception feature cache file corresponding to the input dataloader and metric.

The meta info includs ‘data_root’, ‘data_prefix’, ‘meta_info’ and ‘pipeline’ of the dataset, and ‘inception_style’ and ‘inception_args’ of the metric. Then we calculate the hash value of the meta info dict with md5, and the name of the inception feature cache will be ‘inception_feat_{HASH}.pkl’. :param datalaoder: The dataloader of real images. :type datalaoder: Dataloader :param metric: The metric which needs inception features. :type metric: BaseMetric :param real_nums: Number of images used to extract inception feature. :type real_nums: int :param capture_mean_cov: Whether save the mean and covariance of

inception feature. Defaults to False.

参数

capture_all (bool) – Whether save the raw inception feature. Defaults to False.

返回

Filename and meta info dict of the inception feature

cache.

返回类型

Tuple[str, dict]

mmedit.evaluation.functional.inception_utils.get_vgg_feat_cache_name_and_args(dataloader: torch.utils.data.dataloader.DataLoader, metric: mmengine.evaluator.BaseMetric) Tuple[str, dict][源代码]

Get the name and meta info of the vgg feature cache file corresponding to the input dataloader and metric.

The meta info includs ‘data_root’, ‘data_prefix’, ‘meta_info’ and ‘pipeline’ of the dataset, and ‘use_tero_scirpt’ of the metric. Then we calculate the hash value of the meta info dict with md5, and the name of the vgg feature cache will be ‘vgg_feat_{HASH}.pkl’. :param datalaoder: The dataloader of real images. :type datalaoder: Dataloader :param metric: The metric which needs inception features. :type metric: BaseMetric

返回

Filename and meta info dict of the inception feature

cache.

返回类型

Tuple[str, dict]

mmedit.evaluation.functional.inception_utils.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.inception_utils.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.