mmdeploy/utils/test.py
def backend_checker(backend: Backend, require_plugin: bool = False):
    """A decorator which checks if a backend is available.

    Args:
        backend (Backend): The backend needs to be checked.
        require_plugin (bool): The checker will check if the backend package
            has been installed. If this variable is `True`, then the checker
            will also check if the backend plugin has been compiled. Default
            to `False`.
    """
    is_plugin_available = None
    if backend == Backend.ONNXRUNTIME:
        from mmdeploy.apis.onnxruntime import is_available
        if require_plugin:
            from mmdeploy.apis.onnxruntime import is_plugin_available
    elif backend == Backend.TENSORRT:
        from mmdeploy.apis.tensorrt import is_available
        if require_plugin:
            from mmdeploy.apis.tensorrt import is_plugin_available
    elif backend == Backend.PPLNN:
        from mmdeploy.apis.pplnn import is_available
    elif backend == Backend.NCNN:
        from mmdeploy.apis.ncnn import is_available
        if require_plugin:
            from mmdeploy.apis.ncnn import is_plugin_available
    elif backend == Backend.OPENVINO:
        from mmdeploy.apis.openvino import is_available
    else:
        warnings.warn('The backend checker is not available')
        return

    checker = pytest.mark.skipif(
        not is_available(), reason=f'{backend.value} package is not available')
    if require_plugin and is_plugin_available is not None:
        plugin_checker = pytest.mark.skipif(
            not is_plugin_available(),
            reason=f'{backend.value} plugin is not available')

        def double_checker(func):
            func = checker(func)
            func = plugin_checker(func)
            return func

        return double_checker

    return checker
A decorator which checks if a backend is available.

    Args:
        backend (Backend): The backend needs to be checked.
        require_plugin (bool): The checker will check if the backend package
            has been installed. If this variable is `True`, then the checker
            will also check if the backend plugin has been compiled. Default
            to `False`.
    
A decorator which checks if a backend is available.
A decorator which checks if a backend is available .
def backend_checker(backend: Backend, require_plugin: bool = False):
    is_plugin_available = None
    if backend == Backend.ONNXRUNTIME:
        from mmdeploy.apis.onnxruntime import is_available
        if require_plugin:
            from mmdeploy.apis.onnxruntime import is_plugin_available
    elif backend == Backend.TENSORRT:
        from mmdeploy.apis.tensorrt import is_available
        if require_plugin:
            from mmdeploy.apis.tensorrt import is_plugin_available
    elif backend == Backend.PPLNN:
        from mmdeploy.apis.pplnn import is_available
    elif backend == Backend.NCNN:
        from mmdeploy.apis.ncnn import is_available
        if require_plugin:
            from mmdeploy.apis.ncnn import is_plugin_available
    elif backend == Backend.OPENVINO:
        from mmdeploy.apis.openvino import is_available
    else:
        warnings.warn('The backend checker is not available')
        return
    checker = pytest.mark.skipif(
        not is_available(), reason=f'{backend.value} package is not available')
    if require_plugin and is_plugin_available is not None:
        plugin_checker = pytest.mark.skipif(
            not is_plugin_available(),
            reason=f'{backend.value} plugin is not available')
        def double_checker(func):
            func = checker(func)
            func = plugin_checker(func)
            return func
        return double_checker
    return checker
def backend_checker ( backend : Backend , require_plugin : bool = False ) : is_plugin_available = None if backend == Backend . ONNXRUNTIME : from mmdeploy . apis . onnxruntime import is_available if require_plugin : from mmdeploy . apis . onnxruntime import is_plugin_available elif backend == Backend . TENSORRT : from mmdeploy . apis . tensorrt import is_available if require_plugin : from mmdeploy . apis . tensorrt import is_plugin_available elif backend == Backend . PPLNN : from mmdeploy . apis . pplnn import is_available elif backend == Backend . NCNN : from mmdeploy . apis . ncnn import is_available if require_plugin : from mmdeploy . apis . ncnn import is_plugin_available elif backend == Backend . OPENVINO : from mmdeploy . apis . openvino import is_available else : warnings . warn ( 'The backend checker is not available' ) return checker = pytest . mark . skipif ( not is_available ( ) , reason = f'{backend.value} package is not available' ) if require_plugin and is_plugin_available is not None : plugin_checker = pytest . mark . skipif ( not is_plugin_available ( ) , reason = f'{backend.value} plugin is not available' ) def double_checker ( func ) : func = checker ( func ) func = plugin_checker ( func ) return func return double_checker return checker
A decorator which checks if a backend is available.
A decorator which checks if a backend is available .
"""A decorator which checks if a backend is available.

    Args:
        backend (Backend): The backend needs to be checked.
        require_plugin (bool): The checker will check if the backend package
            has been installed. If this variable is `True`, then the checker
            will also check if the backend plugin has been compiled. Default
            to `False`.
    """
backend
Backend
The backend needs to be checked.
The backend needs to be checked .
require_plugin
bool
The checker will check if the backend package
has been installed. If this variable is `True`, then the checker
will also check if the backend plugin has been compiled. Default
to `False`.
The checker will check if the backend package has been installed . If this variable is ` True ` then the checker will also check if the backend plugin has been compiled . Default to ` False ` .