File size: 1,384 Bytes
cc0dd3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright (c) OpenMMLab. All rights reserved.
from typing import Dict

from mmengine.infer import BaseInferencer


def get_model_aliases(scope: str = 'mmpose') -> Dict[str, str]:
    """Retrieve model aliases and their corresponding configuration names.

    Args:
        scope (str, optional): The scope for the model aliases. Defaults
            to 'mmpose'.

    Returns:
        Dict[str, str]: A dictionary containing model aliases as keys and
            their corresponding configuration names as values.
    """

    # Get a list of model configurations from the metafile
    repo_or_mim_dir = BaseInferencer._get_repo_or_mim_dir(scope)
    model_cfgs = BaseInferencer._get_models_from_metafile(repo_or_mim_dir)

    model_alias_dict = dict()
    for model_cfg in model_cfgs:
        if 'Alias' in model_cfg:
            if isinstance(model_cfg['Alias'], str):
                model_alias_dict[model_cfg['Alias']] = model_cfg['Name']
            elif isinstance(model_cfg['Alias'], list):
                for alias in model_cfg['Alias']:
                    model_alias_dict[alias] = model_cfg['Name']
            else:
                raise ValueError(
                    'encounter an unexpected alias type. Please raise an '
                    'issue at https://github.com/open-mmlab/mmpose/issues '
                    'to announce us')

    return model_alias_dict