Project

General

Profile

Actions

Task #59092

closed

Task #49925: WP 6: first level trigger (FLT)

Task #49929: WP 6.4: frontend implementation

Compilation de tensorflow lite

Added by Colley Jean-Marc about 1 year ago. Updated 27 days ago.

Status:
Closed
Priority:
Normal
Assigned To:
Category:
-
Start date:
11/06/2023
Due date:
% Done:

100%

Estimated time:
Remaining (hours)0.0

Description

1) Définir la procédure pour compiler tensorflow lite sur le Soc Xilinx
2) Comment créer un exécutable sur le soc utlisant cette bibliothèque
3) conversion format de model

Actions #2

Updated by Colley Jean-Marc about 1 year ago

[ 96%] Building CXX object CMakeFiles/tensorflowlite_c.dir/c_api_experimental.cc.o
/home/grand/install/xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ -DPTHREADPOOL_NO_DEPRECATED_API=1 -Dtensorflowlite_c_EXPORTS -I/home/grand/install/tf_lite/tensorflow_src -I/home/grand/install/tf_lite/tensorflow_src/tensorflow/lite/schema -I/home/grand/install/tf_lite/tflite_build/eigen -I/home/grand/install/tf_lite/tflite_build/neon2sse -I/home/grand/install/tf_lite/tflite_build/abseil-cpp -I/home/grand/install/tf_lite/tflite_build/farmhash/src -I/home/grand/install/tf_lite/tflite_build/flatbuffers/include -I/home/grand/install/tf_lite/tflite_build/gemmlowp/public -I/home/grand/install/tf_lite/tflite_build/gemmlowp -I/home/grand/install/tf_lite/tflite_build/ruy -I/home/grand/install/tf_lite/tflite_build/xnnpack/include -I/home/grand/install/tf_lite/tflite_build/pthreadpool-source/include -funsafe-math-optimizations -std=c++11 -fPIC -DTFLITE_BUILD_WITH_XNNPACK_DELEGATE -DTFL_STATIC_LIBRARY_BUILD -pthread -MD -MT CMakeFiles/tensorflowlite_c.dir/c_api_experimental.cc.o -MF CMakeFiles/tensorflowlite_c.dir/c_api_experimental.cc.o.d -o CMakeFiles/tensorflowlite_c.dir/c_api_experimental.cc.o -c /home/grand/install/tf_lite/tensorflow_src/tensorflow/lite/c/c_api_experimental.cc
[100%] Linking CXX shared library libtensorflowlite_c.so
/usr/local/lib/python3.6/dist-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/tensorflowlite_c.dir/link.txt --verbose=1
/home/grand/install/xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ -fPIC -funsafe-math-optimizations -Wl,--version-script,/home/grand/install/tf_lite/tensorflow_src/tensorflow/lite/c/version_script.lds -shared -Wl,-soname,libtensorflowlite_c.so -o libtensorflowlite_c.so CMakeFiles/tensorflowlite_c.dir/common.c.o CMakeFiles/tensorflowlite_c.dir/c_api.cc.o CMakeFiles/tensorflowlite_c.dir/c_api_experimental.cc.o  tensorflow-lite/libtensorflow-lite.a _deps/abseil-cpp-build/absl/flags/libabsl_flags.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a _deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a _deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a _deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a _deps/abseil-cpp-build/absl/base/libabsl_exponential_biased.a _deps/abseil-cpp-build/absl/hash/libabsl_hash.a _deps/abseil-cpp-build/absl/hash/libabsl_city.a _deps/abseil-cpp-build/absl/hash/libabsl_wyhash.a _deps/abseil-cpp-build/absl/status/libabsl_status.a _deps/abseil-cpp-build/absl/strings/libabsl_cord.a _deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a _deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a _deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a _deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a _deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a _deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a _deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a _deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a _deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a _deps/abseil-cpp-build/absl/time/libabsl_time.a _deps/abseil-cpp-build/absl/strings/libabsl_strings.a _deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a _deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a _deps/abseil-cpp-build/absl/base/libabsl_base.a _deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a -lrt _deps/abseil-cpp-build/absl/numeric/libabsl_int128.a _deps/abseil-cpp-build/absl/time/libabsl_civil_time.a _deps/abseil-cpp-build/absl/time/libabsl_time_zone.a _deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a _deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a _deps/abseil-cpp-build/absl/base/libabsl_log_severity.a _deps/farmhash-build/libfarmhash.a _deps/fft2d-build/libfft2d_fftsg2d.a _deps/fft2d-build/libfft2d_fftsg.a _deps/flatbuffers-build/libflatbuffers.a _deps/ruy-build/libruy.a -ldl _deps/xnnpack-build/libXNNPACK.a /home/grand/install/xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/aarch64-linux-gnu/libc/usr/lib/libm.so cpuinfo/libcpuinfo.a clog/libclog.a -pthread pthreadpool/libpthreadpool.a -lpthread 
make[2]: Leaving directory '/home/grand/install/tf_lite/tflite_build'
[100%] Built target tensorflowlite_c
make[1]: Leaving directory '/home/grand/install/tf_lite/tflite_build'
/usr/local/lib/python3.6/dist-packages/cmake/data/bin/cmake -E cmake_progress_start /home/grand/install/tf_lite/tflite_build/CMakeFiles 0

