ARM-software / armnn

Arm NN ML Software. The code here is a read-only mirror of https://review.mlplatform.org/admin/repos/ml/armnn
https://developer.arm.com/products/processors/machine-learning/arm-nn
MIT License
1.14k stars 307 forks source link

armnn_22_05/delegate/DelegateQuickStartGuide.md Errors #650

Closed StuartIanNaylor closed 1 year ago

StuartIanNaylor commented 2 years ago

armnn_22_05/delegate/DelegateQuickStartGuide.md download https://github.com/ARM-software/armnn/releases/download/v22.02/ArmNN-linux-aarch64.tar.gz git clone https://github.com/ARM-software/armnn.git So exactly as stated apart from this makes no diff as later version is avail

 pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple, https://google-coral.github.io/py-repo/
Collecting tflite_runtime
  Downloading tflite_runtime-2.8.0-cp39-cp39-manylinux2014_aarch64.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 3.0 MB/s eta 0:00:00
Collecting numpy>=1.19.2
  Downloading numpy-1.22.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (13.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.4/13.4 MB 3.3 MB/s eta 0:00:00
Installing collected packages: numpy, tflite_runtime
Successfully installed numpy-1.22.4 tflite_runtime-2.8.0
import numpy as np
import tflite_runtime.interpreter as tflite

# Load TFLite model and allocate tensors.
# (if you are using the complete tensorflow package you can find load_delegate in tf.experimental.load_delegate)
armnn_delegate = tflite.load_delegate( library="/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so",
                                       options={"backends": "CpuAcc,GpuAcc,CpuRef", "logging-severity":"info"})
# Delegates/Executes all operations supported by Arm NN to/with Arm NN
interpreter = tflite.Interpreter(model_path="/home/pi/armnn/delegate/python/test/test_data/mock_model.tflite", 
                                 experimental_delegates=[armnn_delegate])
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test model on random input data.
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.uint8)
interpreter.set_tensor(input_details[0]['index'], input_data)

interpreter.invoke()

# Print out result
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)

I am expecting this but just so you know

python ExternalDelegatePythonTutorial.py
Traceback (most recent call last):
  File "/home/pi/dtest/ExternalDelegatePythonTutorial.py", line 6, in <module>
    armnn_delegate = tflite.load_delegate( library="/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so",
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 175, in load_delegate
    delegate = Delegate(library, options)
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 83, in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
  File "/usr/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libarmnn.so.28: cannot open shared object file: No such file or directory
Exception ignored in: <function Delegate.__del__ at 0x7f829c8ca0>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'

Ok pip install pytest cd ../armnn/delegate/python/test

pytest --delegate-dir="/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so" -m "not GpuAccTest"
================================================================================= test session starts =================================================================================
platform linux -- Python 3.9.2, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/pi/armnn/delegate/python/test, configfile: pytest.ini
collected 11 items / 3 deselected / 8 selected

test_external_delegate.py FException ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
FFFFFFF                                                                                                                                              [100%]

====================================================================================== FAILURES =======================================================================================
______________________________________________ test_external_delegate_unknown_options[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] _______________________________________________

delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'

    def test_external_delegate_unknown_options(delegate_dir):
        print(delegate_dir)
        with pytest.raises(ValueError):
>           tflite.load_delegate(
                delegate_dir,
                options={"wrong": "wrong"})

test_external_delegate.py:13:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f90edec70>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
-------------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------------
/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so
_________________________________________ test_external_delegate_options_multiple_backends[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] __________________________________________

delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'

    def test_external_delegate_options_multiple_backends(delegate_dir):
>       tflite.load_delegate(
            delegate_dir,
            options={"backends": "GpuAcc,CpuAcc,CpuRef,Unknown"})

test_external_delegate.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f90707f10>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
________________________________________________ test_external_delegate_cpu_options[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] _________________________________________________

capfd = <_pytest.capture.CaptureFixture object at 0x7f906f4d90>, delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'
test_data_folder = '/home/pi/armnn/delegate/python/test/test_data'

    @pytest.mark.CpuAccTest
    def test_external_delegate_cpu_options(capfd, delegate_dir, test_data_folder):
        # create armnn delegate with enable-fast-math and number-of-threads options
        # fast-math is only enabled on Conv2d layer, so use conv2d model.
>       armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'CpuAcc',
                                                                       'enable-fast-math': '1',
                                                                       'number-of-threads': '4',
                                                                       "logging-severity": "info"})

