ARM-software / ComputeLibrary

The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
MIT License
2.76k stars 767 forks source link

Need help with TensorFlow Model Data Extraction #981

Closed asharma-ampere closed 1 year ago

asharma-ampere commented 2 years ago

I want to run inference using ACL. I am using examples/graph_resnet50.cpp and examples/graph_resnet_v2_50.cpp as reference. I got models from following locations: http://download.tensorflow.org/models/resnet_v1_50_2016_08_28.tar.gz http://download.tensorflow.org/models/resnet_v2_50_2017_04_14.tar.gz

These contains .ckpt files only. To convert these using scripts/tensorflow_data_extractor.py, need to supply .meta files for both. I used TensorFlow docker 1.3.0-py3 to get it from slim models. But facing version issues. Can you share .meta files for these?

morgolock commented 2 years ago

Hi @asharma-ampere

The best option is to use ArmNN's ExecuteNetwork tool to run a tflite model through ACL. Please see https://github.com/ARM-software/armnn/tree/branches/armnn_22_05/tests/ExecuteNetwork

Using ExecuteNetwork you can run tflite models as shown below: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ExecuteNetwork -m ../tflite_models/mobilenet_v2_1.0_224_quant.tflite -c CpuAcc -f tflite-binary -i input -o output

You could use the -e to enable the profiler and read the performance figures.

Hope this helps.

asharma-ampere commented 2 years ago

So there is no way to use graph_xyz examples supplied in ACL (except AlexNet{graph_alexnet.cpp} for which weights are available)?

morgolock commented 2 years ago

Hi @asharma-ampere

ACL does not provide a solution out of the box to go from a tensorflow model to an ACL graph example. The best way to run a tflite model through ACL is using ArmNN's ExecuteNetwork tool.

If you wish to use the ACL graph example you need to find a way to export the model's parameters from the TF file and make sure the layer's names are the same as the ones used in our graph example. The script https://github.com/ARM-software/ComputeLibrary/blob/main/scripts/tensorflow_data_extractor.py is no longer maintained because we advice using ArmNN.

Hope this helps.

asharma-ampere commented 2 years ago

I tried armnn on AWS instance but getting Segmentation fault (core dumped) while using Bfloat16 (--bf16-turbo-mode) (Without --bf16-turbo-mode it works)

How to reproduce: $ mkdir armnn $ cd armnn $ wget https://github.com/ARM-software/armnn/releases/download/v22.05.01/ArmNN-linux-aarch64.tar.gz $ tar -xf ArmNN-linux-aarch64.tar.gz $ wget https://github.com/frogermcs/TFLite-Checker/raw/master/android/ImageClassificationTester/app/src/main/assets/mobilenet_v2_1.0_224.tflite

$ LD_LIBRARY_PATH=. ./ExecuteNetwork -m mobilenet_v2_1.0_224.tflite -c CpuAcc -f tflite-binary -i input -o MobilenetV2/Predictions/Reshape_1 --bf16-turbo-mode

Warning: No input files provided, input tensors will be filled with 0s. Info: ArmNN v29.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: 0.49 ms. Info: Network parsing time: 54.54 ms. Info: Optimization time: 9.88 ms. Segmentation fault (core dumped)

AWS CPU information (for last CPU of system): processor : 63 BogoMIPS : 2100.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm ssbs paca pacg dcpodp svei8mm svebf16 i8mm bf16 dgh rng CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x1 CPU part : 0xd40 CPU revision : 1

morgolock commented 1 year ago

Hi @asharma-ampere

The problem is fixed with the following ArmNN patch: https://review.mlplatform.org/c/ml/armnn/+/7944

Hope this helps.

asharma-ampere commented 1 year ago

Looks like official release is still v22.05.01. I will give it a try as soon as it will be available in the official release.

asharma-ampere commented 1 year ago

It works on Release v22.08.