mmagic.evaluation.functional.inception_utils
¶
Module Contents¶
Functions¶
On PyTorch 1.9 a CUDA fuser bug prevents the Inception JIT model to run. |
|
|
Load Inception Model from given |
|
Load inception from passed path. |
|
Load Inception network from the give inception_url |
|
Load Inception network from PyTorch's model zoo. |
|
Get the name and meta info of the inception feature cache file |
|
Get the name and meta info of the vgg feature cache file corresponding |
|
Prepare inception feature for the input metric. |
|
Prepare vgg feature for the input metric. |
Attributes¶
- mmagic.evaluation.functional.inception_utils.TERO_INCEPTION_URL = https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/metrics/inception-2015-12-05.pt[source]¶
- mmagic.evaluation.functional.inception_utils.disable_gpu_fuser_on_pt19()[source]¶
On PyTorch 1.9 a CUDA fuser bug prevents the Inception JIT model to run.
- mmagic.evaluation.functional.inception_utils.load_inception(inception_args, metric)[source]¶
Load Inception Model from given
inception_args
andmetric
.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.inception_utils._load_inception_from_path(inception_path)[source]¶
Load inception from passed path.
- Parameters
inception_path (str) – The path of inception.
- Returns
The loaded inception.
- Return type
nn.Module
- mmagic.evaluation.functional.inception_utils._load_inception_from_url(inception_url: str) torch.nn.Module [source]¶
Load Inception network from the give inception_url
- mmagic.evaluation.functional.inception_utils._load_inception_torch(inception_args, metric) torch.nn.Module [source]¶
Load Inception network from PyTorch’s model zoo.
- mmagic.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] [source]¶
Get the name and meta info of the inception feature cache file corresponding to the input dataloader and metric.
The meta info includes ‘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 dataloader: The dataloader of real images. :type dataloader: 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.
- Parameters
capture_all (bool) – Whether save the raw inception feature. Defaults to False.
- Returns
- Filename and meta info dict of the inception feature
cache.
- Return type
Tuple[str, dict]
- mmagic.evaluation.functional.inception_utils.get_vgg_feat_cache_name_and_args(dataloader: torch.utils.data.dataloader.DataLoader, metric: mmengine.evaluator.BaseMetric) Tuple[str, dict] [source]¶
Get the name and meta info of the vgg feature cache file corresponding to the input dataloader and metric.
The meta info includes ‘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 dataloader: The dataloader of real images. :type dataloader: Dataloader :param metric: The metric which needs inception features. :type metric: BaseMetric
- Returns
- Filename and meta info dict of the inception feature
cache.
- Return type
Tuple[str, dict]
- mmagic.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 [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.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 [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.