def get_callbacks(config: DictConfig | ListConfig | Namespace) -> list[Callback]:
    """Get default callbacks for Anomalib models based on configuration.

    This function returns a list of callbacks based on the provided configuration.
    It automatically adds:

    - Model loading callback if checkpoint path is specified
    - NNCF optimization callback if NNCF optimization is enabled

    Args:
        config (DictConfig | ListConfig | Namespace): Configuration object containing model and training settings.
            Expected to have the following structure:

            .. code-block:: yaml

                trainer:
                    ckpt_path: Optional[str]  # Path to model checkpoint
                optimization:
                    nncf:
                        apply: bool  # Whether to apply NNCF optimization
                        # Other NNCF config options
                project:
                    path: str  # Project directory path

    Returns:
        list[Callback]: List of PyTorch Lightning callbacks to be used during training.
            May include:

            - :class:`LoadModelCallback`: For loading model checkpoints
            - :class:`NNCFCallback`: For neural network compression
            - Other default callbacks

    Example:
        >>> from omegaconf import DictConfig
        >>> config = DictConfig({
        ...     "trainer": {"ckpt_path": None},
        ...     "project": {"path": "/tmp"},
        ...     "optimization": {"nncf": {"apply": False}}
        ... })
        >>> callbacks = get_callbacks(config)
        >>> isinstance(callbacks, list)
        True

    Note:
        NNCF is imported dynamically only when required since it conflicts with
        some kornia JIT operations.
    """
    logger.info("Loading the callbacks")

    callbacks: list[Callback] = []

    if "ckpt_path" in config.trainer and config.ckpt_path is not None:
        load_model = LoadModelCallback(config.ckpt_path)
        callbacks.append(load_model)

    if "optimization" in config and "nncf" in config.optimization and config.optimization.nncf.apply:
        # NNCF wraps torch's jit which conflicts with kornia's jit calls.
        # Hence, nncf is imported only when required
        nncf_module = import_module("anomalib.utils.callbacks.nncf.callback")
        nncf_callback = nncf_module.NNCFCallback
        nncf_config = yaml.safe_load(OmegaConf.to_yaml(config.optimization.nncf))
        callbacks.append(
            nncf_callback(
                config=nncf_config,
                export_dir=str(Path(config.project.path) / "compressed"),
            ),
        )

    return callbacks
Get default callbacks for Anomalib models based on configuration.

    This function returns a list of callbacks based on the provided configuration.
    It automatically adds:

    - Model loading callback if checkpoint path is specified
    - NNCF optimization callback if NNCF optimization is enabled

    Args:
        config (DictConfig | ListConfig | Namespace): Configuration object containing model and training settings.
            Expected to have the following structure:

            .. code-block:: yaml

                trainer:
                    ckpt_path: Optional[str]  # Path to model checkpoint
                optimization:
                    nncf:
                        apply: bool  # Whether to apply NNCF optimization
                        # Other NNCF config options
                project:
                    path: str  # Project directory path

    Returns:
        list[Callback]: List of PyTorch Lightning callbacks to be used during training.
            May include:

            - :class:`LoadModelCallback`: For loading model checkpoints
            - :class:`NNCFCallback`: For neural network compression
            - Other default callbacks

    Example:
        >>> from omegaconf import DictConfig
        >>> config = DictConfig({
        ...     "trainer": {"ckpt_path": None},
        ...     "project": {"path": "/tmp"},
        ...     "optimization": {"nncf": {"apply": False}}
        ... })
        >>> callbacks = get_callbacks(config)
        >>> isinstance(callbacks, list)
        True

    Note:
        NNCF is imported dynamically only when required since it conflicts with
        some kornia JIT operations.
    
src/anomalib/callbacks/__init__.py