grand@xilinx2:~/install/tf_lite/tflite_build$ ll

Actions #3

Updated by Colley Jean-Marc about 1 year ago

avec cette page https://www.tensorflow.org/lite/guide/build_cmake_arm?hl=fr#build_for_aarch64_arm64

. ~/install/xilinx/SDK/2018.3/settings64.sh
 1732  ARMCC_PREFIX=/home/grand/install/xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-
 1733  ARMCC_FLAGS="-funsafe-math-optimizations" 
 1736  /usr/local/bin/cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc -DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ -DCMAKE_C_FLAGS="${ARMCC_FLAGS}" -DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64  ../tensorflow_src/tensorflow/lite/c
 1737  /usr/local/bin/cmake --build . -j 2

Actions #4

Updated by Colley Jean-Marc about 1 year ago

  • Description updated (diff)
Actions #5

Updated by Colley Jean-Marc about 1 year ago

3) conversion modele Keras

tflite_convert --keras_model_file=trigger_icrc_80.keras --output_file=trigger_icrc_80.tflite
Actions #6

Updated by Colley Jean-Marc 7 months ago

Tensorflow Lite sur CPU ARM

1) Compilation de la bibliothèque tensorflow lite pour ARM xilinx avec cmake

pour clone le package tensotflow lite

https://www.tensorflow.org/lite/guide/build_cmake?hl=fr#step_1_install_cmake_tool

Compilation sur ARM

https://www.tensorflow.org/lite/guide/build_cmake_arm?hl=fr#build_for_aarch64_arm64

mon adaption à Xilinx avec un cmake plus récent que celui de Xilinx installé ici /usr/local/bin/cmake

source ~/install/xilinx/SDK/2018.3/settings64.sh
1732 ARMCC_PREFIX=/home/grand/install/xilinx/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-
1733 ARMCC_FLAGS="-funsafe-math-optimizations"
1736 /usr/local/bin/cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc -DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ -DCMAKE_C_FLAGS="${ARMCC_FLAGS}" -DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 ../tensorflow_src/tensorflow/lite/c
1737 /usr/local/bin/cmake --build . -j 2

2) Code d'inférence en C

L'inférence de réseau de neurone est juste la réponse du réseau à une entrée, à ce moment l’entraînement du réseau est terminé.

Démarche général:

https://www.tensorflow.org/lite/guide/inference?hl=fr

La description du réseau est dans un format spécifique à tensorflow lite, une "moulinette" de conversion existe entre tensorflow et keras.

Pour GRAND nous avons utilisé Keras et c'est

https://www.tensorflow.org/lite/convert/index?hl=fr

tflite_convert --keras_model_file=trigger_icrc_80.keras --output_file=trigger_icrc_80.tflite

Ensuite il faut faire le code d'inférence de C , la doc donne cette exemple

https://www.tensorflow.org/lite/guide/inference?hl=fr#using_c_api_in_objective-c_code

voici mon adapation pour le projet GRAND

https://github.com/grand-mother/grand-daq-master/blob/815e9b8a44be24ed2fb50541b455753a53a508a9/dudaq_1/proto_tf/main.c#L522C4-L522C4

et ici le "makefile" qui compile et lie avec la lib tensorflow lite (libtensorflowlite_c.so) avec l'outil python SCons

https://github.com/grand-mother/grand-daq-master/blob/dev_tensorflow/dudaq_1/proto_tf/SConstruct.py

Actions #7

Updated by Colley Jean-Marc about 2 months ago

  • % Done changed from 0 to 80

Need to do update tensorflowLite version

Actions #8

Updated by Colley Jean-Marc 27 days ago

  • Status changed from Assigned to Closed
  • % Done changed from 80 to 100
  • Remaining (hours) set to 0.0
Actions

Also available in: Atom PDF