test_external_delegate.py:137:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f906f4430>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
________________________________________ test_external_delegate_options_wrong_logging_level[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] _________________________________________

delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'

    def test_external_delegate_options_wrong_logging_level(delegate_dir):
        with pytest.raises(ValueError):
>           tflite.load_delegate(
                delegate_dir,
                options={"logging-severity": "wrong"})

test_external_delegate.py:171:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f90770040>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
_______________________________________________ test_external_delegate_options_debug[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] ________________________________________________

capfd = <_pytest.capture.CaptureFixture object at 0x7f9067ac10>, delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'
test_data_folder = '/home/pi/armnn/delegate/python/test/test_data'

    def test_external_delegate_options_debug(capfd, delegate_dir, test_data_folder):
        # create armnn delegate with debug option
>       armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'CpuRef', 'debug-data': '1'})

test_external_delegate.py:177:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f9067afd0>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
____________________________________________ test_external_delegate_options_fp32_to_fp16[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] ____________________________________________

capfd = <_pytest.capture.CaptureFixture object at 0x7f9076a550>, delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'
test_data_folder = '/home/pi/armnn/delegate/python/test/test_data'

    def test_external_delegate_options_fp32_to_fp16(capfd, delegate_dir, test_data_folder):
        # create armnn delegate with reduce-fp32-to-fp16 option
>       armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'CpuRef',
                                                                       'debug-data': '1',
                                                                       'reduce-fp32-to-fp16': '1'})

test_external_delegate.py:200:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f9076a310>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
____________________________________________ test_external_delegate_options_fp32_to_bf16[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] ____________________________________________

capfd = <_pytest.capture.CaptureFixture object at 0x7f90791eb0>, delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'
test_data_folder = '/home/pi/armnn/delegate/python/test/test_data'

    def test_external_delegate_options_fp32_to_bf16(capfd, delegate_dir, test_data_folder):
        # create armnn delegate with reduce-fp32-to-bf16 option
>       armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'CpuRef',
                                                                       'debug-data': '1',
                                                                       'reduce-fp32-to-bf16': '1'})

test_external_delegate.py:225:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f907915e0>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
___________________________________________ test_external_delegate_options_memory_import[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] ____________________________________________

delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', test_data_folder = '/home/pi/armnn/delegate/python/test/test_data'

    def test_external_delegate_options_memory_import(delegate_dir, test_data_folder):
        # create armnn delegate with memory-import option
>       armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'CpuAcc,CpuRef',
                                                                       'memory-import': '1'})

test_external_delegate.py:258:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:175: in load_delegate
    delegate = Delegate(library, options)
/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py:83: in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
/usr/lib/python3.9/ctypes/__init__.py:452: in LoadLibrary
    return self._dlltype(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PyDLL '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', handle 0 at 0x7f907017f0>, name = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so', mode = 0, handle = None
use_errno = False, use_last_error = False, winmode = None

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False,
                 winmode=None):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR
        if _sys.platform.startswith("aix"):
            """When the name contains ".a(" and ends with ")",
               e.g., "libFOO.a(libFOO.so)" - this is taken to be an
               archive(member) syntax for dlopen(), and the mode is adjusted.
               Otherwise, name is presented to dlopen() as a file argument.
            """
            if name and name.endswith(")") and ".a(" in name:
                mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
        if _os.name == "nt":
            if winmode is not None:
                mode = winmode
            else:
                import nt
                mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
                if '/' in name or '\\' in name:
                    self._name = nt._getfullpathname(self._name)
                    mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
