Skip to content

ModelRegistry

ModelRegistry #

Central registry of pretrained models.

This class serves as a centralized registry for all pretrained models in the Focoos system. It provides methods to access model information, list available models, and check model existence.

Attributes:

Name Type Description
_pretrained_models Dict[str, str]

Dictionary mapping model names to their JSON file paths.

Source code in focoos/model_registry/model_registry.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class ModelRegistry:
    """Central registry of pretrained models.

    This class serves as a centralized registry for all pretrained models in the Focoos system.
    It provides methods to access model information, list available models, and check model existence.

    Attributes:
        _pretrained_models (Dict[str, str]): Dictionary mapping model names to their JSON file paths.
    """

    _pretrained_models: Dict[str, str] = {
        "fai-detr-l-obj365": os.path.join(REGISTRY_PATH, "fai-detr-l-obj365.json"),
        "fai-detr-l-coco": os.path.join(REGISTRY_PATH, "fai-detr-l-coco.json"),
        "fai-detr-m-coco": os.path.join(REGISTRY_PATH, "fai-detr-m-coco.json"),
        "fai-mf-l-ade": os.path.join(REGISTRY_PATH, "fai-mf-l-ade.json"),
        "fai-mf-m-ade": os.path.join(REGISTRY_PATH, "fai-mf-m-ade.json"),
        "fai-mf-l-coco-ins": os.path.join(REGISTRY_PATH, "fai-mf-l-coco-ins.json"),
        "fai-mf-m-coco-ins": os.path.join(REGISTRY_PATH, "fai-mf-m-coco-ins.json"),
        "fai-mf-s-coco-ins": os.path.join(REGISTRY_PATH, "fai-mf-s-coco-ins.json"),
        "bisenetformer-m-ade": os.path.join(REGISTRY_PATH, "bisenetformer-m-ade.json"),
        "bisenetformer-l-ade": os.path.join(REGISTRY_PATH, "bisenetformer-l-ade.json"),
        "bisenetformer-s-ade": os.path.join(REGISTRY_PATH, "bisenetformer-s-ade.json"),
    }

    @classmethod
    def get_model_info(cls, model_name: str) -> ModelInfo:
        """Get the model information for a given model name.

        Args:
            model_name (str): The name of the model to retrieve information for.
                Can be either a pretrained model name or a path to a JSON file.

        Returns:
            ModelInfo: The model information object containing model details.

        Raises:
            ValueError: If the model is not found in the registry and the provided
                path does not exist.
        """
        if model_name in cls._pretrained_models:
            return ModelInfo.from_json(cls._pretrained_models[model_name])
        if not os.path.exists(model_name):
            logger.warning(f"⚠️ Model {model_name} not found")
            raise ValueError(f"⚠️ Model {model_name} not found")
        return ModelInfo.from_json(model_name)

    @classmethod
    def list_models(cls) -> list[str]:
        """List all available pretrained models.

        Returns:
            list[str]: A list of all available pretrained model names.
        """
        return list(cls._pretrained_models.keys())

    @classmethod
    def exists(cls, model_name: str) -> bool:
        """Check if a model exists in the registry.

        Args:
            model_name (str): The name of the model to check.

        Returns:
            bool: True if the model exists in the pretrained models registry,
                False otherwise.
        """
        return model_name in cls._pretrained_models

exists(model_name) classmethod #

Check if a model exists in the registry.

Parameters:

Name Type Description Default
model_name str

The name of the model to check.

required

Returns:

Name Type Description
bool bool

True if the model exists in the pretrained models registry, False otherwise.

Source code in focoos/model_registry/model_registry.py
67
68
69
70
71
72
73
74
75
76
77
78
@classmethod
def exists(cls, model_name: str) -> bool:
    """Check if a model exists in the registry.

    Args:
        model_name (str): The name of the model to check.

    Returns:
        bool: True if the model exists in the pretrained models registry,
            False otherwise.
    """
    return model_name in cls._pretrained_models

get_model_info(model_name) classmethod #

Get the model information for a given model name.

Parameters:

Name Type Description Default
model_name str

The name of the model to retrieve information for. Can be either a pretrained model name or a path to a JSON file.

required

Returns:

Name Type Description
ModelInfo ModelInfo

The model information object containing model details.

Raises:

Type Description
ValueError

If the model is not found in the registry and the provided path does not exist.

Source code in focoos/model_registry/model_registry.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@classmethod
def get_model_info(cls, model_name: str) -> ModelInfo:
    """Get the model information for a given model name.

    Args:
        model_name (str): The name of the model to retrieve information for.
            Can be either a pretrained model name or a path to a JSON file.

    Returns:
        ModelInfo: The model information object containing model details.

    Raises:
        ValueError: If the model is not found in the registry and the provided
            path does not exist.
    """
    if model_name in cls._pretrained_models:
        return ModelInfo.from_json(cls._pretrained_models[model_name])
    if not os.path.exists(model_name):
        logger.warning(f"⚠️ Model {model_name} not found")
        raise ValueError(f"⚠️ Model {model_name} not found")
    return ModelInfo.from_json(model_name)

list_models() classmethod #

List all available pretrained models.

Returns:

Type Description
list[str]

list[str]: A list of all available pretrained model names.

Source code in focoos/model_registry/model_registry.py
58
59
60
61
62
63
64
65
@classmethod
def list_models(cls) -> list[str]:
    """List all available pretrained models.

    Returns:
        list[str]: A list of all available pretrained model names.
    """
    return list(cls._pretrained_models.keys())