From 9828282626c9fc1e10e64f2702a81bfe2fd7eae4 Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Mon, 25 Jul 2022 13:24:49 +0100 Subject: GitHub #650: DelegateQuickStartGuide.md errors fix. Signed-off-by: Cathal Corbett Change-Id: If24cad1d5d403e195d7adc539afb83cc5df134d1 --- delegate/DelegateQuickStartGuide.md | 8 +++- delegate/python/test/test_external_delegate.py | 58 +++++++++++++------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/delegate/DelegateQuickStartGuide.md b/delegate/DelegateQuickStartGuide.md index b7cdef8f6e..c24a17bcf6 100644 --- a/delegate/DelegateQuickStartGuide.md +++ b/delegate/DelegateQuickStartGuide.md @@ -42,7 +42,11 @@ Pre-requisites: * numpy (Depends on TfLite version) * tflite_runtime (>=2.5, depends on Arm NN Delegate) -If you haven't built the delegate yet then take a look at the [build guide](./BuildGuideNative.md). Otherwise, you can download the binaries [here](https://github.com/ARM-software/armnn/releases/). +If you haven't built the delegate yet then take a look at the [build guide](./BuildGuideNative.md). Otherwise, you can download the binaries [here](https://github.com/ARM-software/armnn/releases/). Set the following environment variable to the location of the .so binary files: + +```bash +export LD_LIBRARY_PATH= +``` We recommend creating a virtual environment for this tutorial. For the following code to work python3 is needed. Please also check the documentation of the TfLite version you want to use. There might be additional prerequisites for the python @@ -73,7 +77,7 @@ you may need to build the pip package from source. You can find more information But in our case, with Tensorflow Lite 2.5.0, we can install through: ``` -pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime +pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime==2.5.0 ``` Your virtual environment is now all setup. Copy the final python script into a python file e.g. diff --git a/delegate/python/test/test_external_delegate.py b/delegate/python/test/test_external_delegate.py index f01a2d3928..a8dd8e6d3e 100644 --- a/delegate/python/test/test_external_delegate.py +++ b/delegate/python/test/test_external_delegate.py @@ -1,4 +1,4 @@ -# Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +# Copyright © 2022 Arm Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT import numpy as np @@ -66,7 +66,7 @@ def test_external_delegate_options_gpu_cached_network(delegate_dir, test_data_fo os.remove(binary_file) # Create blank binary file to write to. - open(binary_file, 'a').close() + open(binary_file, "a").close() assert (os.path.exists(binary_file)) assert (os.stat(binary_file).st_size == 0) @@ -102,11 +102,11 @@ def test_external_delegate_options_gpu_cached_network(delegate_dir, test_data_fo def test_external_delegate_gpu_fastmath(delegate_dir, test_data_folder): # create armnn delegate with enable-fast-math # fast-math is only enabled on Conv2d layer, so use conv2d model. - armnn_delegate = tflite.load_delegate(delegate_dir, options = {'backends': 'GpuAcc', - 'enable-fast-math': '1', + armnn_delegate = tflite.load_delegate(delegate_dir, options = {"backends": "GpuAcc", + "enable-fast-math": "1", "logging-severity": "info"}) - model_file_name = 'conv2d.tflite' + model_file_name = "conv2d.tflite" inputShape = [ 1, 5, 5, 1 ] outputShape = [ 1, 3, 3, 1 ] @@ -131,15 +131,15 @@ def test_external_delegate_gpu_fastmath(delegate_dir, test_data_folder): compare_outputs(armnn_outputs, [expected_output]) @pytest.mark.CpuAccTest -def test_external_delegate_cpu_options(capfd, delegate_dir, test_data_folder): +def test_external_delegate_cpu_options(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', + 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' + model_file_name = "conv2d.tflite" inputShape = [ 1, 5, 5, 1 ] outputShape = [ 1, 3, 3, 1 ] @@ -163,9 +163,6 @@ def test_external_delegate_cpu_options(capfd, delegate_dir, test_data_folder): # 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 - def test_external_delegate_options_wrong_logging_level(delegate_dir): with pytest.raises(ValueError): tflite.load_delegate( @@ -174,9 +171,10 @@ def test_external_delegate_options_wrong_logging_level(delegate_dir): 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'}) + armnn_delegate = tflite.load_delegate(delegate_dir, options = {"backends": "CpuRef", + "debug-data": "1"}) - model_file_name = 'fp32_model.tflite' + model_file_name = "fp32_model.tflite" tensor_shape = [1, 2, 2, 1] @@ -192,16 +190,16 @@ def test_external_delegate_options_debug(capfd, delegate_dir, test_data_folder): compare_outputs(armnn_outputs, [expected_output]) captured = capfd.readouterr() - assert 'layerGuid' in captured.out + assert "layerGuid" in captured.out 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'}) + armnn_delegate = tflite.load_delegate(delegate_dir, options = {"backends": "CpuRef", + "debug-data": "1", + "reduce-fp32-to-fp16": "1"}) - model_file_name = 'fp32_model.tflite' + model_file_name = "fp32_model.tflite" tensor_shape = [1, 2, 2, 1] @@ -217,16 +215,16 @@ def test_external_delegate_options_fp32_to_fp16(capfd, delegate_dir, test_data_f compare_outputs(armnn_outputs, [expected_output]) captured = capfd.readouterr() - assert 'convert_fp32_to_fp16' in captured.out - assert 'convert_fp16_to_fp32' in captured.out + assert "convert_fp32_to_fp16" in captured.out + assert "convert_fp16_to_fp32" in captured.out 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'}) + armnn_delegate = tflite.load_delegate(delegate_dir, options = {"backends": "CpuRef", + "debug-data": "1", + "reduce-fp32-to-bf16": "1"}) - model_file_name = 'conv2d.tflite' + model_file_name = "conv2d.tflite" inputShape = [ 1, 5, 5, 1 ] outputShape = [ 1, 3, 3, 1 ] @@ -251,14 +249,14 @@ def test_external_delegate_options_fp32_to_bf16(capfd, delegate_dir, test_data_f compare_outputs(armnn_outputs, [expected_output]) captured = capfd.readouterr() - assert 'convert_fp32_to_bf16' in captured.out + assert "convert_fp32_to_bf16" in captured.out 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'}) + armnn_delegate = tflite.load_delegate(delegate_dir, options = {"backends": "CpuAcc,CpuRef", + "memory-import": "1"}) - model_file_name = 'fallback_model.tflite' + model_file_name = "fallback_model.tflite" tensor_shape = [1, 2, 2, 1] -- cgit v1.2.1