>           self._handle = _dlopen(self._name, mode)
E           OSError: libarmnn.so.28: cannot open shared object file: No such file or directory

/usr/lib/python3.9/ctypes/__init__.py:374: OSError
=============================================================================== short test summary info ===============================================================================
FAILED test_external_delegate.py::test_external_delegate_unknown_options[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared object file...
FAILED test_external_delegate.py::test_external_delegate_options_multiple_backends[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared o...
FAILED test_external_delegate.py::test_external_delegate_cpu_options[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared object file: No...
FAILED test_external_delegate.py::test_external_delegate_options_wrong_logging_level[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared...
FAILED test_external_delegate.py::test_external_delegate_options_debug[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared object file: ...
FAILED test_external_delegate.py::test_external_delegate_options_fp32_to_fp16[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared object...
FAILED test_external_delegate.py::test_external_delegate_options_fp32_to_bf16[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared object...
FAILED test_external_delegate.py::test_external_delegate_options_memory_import[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - OSError: libarmnn.so.28: cannot open shared objec...
=========================================================================== 8 failed, 3 deselected in 2.63s ===========================================================================
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Exception ignored in: <function Delegate.__del__ at 0x7f90ee3700>
Traceback (most recent call last):
  File "/home/pi/dtest/myenv/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 118, in __del__
AttributeError: 'Delegate' object has no attribute '_library'

I have been ok just copy to the local test dir and maybe this is the start of where I am going wrong

libarmnn.so
libarmnn.so.28
libarmnn.so.28.0
 pytest --delegate-dir="/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so" -m "not GpuAccTest"
================================================================================= test session starts =================================================================================
platform linux -- Python 3.9.2, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/pi/armnn/delegate/python/test, configfile: pytest.ini
collected 11 items / 3 deselected / 8 selected

test_external_delegate.py ..F.....                                                                                                                                              [100%]

====================================================================================== FAILURES =======================================================================================
________________________________________________ test_external_delegate_cpu_options[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] _________________________________________________

capfd = <_pytest.capture.CaptureFixture object at 0x7fa17ca100>, delegate_dir = '/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so'
test_data_folder = '/home/pi/armnn/delegate/python/test/test_data'

    @pytest.mark.CpuAccTest
    def test_external_delegate_cpu_options(capfd, delegate_dir, test_data_folder):
        # create armnn delegate with enable-fast-math and number-of-threads options
        # fast-math is only enabled on Conv2d layer, so use conv2d model.
        armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'CpuAcc',
                                                                       'enable-fast-math': '1',
                                                                       'number-of-threads': '4',
                                                                       "logging-severity": "info"})

        model_file_name = 'conv2d.tflite'

        inputShape = [ 1, 5, 5, 1 ]
        outputShape = [ 1, 3, 3, 1 ]

        inputValues = [ 1, 5, 2, 3, 5,
                        8, 7, 3, 6, 3,
                        3, 3, 9, 1, 9,
                        4, 1, 8, 1, 3,
                        6, 8, 1, 9, 2 ]

        expectedResult = [ 28, 38, 29,
                           96, 104, 53,
                           31, 55, 24 ]

        input = np.array(inputValues, dtype=np.float32).reshape(inputShape)
        expected_output = np.array(expectedResult, dtype=np.float32).reshape(outputShape)

        # run the inference
        armnn_outputs = run_inference(test_data_folder, model_file_name, [input], [armnn_delegate])

        # check results
        compare_outputs(armnn_outputs, [expected_output])

        captured = capfd.readouterr()
>       assert 'Set CPPScheduler to Linear mode, with 4 threads to use' in captured.out
E       AssertionError: assert 'Set CPPScheduler to Linear mode, with 4 threads to use' in 'Info: ArmNN v28.0.0\nInfo: Initialization time: 0.58 ms.\nInfo: ArmnnSubgraph creation\nInfo: Parse nodes to ArmNN ti...ad ArmnnSubgraph time: 3.61 ms\nInfo: Overall ArmnnSubgraph creation time: 4.64 ms\n\nInfo: Execution time: 0.38 ms.\n'
E        +  where 'Info: ArmNN v28.0.0\nInfo: Initialization time: 0.58 ms.\nInfo: ArmnnSubgraph creation\nInfo: Parse nodes to ArmNN ti...ad ArmnnSubgraph time: 3.61 ms\nInfo: Overall ArmnnSubgraph creation time: 4.64 ms\n\nInfo: Execution time: 0.38 ms.\n' = CaptureResult(out='Info: ArmNN v28.0.0\nInfo: Initialization time: 0.58 ms.\nInfo: ArmnnSubgraph creation\nInfo: Parse...ubgraph time: 3.61 ms\nInfo: Overall ArmnnSubgraph creation time: 4.64 ms\n\nInfo: Execution time: 0.38 ms.\n', err='').out

test_external_delegate.py:167: AssertionError
=============================================================================== short test summary info ===============================================================================
FAILED test_external_delegate.py::test_external_delegate_cpu_options[/home/pi/ArmNN-linux-aarch64/libarmnnDelegate.so] - AssertionError: assert 'Set CPPScheduler to Linear mode, wi...
====================================================================== 1 failed, 7 passed, 3 deselected in 0.96s ======================================================================
Info: Shutdown time: 0.18 ms.

Also same with python ExternalDelegatePythonTutorial.py copy so libarmnn is local

Info: ArmNN v28.0.0
Can't load libOpenCL.so: libOpenCL.so: cannot open shared object file: No such file or directory
Can't load libGLES_mali.so: libGLES_mali.so: cannot open shared object file: No such file or directory
Can't load libmali.so: libmali.so: cannot open shared object file: No such file or directory
Couldn't find any OpenCL library.
Info: Initialization time: 2.80 ms.
INFO: TfLiteArmnnDelegate: Requested unknown backend GpuAcc
INFO: TfLiteArmnnDelegate: Created TfLite ArmNN delegate.
Warning: The backend makes use of a deprecated interface to read constant tensors. If you are a backend developer please find more information in our doxygen documentation on github https://github.com/ARM-software/armnn under the keyword 'ConstTensorsAsInputs'.
Info: ArmnnSubgraph creation
Info: Parse nodes to ArmNN time: 0.30 ms
Warning: The backend makes use of a deprecated interface to read constant tensors. If you are a backend developer please find more information in our doxygen documentation on github https://github.com/ARM-software/armnn under the keyword 'ConstTensorsAsInputs'.
Info: Optimize ArmnnSubgraph time: 1.70 ms
Info: Load ArmnnSubgraph time: 5.14 ms
Info: Overall ArmnnSubgraph creation time: 7.51 ms

Info: Execution time: 2.97 ms.
[[ 12 123  16  12  11  14  20  16  20  12]]
Info: Shutdown time: 0.45 ms.

Have not tried my own tflite models as expecting them to still seg fault as yeah works but still having to copy libarmnn local so guessing it will still be the same. Any chance of binaries for the latest release than just src?

StuartIanNaylor commented 2 years ago

PS should say wget https://github.com/google-coral/pycoral/releases/download/v2.0.0/tflite_runtime-2.5.0.post1-cp39-cp39-linux_aarch64.whl#sha256=9839c3acb506b5003a9bd3860329a8ae20e675efbae14dbea02659b0054f42c6

ensures you get that tflite version as pip install tflite-runtime installs latest pip install tflite_runtime-2.5.0.post1-cp39-cp39-linux_aarch64.whl

catcor01 commented 1 year ago

Hello @StuartIanNaylor,

I have updated the Delegate Quick Start Guide with your suggestions.

The main updates are:

Additionally, I removed the assert in test_external_delegate_cpu_options as that is an error coming from Compute Library that is now not being thrown.

Thank you for reporting ArmNN guide problems and hope issues have been resolved in relation to this guide.

Kind Regards, Cathal.

StuartIanNaylor commented 1 year ago

Thnx, I will give it another go myself :)