def get_model(model_name: str, pretrained_ckpt: Optional[str]=None, args: Optional[Namespace]=None) -> BaseModel:
    'Return an instance of a chosen model.\n\n    The instance can have configured by he arguments, and load some existing pretrained weights.\n\n    Note that this is different from get_model_reference(), which returns a reference to the model class. The instance,\n    returned by this function, is a class already instantiated. Therefore, the return of this function is equivalent to\n    "return get_model_reference()()", which looks confusing. This can be rewritten as\n    "model_ref = get_model_reference(); return model_ref()".\n\n    Parameters\n    ----------\n    model_name : str\n        Name of the model to get an instance of.\n    pretrained_ckpt : Optional[str], optional\n        Name of the pretrained weight to load or a path to a local checkpoint file.\n    args : Optional[Namespace], optional\n        Some arguments that ill be provided to the model.\n\n    Returns\n    -------\n    BaseModel\n        The instance of the chosen model.\n\n    Raises\n    ------\n    ValueError\n        If the given checkpoint name is not a valid choice.\n    ValueError\n        If a checkpoint name is given, but the model does not have any pretrained weights available.\n\n    See Also\n    --------\n    get_model_reference : To get a reference to the class of a model.\n    '
    model_ref = get_model_reference(model_name)
    if (args is None):
        parser = model_ref.add_model_specific_args()
        args = parser.parse_args([])
    model = model_ref(args)
    if ((pretrained_ckpt is None) and (args is not None) and (args.pretrained_ckpt is not None)):
        pretrained_ckpt = args.pretrained_ckpt
    if (pretrained_ckpt is not None):
        if Path(pretrained_ckpt).exists():
            ckpt_path = pretrained_ckpt
        elif hasattr(model_ref, 'pretrained_checkpoints'):
            ckpt_path = model_ref.pretrained_checkpoints.get(pretrained_ckpt)
            if (ckpt_path is None):
                raise ValueError(f"Invalid checkpoint name {pretrained_ckpt}. Choose one from {{{','.join(model.pretrained_checkpoints.keys())}}}")
        else:
            raise ValueError(f'Cannot find checkpoint {pretrained_ckpt} for model {model_name}')
        device = ('cuda' if torch.cuda.is_available() else 'cpu')
        if Path(ckpt_path).exists():
            ckpt = torch.load(ckpt_path, map_location=torch.device(device))
        else:
            model_dir = ((Path(hub.get_dir()) / 'ptlflow') / 'checkpoints')
            ckpt = hub.load_state_dict_from_url(ckpt_path, model_dir=model_dir, map_location=torch.device(device), check_hash=True)
        state_dict = ckpt['state_dict']
        model.load_state_dict(state_dict)
    return model
Return an instance of a chosen model.

The instance can have configured by he arguments, and load some existing pretrained weights.

Note that this is different from get_model_reference(), which returns a reference to the model class. The instance,
returned by this function, is a class already instantiated. Therefore, the return of this function is equivalent to
"return get_model_reference()()", which looks confusing. This can be rewritten as
"model_ref = get_model_reference(); return model_ref()".

Parameters
----------
model_name : str
    Name of the model to get an instance of.
pretrained_ckpt : Optional[str], optional
    Name of the pretrained weight to load or a path to a local checkpoint file.
args : Optional[Namespace], optional
    Some arguments that ill be provided to the model.

Returns
-------
BaseModel
    The instance of the chosen model.

Raises
------
ValueError
    If the given checkpoint name is not a valid choice.
ValueError
    If a checkpoint name is given, but the model does not have any pretrained weights available.

See Also
--------
get_model_reference : To get a reference to the class of a model.
def get_model(model_name: str, pretrained_ckpt: Optional[str]=None, args: Optional[Namespace]=None) -> BaseModel:
    'Return an instance of a chosen model.\n\n    The instance can have configured by he arguments, and load some existing pretrained weights.\n\n    Note that this is different from get_model_reference(), which returns a reference to the model class. The instance,\n    returned by this function, is a class already instantiated. Therefore, the return of this function is equivalent to\n    "return get_model_reference()()", which looks confusing. This can be rewritten as\n    "model_ref = get_model_reference(); return model_ref()".\n\n    Parameters\n    ----------\n    model_name : str\n        Name of the model to get an instance of.\n    pretrained_ckpt : Optional[str], optional\n        Name of the pretrained weight to load or a path to a local checkpoint file.\n    args : Optional[Namespace], optional\n        Some arguments that ill be provided to the model.\n\n    Returns\n    -------\n    BaseModel\n        The instance of the chosen model.\n\n    Raises\n    ------\n    ValueError\n        If the given checkpoint name is not a valid choice.\n    ValueError\n        If a checkpoint name is given, but the model does not have any pretrained weights available.\n\n    See Also\n    --------\n    get_model_reference : To get a reference to the class of a model.\n    '
    model_ref = get_model_reference(model_name)
    if (args is None):
        parser = model_ref.add_model_specific_args()
        args = parser.parse_args([])
    model = model_ref(args)
    if ((pretrained_ckpt is None) and (args is not None) and (args.pretrained_ckpt is not None)):
        pretrained_ckpt = args.pretrained_ckpt
    if (pretrained_ckpt is not None):
        if Path(pretrained_ckpt).exists():
            ckpt_path = pretrained_ckpt
        elif hasattr(model_ref, 'pretrained_checkpoints'):
            ckpt_path = model_ref.pretrained_checkpoints.get(pretrained_ckpt)
            if (ckpt_path is None):
                raise ValueError(f"Invalid checkpoint name {pretrained_ckpt}. Choose one from {{{','.join(model.pretrained_checkpoints.keys())}}}")
        else:
            raise ValueError(f'Cannot find checkpoint {pretrained_ckpt} for model {model_name}')
        device = ('cuda' if torch.cuda.is_available() else 'cpu')
        if Path(ckpt_path).exists():
            ckpt = torch.load(ckpt_path, map_location=torch.device(device))
        else:
            model_dir = ((Path(hub.get_dir()) / 'ptlflow') / 'checkpoints')
            ckpt = hub.load_state_dict_from_url(ckpt_path, model_dir=model_dir, map_location=torch.device(device), check_hash=True)
        state_dict = ckpt['state_dict']
        model.load_state_dict(state_dict)
    return model