diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0001-onnxruntime-test-remove-AVX-specific-micro-benchmark.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0001-onnxruntime-test-remove-AVX-specific-micro-benchmark.patch deleted file mode 100644 index 7ee52241f..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0001-onnxruntime-test-remove-AVX-specific-micro-benchmark.patch +++ /dev/null @@ -1,47 +0,0 @@ -From a17c1c5d0b4957b5b3a65fc5d211f5ba6764d404 Mon Sep 17 00:00:00 2001 -From: Vincent ABRIOU -Date: Fri, 24 Mar 2023 11:09:00 +0100 -Subject: [PATCH 1/5] onnxruntime: test: remove AVX specific micro benchmark - -Signed-off-by: Vincent ABRIOU - -%% original patch: 0001-onnxruntime-test-remove-AVX-specific-micro-benchmark.patch ---- - .../test/onnx/microbenchmark/reduceminmax.cc | 24 ------------------- - 1 file changed, 24 deletions(-) - -diff --git a/onnxruntime/test/onnx/microbenchmark/reduceminmax.cc b/onnxruntime/test/onnx/microbenchmark/reduceminmax.cc -index 06a7f50c9a..eeaa9e0067 100644 ---- a/onnxruntime/test/onnx/microbenchmark/reduceminmax.cc -+++ b/onnxruntime/test/onnx/microbenchmark/reduceminmax.cc -@@ -91,28 +91,4 @@ BENCHMARK(BM_FindMinMaxMlasSSE2) - ->Arg(98304) - ->Arg(160000); - --// MLAS avx implementation --static void BM_FindMinMaxMlasAvx(benchmark::State& state) { -- const size_t batch_size = static_cast(state.range(0)); -- float* data = GenerateArrayWithRandomValue(batch_size, -1, 1); -- float min = std::numeric_limits::max(); -- float max = std::numeric_limits::lowest(); -- for (auto _ : state) { -- MlasReduceMinimumMaximumF32KernelAvx(data, &min, &max, batch_size); -- } -- aligned_free(data); --} -- --BENCHMARK(BM_FindMinMaxMlasAvx) -- ->UseRealTime() -- ->UseRealTime() -- ->Unit(benchmark::TimeUnit::kNanosecond) -- ->Arg(100) -- ->Arg(1000) -- ->Arg(10000) -- ->Arg(20000) -- ->Arg(40000) -- ->Arg(80000) -- ->Arg(98304) -- ->Arg(160000); - --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0002-onnxruntime-add-SONAME-with-MAJOR-version.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0002-onnxruntime-add-SONAME-with-MAJOR-version.patch deleted file mode 100644 index 6ef4e4200..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0002-onnxruntime-add-SONAME-with-MAJOR-version.patch +++ /dev/null @@ -1,25 +0,0 @@ -From cb9bd5d833845a5e12c38b5b457fd232498efeb7 Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Tue, 9 May 2023 13:33:14 +0200 -Subject: [PATCH 2/5] onnxruntime: add SONAME with MAJOR version - -Signed-off-by: Othmane AHL ZOUAOUI - -%% original patch: 0002-onnxruntime-add-SONAME-with-MAJOR-version.patch ---- - cmake/CMakeLists.txt | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt -index a5d28fb516..08a4c6af52 100644 ---- a/cmake/CMakeLists.txt -+++ b/cmake/CMakeLists.txt -@@ -1617,3 +1617,6 @@ if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS) - COMMENT "Installing protobuf" - ) - endif() -+ -+message("ONNXRUNTIME_VERSION_MAJOR=${ONNXRUNTIME_VERSION_MAJOR}") -+set_target_properties(onnxruntime PROPERTIES SOVERSION "${ONNXRUNTIME_VERSION_MAJOR}") --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0003-onnxruntime-test-libcustom-library-remove-relative.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0003-onnxruntime-test-libcustom-library-remove-relative.patch deleted file mode 100644 index 7be9cb5ad..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0003-onnxruntime-test-libcustom-library-remove-relative.patch +++ /dev/null @@ -1,59 +0,0 @@ -From e13955dec97f7635cb055e86cb2db026f74e4823 Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Tue, 9 May 2023 13:50:46 +0200 -Subject: [PATCH 3/5] onnxruntime: test: libcustom library remove relative - -Signed-off-by: Othmane AHL ZOUAOUI - -%% original patch: 0003-onnxruntime-test-libcustom-library-remove-relative.patch ---- - onnxruntime/test/python/onnxruntime_test_python.py | 4 ++-- - onnxruntime/test/shared_lib/test_inference.cc | 4 ++-- - 2 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/onnxruntime/test/python/onnxruntime_test_python.py b/onnxruntime/test/python/onnxruntime_test_python.py -index 89fd90ad3a..6bf0eb0399 100644 ---- a/onnxruntime/test/python/onnxruntime_test_python.py -+++ b/onnxruntime/test/python/onnxruntime_test_python.py -@@ -953,7 +953,7 @@ class TestInferenceSession(unittest.TestCase): - raise FileNotFoundError("Unable to find '{0}'".format(shared_library)) - - else: -- shared_library = "./libcustom_op_library.so" -+ shared_library = "/usr/lib/libcustom_op_library.so" - if not os.path.exists(shared_library): - raise FileNotFoundError("Unable to find '{0}'".format(shared_library)) - -@@ -1312,7 +1312,7 @@ class TestInferenceSession(unittest.TestCase): - return - - else: -- shared_library = "./libtest_execution_provider.so" -+ shared_library = "/usr/lib/libtest_execution_provider.so" - - if not os.path.exists(shared_library): - raise FileNotFoundError("Unable to find '{0}'".format(shared_library)) -diff --git a/onnxruntime/test/shared_lib/test_inference.cc b/onnxruntime/test/shared_lib/test_inference.cc -index 09219b40de..db4d73f4c0 100644 ---- a/onnxruntime/test/shared_lib/test_inference.cc -+++ b/onnxruntime/test/shared_lib/test_inference.cc -@@ -1302,7 +1302,7 @@ TEST(CApiTest, test_custom_op_library) { - #elif defined(__APPLE__) - lib_name = ORT_TSTR("libcustom_op_library.dylib"); - #else -- lib_name = ORT_TSTR("./libcustom_op_library.so"); -+ lib_name = ORT_TSTR("libcustom_op_library.so"); - #endif - - #ifdef USE_CUDA -@@ -1329,7 +1329,7 @@ TEST(CApiTest, test_custom_op_library_registration_error) { - #elif defined(__APPLE__) - lib_name = ORT_TSTR("libcustom_op_invalid_library.dylib"); - #else -- lib_name = ORT_TSTR("./libcustom_op_invalid_library.so"); -+ lib_name = ORT_TSTR("libcustom_op_invalid_library.so"); - #endif - - Ort::SessionOptions session_options; --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0004-onnxruntime-fix-imcompatibility-with-compiler-GCC12.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0004-onnxruntime-fix-imcompatibility-with-compiler-GCC12.patch deleted file mode 100644 index 613fcfcfb..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0004-onnxruntime-fix-imcompatibility-with-compiler-GCC12.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 961ee9cf8510b4d9d87777105a338fa31a5d572a Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Tue, 9 May 2023 14:03:04 +0200 -Subject: [PATCH 4/5] onnxruntime: fix imcompatibility with compiler GCC12.2.1 - bug - -As stated in this issue below, the onnxruntime 14.4.0 release is -not compatible with the version 12.2.1 of the GCC cross compiler. -This patch is a workaround to fix this incompatibility bug. - -Link to onnxruntime github issue: -https://github.com/microsoft/onnxruntime/issues/14981 - -Signed-off-by: Othmane AHL ZOUAOUI - -%% original patch: 0004-onnxruntime-fix-imcompatibility-with-compiler-GCC12..patch ---- - onnxruntime/core/providers/cpu/tensor/scatter.cc | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/onnxruntime/core/providers/cpu/tensor/scatter.cc b/onnxruntime/core/providers/cpu/tensor/scatter.cc -index 2d932dfe59..2e2f47d31f 100644 ---- a/onnxruntime/core/providers/cpu/tensor/scatter.cc -+++ b/onnxruntime/core/providers/cpu/tensor/scatter.cc -@@ -340,7 +340,11 @@ Status ScatterData( - // and so on - std::vector dim_block_size(num_dims); - -+#if __GNUC__ >= 12 -+ dim_block_size[num_dims-1] = 1; -+#else - dim_block_size.back() = 1; -+#endif - if (num_dims > 1) { - // We start at num_dims - 2 because we already pre-populated - // the last element above --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0005-onnxruntime-avoid-using-unsupported-Eigen-headers.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0005-onnxruntime-avoid-using-unsupported-Eigen-headers.patch deleted file mode 100644 index 034b7d8d6..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0005-onnxruntime-avoid-using-unsupported-Eigen-headers.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 8195a2404f122d25814b851cd738cf0ff1e91d89 Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Wed, 10 May 2023 10:39:00 +0200 -Subject: [PATCH 5/5] onnxruntime: avoid using unsupported Eigen headers -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -This patch removes the suspected Unsupported/Eigen/CXX11 headers and -uses Onnx internal headers instead. It enables also the pragma for -HAS_CLASS_MEMACCESS to treat the class-memaccess as warnings. -This allows fixing the following build error: ‘void* memcpy(void*, -const void*, size_t)’ copying an object of non-trivial type -‘Eigen::internal::Packet4c’{aka ‘const signed char’} -[-Werror=class-memaccess] - -Signed-off-by: Othmane AHL ZOUAOUI - -%% original patch: 0006-onnxruntime-avoid-using-unsupported-Eigen-headers.patch ---- - onnxruntime/test/onnx/microbenchmark/eigen.cc | 15 ++++++++++++--- - 1 file changed, 12 insertions(+), 3 deletions(-) - -diff --git a/onnxruntime/test/onnx/microbenchmark/eigen.cc b/onnxruntime/test/onnx/microbenchmark/eigen.cc -index b3b2c55600..00c317da50 100644 ---- a/onnxruntime/test/onnx/microbenchmark/eigen.cc -+++ b/onnxruntime/test/onnx/microbenchmark/eigen.cc -@@ -6,6 +6,13 @@ - #pragma GCC diagnostic ignored "-Wunused-parameter" - #pragma GCC diagnostic ignored "-Wunused-result" - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -+// cmake/external/eigen/unsupported/Eigen/CXX11/../../../Eigen/src/Core/arch/NEON/PacketMath.h:1633:9: -+// error: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘Eigen::internal::Packet4c’ -+// {aka ‘struct Eigen::internal::eigen_packet_wrapper’} from an array of ‘const int8_t’ -+// {aka ‘const signed char’} [-Werror=class-memaccess] -+#ifdef HAS_CLASS_MEMACCESS -+#pragma GCC diagnostic ignored "-Wclass-memaccess" -+#endif - #elif defined(_MSC_VER) - // build\windows\debug\external\eigen3\unsupported\eigen\cxx11\src/Tensor/Tensor.h(76): - // warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence -@@ -22,9 +29,11 @@ - #define EIGEN_USE_THREADS - #endif - --#include --#include --#include -+#include "core/platform/threadpool.h" -+#include "core/common/eigen_common_wrapper.h" -+#include "core/util/thread_utils.h" -+#include -+ - #if defined(__GNUC__) - #pragma GCC diagnostic pop - #elif defined(_MSC_VER) --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0006-onnxruntime-xnnpack-Fix-mcpu-compiler-build-failure.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0006-onnxruntime-xnnpack-Fix-mcpu-compiler-build-failure.patch deleted file mode 100644 index 3e6c53b55..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0006-onnxruntime-xnnpack-Fix-mcpu-compiler-build-failure.patch +++ /dev/null @@ -1,43 +0,0 @@ -From a313277345bb498f9a788b905ed3f4e37ba31b57 Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Tue, 30 May 2023 17:17:39 +0200 -Subject: [PATCH 6/6] onnxruntime: xnnpack: Fix -mcpu compiler build failure - -The "-mcpu=" switch is introduced externaly into CMake by Yocto -buildsystem toolchain. This switch is not compatible with XNNPACK -build mechanism and causes the XNNPACK compilation break due to -"unsupported instructions". -This switch needs to be removed for XNNPACK In order to isolate -the changes only for XNNPACK and its depencencies, a subfolder and -a fix are introduced through this patch. - -Signed-off-by: Othmane AHL ZOUAOUI ---- - cmake/external/xnnpack.cmake | 12 ++++++++++++ - 1 file changed, 12 insertions(+) - -diff --git a/cmake/external/xnnpack.cmake b/cmake/external/xnnpack.cmake -index 1fc2c6ccdc..62fad6ce38 100644 ---- a/cmake/external/xnnpack.cmake -+++ b/cmake/external/xnnpack.cmake -@@ -11,6 +11,18 @@ if(CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a) - set(XNNPACK_ENABLE_ARM_BF16 OFF) - ENDIF() - -+string(REGEX REPLACE "-mcpu=[-a-zA-Z0-9_.^$*+?]*" "" _tmp ${CMAKE_C_FLAGS}) -+set(CMAKE_C_FLAGS ${_tmp}) -+message("CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") -+ -+string(REGEX REPLACE "-mcpu=[-a-zA-Z0-9_.^$*+?]*" "" _tmp ${CMAKE_ASM_FLAGS}) -+set(CMAKE_ASM_FLAGS ${_tmp}) -+message("CMAKE_ASM_FLAGS: ${CMAKE_ASM_FLAGS}") -+ -+string(REGEX REPLACE "-mcpu=[-a-zA-Z0-9_.^$*+?]*" "" _tmp ${CMAKE_CXX_FLAGS}) -+set(CMAKE_CXX_FLAGS ${_tmp}) -+message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") -+ - # fp16 depends on psimd - FetchContent_Declare(psimd URL ${DEP_URL_psimd} URL_HASH SHA1=${DEP_SHA1_psimd}) - onnxruntime_fetchcontent_makeavailable(psimd) --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0007-onnxruntime-cmake-change-visibility-compilation-opti.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0007-onnxruntime-cmake-change-visibility-compilation-opti.patch deleted file mode 100644 index 6ae66fc2a..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/files/0007-onnxruntime-cmake-change-visibility-compilation-opti.patch +++ /dev/null @@ -1,26 +0,0 @@ -From ce4219ad77d422b9b5adc032ab911824ef212c41 Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Wed, 20 Mar 2024 15:59:12 +0100 -Subject: [PATCH 1/1] onnxruntime: cmake: change visibility compilation options - -Changing the compile options of the libonnxruntime shared lib -to export all the symbols of the lib and make them visible during -the runtime. - -Signed-off-by: Othmane AHL ZOUAOUI ---- - cmake/CMakeLists.txt | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt -index 08a4c6af52..1336ceb19b 100644 ---- a/cmake/CMakeLists.txt -+++ b/cmake/CMakeLists.txt -@@ -1620,3 +1620,5 @@ endif() - - message("ONNXRUNTIME_VERSION_MAJOR=${ONNXRUNTIME_VERSION_MAJOR}") - set_target_properties(onnxruntime PROPERTIES SOVERSION "${ONNXRUNTIME_VERSION_MAJOR}") -+target_compile_options(onnxruntime PRIVATE -fvisibility=hidden) -+target_compile_options(onnxruntime PRIVATE -fvisibility=default) --- -2.34.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/onnxruntime_git.bbappend b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/onnxruntime_git.bbappend deleted file mode 100644 index 6ef6386c2..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/onnxruntime/onnxruntime_git.bbappend +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright (C) 2023-2024, Digi International Inc. - -FILESEXTRAPATHS:prepend := "${THISDIR}/files:" - -PV = "1.14.0+git${SRCPV}" - -SRCREV = "6ccaeddefa65ccac402a47fa4d9cad8229794bb2" -SRC_URI = "gitsm://github.com/microsoft/onnxruntime.git;branch=rel-1.14.0;protocol=https" -SRC_URI += " file://0001-onnxruntime-test-remove-AVX-specific-micro-benchmark.patch " -SRC_URI += " file://0002-onnxruntime-add-SONAME-with-MAJOR-version.patch " -SRC_URI += " file://0003-onnxruntime-test-libcustom-library-remove-relative.patch " -SRC_URI += " file://0004-onnxruntime-fix-imcompatibility-with-compiler-GCC12.patch " -SRC_URI += " file://0005-onnxruntime-avoid-using-unsupported-Eigen-headers.patch " -SRC_URI += " file://0007-onnxruntime-cmake-change-visibility-compilation-opti.patch " -SRC_URI:append:stm32mp2common = " file://0006-onnxruntime-xnnpack-Fix-mcpu-compiler-build-failure.patch " - -PROTOC_VERSION = "3.20.2" -SRC_URI += "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip;name=protoc;subdir=protoc-${PROTOC_VERSION}/" -SRC_URI[protoc.sha256sum] = "d97227fd8bc840dcb1cf7332c8339a2d8f0fc381a98b028006e5c9a911d07c2a" - -S = "${WORKDIR}/git" - -inherit python3-dir cmake - -DEPENDS:append = "\ - ${PYTHON_PN}-numpy \ -" - -EXTRA_OECMAKE += " -DPython_NumPy_INCLUDE_DIR="${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include" \ - -DBENCHMARK_ENABLE_GTEST_TESTS=OFF \ - -Donnxruntime_USE_XNNPACK=ON \ - -Donnxruntime_BUILD_UNIT_TESTS=ON \ -" - -ONNX_TARGET_ARCH:aarch64="${@bb.utils.contains('TUNE_FEATURES', 'cortexa35', 'aarch64', '', d)}" - -do_install() { - - # Install onnxruntime dynamic library - install -d ${D}${libdir} - install -d ${D}${prefix}/local/bin/${PN}-${PVB}/tools - install -d ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - - install -m 0644 ${B}/libonnxruntime.so ${D}${libdir}/libonnxruntime.so.${PVB} - - # This shared lib is used by onnxruntime_shared_lib_test and onnxruntime_test_python.py - install -m 644 ${B}/libcustom_op_library.so ${D}${libdir} - - # And this one only by onnxruntime_test_python.py - install -m 644 ${B}/libtest_execution_provider.so ${D}${libdir} - install -m 644 ${B}/libonnxruntime_providers_shared.so ${D}${libdir}/libonnxruntime_providers_shared.so - install -m 644 ${B}/libcustom_op_invalid_library.so ${D}${libdir}/libcustom_op_invalid_library.so - install -m 644 ${B}/onnxruntime_pybind11_state.so ${D}${libdir}/onnxruntime_pybind11_state.so - - # Install the symlinks. - ln -sf libonnxruntime.so.${PVB} ${D}${libdir}/libonnxruntime.so.${MAJOR} - ln -sf libonnxruntime.so.${PVB} ${D}${libdir}/libonnxruntime.so - - # These are not included in the base installation, so we install them manually. - install -m 755 ${B}/onnx_test_runner ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - install -m 755 ${B}/onnxruntime_perf_test ${D}${prefix}/local/bin/${PN}-${PVB}/tools - install -m 755 ${B}/onnxruntime_test_all ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - install -m 755 ${B}/onnxruntime_shared_lib_test ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - install -m 755 ${B}/onnxruntime_api_tests_without_env ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - install -m 755 ${B}/onnxruntime_global_thread_pools_test ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - install -m 755 ${B}/onnxruntime_test_python.py ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - install -m 755 ${B}/helper.py ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - cp -r ${B}/testdata ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests - - # We have to change some of the RPATH as well. - chrpath -r '$ORIGIN' ${D}${prefix}/local/bin/${PN}-${PVB}/tools/onnxruntime_perf_test - chrpath -r '$ORIGIN' ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests/onnxruntime_shared_lib_test - chrpath -r '$ORIGIN' ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests/onnxruntime_api_tests_without_env - chrpath -r '$ORIGIN' ${D}${prefix}/local/bin/${PN}-${PVB}/unit-tests/onnxruntime_global_thread_pools_test - chrpath -r '$ORIGIN' ${D}${libdir}/libtest_execution_provider.so - - # Install the Python package. - mkdir -p ${D}${PYTHON_SITEPACKAGES_DIR}/onnxruntime - cp -r ${B}/onnxruntime ${D}${PYTHON_SITEPACKAGES_DIR} - - # Install header files - install -d ${D}${includedir}/onnxruntime - cd ${S}/onnxruntime - cp --parents $(find . -name "*.h*" -not -path "*cmake_build/*") ${D}${includedir}/onnxruntime - cp ${S}/include/onnxruntime/core/session/onnxruntime_cxx_api.h ${D}${includedir}/onnxruntime - cp ${S}/include/onnxruntime/core/session/onnxruntime_c_api.h ${D}${includedir}/onnxruntime - cp ${S}/include/onnxruntime/core/session/onnxruntime_cxx_inline.h ${D}${includedir}/onnxruntime -} - -# The package_qa() task does not like the fact that this library is present in both onnxruntime-tools -# and python3-onnxruntime packages (the normal /usr/lib version and a copy placed inside the Python package). -# So we simply mark the lib as a "private lib", to prevent the task from outputting an error. -PRIVATE_LIBS = "libonnxruntime_providers_shared.so" - -PACKAGES += "${PN}-unit-tests" -PROVIDES += "${PN}-unit-tests" - -FILES:${PN}-tools = "${prefix}/local/bin/${PN}-${PVB}/tools/onnxruntime_perf_test" -FILES:${PN}-unit-tests = "${prefix}/local/bin/${PN}-${PVB}/unit-tests/* ${libdir}/libcustom_op_invalid_library.so ${libdir}/libtest_execution_provider.so ${libdir}/libcustom_op_library.so" - -# onnxruntime_test_python.py unitary test requires python3-numpy and python3-onnxruntime packages -RDEPENDS:${PN}-unit-tests += "${PYTHON_PN}-${PN}" -RDEPENDS:${PYTHON_PN}-${PN} += "${PYTHON_PN}-numpy" diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch deleted file mode 100644 index 6aea05595..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch +++ /dev/null @@ -1,25 +0,0 @@ -From c8af5997f3d9b851ff81ef1fb4045ec59f80d976 Mon Sep 17 00:00:00 2001 -From: Alexis BRISSON -Date: Wed, 10 May 2023 16:44:47 +0200 -Subject: [PATCH 1/1] TFLite add XNNPACK delegate u8 and i8 definition - -Signed-off-by: Alexis BRISSON ---- - tensorflow/lite/CMakeLists.txt | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt -index 073b29c4860..b3b89a4236c 100644 ---- a/tensorflow/lite/CMakeLists.txt -+++ b/tensorflow/lite/CMakeLists.txt -@@ -404,6 +404,8 @@ if(TFLITE_ENABLE_XNNPACK) - TFLITE_DELEGATES_XNNPACK_SRCS - FILTER ".*(_test|_tester)\\.(cc|h)" - ) -+ add_definitions( -DXNNPACK_DELEGATE_ENABLE_QS8=1 ) -+ add_definitions( -DXNNPACK_DELEGATE_ENABLE_QU8=1 ) - list(APPEND TFLITE_TARGET_DEPENDENCIES - XNNPACK - ) --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0007-TFLite-fix-aarch64-support-for-XNNPACK.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0007-TFLite-fix-aarch64-support-for-XNNPACK.patch deleted file mode 100644 index 62519cb53..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0007-TFLite-fix-aarch64-support-for-XNNPACK.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 78cbe3bb1970982adf32c9966b83789301d45cd8 Mon Sep 17 00:00:00 2001 -From: Maxence GUILHIN -Date: Mon, 10 Jul 2023 15:47:59 +0200 -Subject: [PATCH 1/1] tensorflow-lite : fix aarch64 support for XNNPACK - -The "-mcpu=" switch might be introduced externaly into CMake: either in _FLAGS or -as part of CC, CXX, ASM environmental variables (to be stored in CMAKE__COMPILER_ARG1). -This switch is not compatible with XNNPACK build mechanism and causes the XNNPACK compilation -break due to "unsupported instructions". This switch needs to be removed for XNNPACK -In order to isolate the changes only for XNNPACK and its depencencies, a subfolder is -introduced. - -Signed-off-by: Maxence GUILHIN ---- - tensorflow/lite/tools/cmake/modules/xnnpack.cmake | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) - -diff --git a/tensorflow/lite/tools/cmake/modules/xnnpack.cmake b/tensorflow/lite/tools/cmake/modules/xnnpack.cmake -index 24f0674cf92..028fc3a76e2 100644 ---- a/tensorflow/lite/tools/cmake/modules/xnnpack.cmake -+++ b/tensorflow/lite/tools/cmake/modules/xnnpack.cmake -@@ -38,6 +38,20 @@ endif() - set(XNNPACK_BUILD_TESTS OFF CACHE BOOL "Disable XNNPACK test.") - set(XNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "Disable XNNPACK benchmarks.") - -+# The "-mcpu=" switch might be introduced externaly into CMake: either in _FLAGS or -+# as part of CC, CXX, ASM environmental variables (to be stored in CMAKE__COMPILER_ARG1). -+# This switch is not compatible with XNNPACK build mechanism and causes the XNNPACK compilation -+# break due to "unsupported instructions". This switch needs to be removed for XNNPACK -+# In order to isolate the changes only for XNNPACK and its depencencies, a subfolder is -+# introduced. -+ -+foreach(FLAG IN ITEMS CMAKE_ASM_FLAGS CMAKE_ASM_COMPILER_ARG1 CMAKE_C_FLAGS CMAKE_C_COMPILER_ARG1 CMAKE_CXX_FLAGS CMAKE_CXX_COMPILER_ARG1) -+ if(${FLAG}) -+ string(REGEX REPLACE "-mcpu=[-a-zA-Z0-9_.^$*+?]*" "" _tmp ${${FLAG}}) -+ set(${FLAG} ${_tmp}) -+ endif() -+endforeach() -+ - # The following line adds project of PTHREADPOOL, FP16 and XNNPACK which are - # needed to compile XNNPACK delegate of TFLite. - add_subdirectory( --- -2.25.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0008-TFLite-cmake-change-visibility-compilation-options.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0008-TFLite-cmake-change-visibility-compilation-options.patch deleted file mode 100644 index 714f30fbe..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/files/0008-TFLite-cmake-change-visibility-compilation-options.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 0675ef8a401c5f77aeb674b006594190c7f58810 Mon Sep 17 00:00:00 2001 -From: Othmane AHL ZOUAOUI -Date: Wed, 20 Mar 2024 15:05:40 +0100 -Subject: [PATCH 8/8] TFLite: cmake: change visibility compilation options - -Changing the compile options of the libtensorflow-lite shared lib -to export all the symbols of the lib and make them visible during -the runtime. - -Change-Id: I25a88a3ba29b00d1f40336e10acb898ab8b016a5 -Signed-off-by: Othmane AHL ZOUAOUI ---- - tensorflow/lite/CMakeLists.txt | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt -index 40812886306..f7bb65d894a 100644 ---- a/tensorflow/lite/CMakeLists.txt -+++ b/tensorflow/lite/CMakeLists.txt -@@ -517,6 +517,8 @@ set(_ALL_TFLITE_SRCS - add_library(tensorflow-lite SHARED EXCLUDE_FROM_ALL - ${_ALL_TFLITE_SRCS} - ) -+target_compile_options(tensorflow-lite PRIVATE -fvisibility=hidden) -+target_compile_options(tensorflow-lite PRIVATE -fvisibility=default) - set(_ALL_TFLITE_HDRS ${_ALL_TFLITE_SRCS}) - list(FILTER _ALL_TFLITE_HDRS INCLUDE REGEX ".*\\.h$") - target_include_directories(tensorflow-lite --- -2.34.1 diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bbappend b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bbappend deleted file mode 100644 index 35e8e1eab..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tensorflow-lite/tensorflow-lite_git.bbappend +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2024, Digi International Inc. - -FILESEXTRAPATHS:prepend := "${THISDIR}/files:" - -SRC_URI += " file://0006-TFLite-cmake-add-XNNPACK-delegate-u8-and-i8-definition.patch " -SRC_URI += " file://0008-TFLite-cmake-change-visibility-compilation-options.patch " -SRC_URI:append:stm32mp2common = " file://0007-TFLite-fix-aarch64-support-for-XNNPACK.patch " - -# Set building environment variables -TENSORFLOW_TARGET:aarch64="linux" -TENSORFLOW_TARGET_ARCH:aarch64="aarch64" - -# Activate -O3 optimization and disable debug symbols -OECMAKE_C_FLAGS_RELEASE = "-O3 -DNDEBUG" -OECMAKE_CXX_FLAGS_RELEASE = "-O3 -DNDEBUG" -# Build tensorflow-lite.so library, _pywrap_tensorflow_interpreter_wrapper.so library and the benchmark_model application -OECMAKE_TARGET_COMPILE = "tensorflow-lite _pywrap_tensorflow_interpreter_wrapper benchmark_model" - -EXTRA_OECMAKE += " -DTFLITE_ENABLE_XNNPACK=OFF " - -do_compile() { - # Standard CMAKE build. - cmake_runcmake_build --target ${OECMAKE_TARGET_COMPILE} - # Build the python wheel (procedure extract form the build_pip_package_with_cmake.sh) - BUILD_DIR=${WORKDIR}/build - TENSORFLOW_DIR=${S} - TENSORFLOW_LITE_DIR="${TENSORFLOW_DIR}/tensorflow/lite" - TENSORFLOW_VERSION=$(grep "_VERSION = " "${TENSORFLOW_DIR}/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g") - mkdir -p "${BUILD_DIR}/tflite_runtime" - cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \ - "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \ - "${BUILD_DIR}" - cp -r "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" "${BUILD_DIR}" - cp "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" "${BUILD_DIR}/setup.py" - cp "${TENSORFLOW_LITE_DIR}/python/interpreter.py" \ - "${TENSORFLOW_LITE_DIR}/python/metrics/metrics_interface.py" \ - "${TENSORFLOW_LITE_DIR}/python/metrics/metrics_portable.py" \ - "${BUILD_DIR}/tflite_runtime" - echo "__version__ = '${TENSORFLOW_VERSION}'" >> "${BUILD_DIR}/tflite_runtime/__init__.py" - echo "__git_version__ = '$(git -C "${TENSORFLOW_DIR}" describe)'" >> "${BUILD_DIR}/tflite_runtime/__init__.py" - - export PACKAGE_VERSION="${TENSORFLOW_VERSION}" - export PROJECT_NAME="tflite_runtime" - cp "${BUILD_DIR}/_pywrap_tensorflow_interpreter_wrapper.so" "tflite_runtime" - - setuptools3_do_compile -} - -# Require the external NPU delegate. -RDEPENDS:${PN}:append:stm32mp25common = " tflite-vx-delegate " diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tflite-vx-delegate/tflite-vx-delegate/0001-tflite-vx-delegate-fix-to-support-tflite-2-11.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tflite-vx-delegate/tflite-vx-delegate/0001-tflite-vx-delegate-fix-to-support-tflite-2-11.patch deleted file mode 100644 index af997e91d..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tflite-vx-delegate/tflite-vx-delegate/0001-tflite-vx-delegate-fix-to-support-tflite-2-11.patch +++ /dev/null @@ -1,111 +0,0 @@ -commit 7ac938965051de91c493b75a8825b007e1f52599 -Author: Feiyue Chen -Date: Thu Jul 6 10:41:35 2023 +0000 - - Fixed bugs for kernel test building - -diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt -index 073b29c4860..67486fa183b 100644 ---- a/tensorflow/lite/CMakeLists.txt -+++ b/tensorflow/lite/CMakeLists.txt -@@ -209,6 +209,8 @@ list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*tflite_with_xnnpack\\.cc$") - # Exclude Flex related files. - list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*with_selected_ops\\.cc$") - -+list(FILTER TFLITE_SRCS EXCLUDE REGEX "tensorflow_profiler_logger\\.cc$") -+ - if(_TFLITE_ENABLE_MMAP) - list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$") - else() -diff --git a/tensorflow/lite/kernels/CMakeLists.txt b/tensorflow/lite/kernels/CMakeLists.txt -index f5e22ee97da..d0da2680e7b 100644 ---- a/tensorflow/lite/kernels/CMakeLists.txt -+++ b/tensorflow/lite/kernels/CMakeLists.txt -@@ -63,16 +63,16 @@ build_flatbuffers( - set(DELEGATE_PROVIDERS_SUPP - ${TFLITE_SOURCE_DIR}/nnapi/sl/SupportLibrary.cc - ${TFLITE_SOURCE_DIR}/tools/delegates/delegate_provider.cc -- ${TFLITE_SOURCE_DIR}/tools/evaluation/utils.cc -+ # ${TFLITE_SOURCE_DIR}/tools/evaluation/utils.cc - ) - - set(DELEGATE_PROVIDERS - ${DELEGATE_PROVIDERS_SUPP} - ${TFLITE_SOURCE_DIR}/tools/delegates/default_execution_provider.cc - # List of delegates referenced as options in the tensorflow/lite/CMakeLists.txt -- ${TFLITE_SOURCE_DIR}/tools/delegates/gpu_delegate_provider.cc -+ # ${TFLITE_SOURCE_DIR}/tools/delegates/gpu_delegate_provider.cc - ${TFLITE_SOURCE_DIR}/tools/delegates/nnapi_delegate_provider.cc -- ${TFLITE_SOURCE_DIR}/tools/delegates/xnnpack_delegate_provider.cc -+ # ${TFLITE_SOURCE_DIR}/tools/delegates/xnnpack_delegate_provider.cc - ) - - if(TFLITE_ENABLE_EXTERNAL_DELEGATE) -@@ -92,9 +92,9 @@ set(TEST_FRAMEWORK_SRC - ${TFLITE_SOURCE_DIR}/tools/tool_params.cc - ${TFLITE_SOURCE_DIR}/tools/versioning/op_version.cc - ${TFLITE_SOURCE_DIR}/tools/versioning/op_signature.cc -- ${TF_SOURCE_DIR}/core/platform/default/env_time.cc -- ${TF_SOURCE_DIR}/core/platform/default/logging.cc -- ${TF_SOURCE_DIR}/core/platform/default/mutex.cc -+ ${TF_SOURCE_DIR}/tsl/platform/default/env_time.cc -+ ${TF_SOURCE_DIR}/tsl/platform/default/logging.cc -+ ${TF_SOURCE_DIR}/tsl/platform/default/mutex.cc - internal/test_util.cc - acceleration_test_util.cc - acceleration_test_util_internal.cc -@@ -154,7 +154,8 @@ macro(add_kernel_test TEST_SRC TEST_LIB) - set(DELEGATE_TEST "${TEST_NAME}_delegate") - add_test( - NAME ${DELEGATE_TEST} -- COMMAND cmake -DTEST_EXECUTABLE=$ -P run-tests.cmake -+ # COMMAND cmake -DTEST_EXECUTABLE=$ -P run-tests.cmake -+ COMMAND cmake -DTEST_EXECUTABLE=$ -P ${TFLITE_SOURCE_DIR}/tools/cmake/test_utils/run-tests.cmake - ) - set_tests_properties(${DELEGATE_TEST} PROPERTIES LABELS "delegate") - endif() -diff --git a/tensorflow/lite/kernels/test_main.cc b/tensorflow/lite/kernels/test_main.cc -index 1887533399b..6e3958b77dc 100644 ---- a/tensorflow/lite/kernels/test_main.cc -+++ b/tensorflow/lite/kernels/test_main.cc -@@ -16,7 +16,6 @@ limitations under the License. - #include - - #include --#include "benchmark/benchmark.h" // from @com_google_benchmark - #include "tensorflow/lite/kernels/test_delegate_providers.h" - #include "tensorflow/lite/kernels/test_util.h" - #include "tensorflow/lite/testing/util.h" -@@ -51,7 +50,6 @@ int main(int argc, char** argv) { - ::tflite::LogToStderr(); - if (InitKernelTest(&argc, argv)) { - ::testing::InitGoogleTest(&argc, argv); -- benchmark::RunSpecifiedBenchmarks(); - return RUN_ALL_TESTS(); - } else { - return EXIT_FAILURE; -diff --git a/tensorflow/lite/kernels/unidirectional_sequence_lstm_test.cc b/tensorflow/lite/kernels/unidirectional_sequence_lstm_test.cc -index cf3fd3a031a..e96f4e3f357 100644 ---- a/tensorflow/lite/kernels/unidirectional_sequence_lstm_test.cc -+++ b/tensorflow/lite/kernels/unidirectional_sequence_lstm_test.cc -@@ -18,7 +18,6 @@ limitations under the License. - - #include - #include --#include "benchmark/benchmark.h" // from @com_google_benchmark - #include "flatbuffers/flatbuffers.h" // from @flatbuffers - #include "tensorflow/lite/kernels/test_util.h" - #include "tensorflow/lite/kernels/unidirectional_sequence_lstm_test_util.h" -diff --git a/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake -index 54b413f69ac..d7a2f8ce0f2 100644 ---- a/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake -+++ b/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake -@@ -23,7 +23,7 @@ OverridableFetchContent_Declare( - flatbuffers - GIT_REPOSITORY https://github.com/google/flatbuffers - # Sync with tensorflow/third_party/flatbuffers/workspace.bzl -- GIT_TAG v2.0.6 -+ GIT_TAG v2.0.8 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - SOURCE_DIR "${CMAKE_BINARY_DIR}/flatbuffers" diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tflite-vx-delegate/tflite-vx-delegate_git.bb b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tflite-vx-delegate/tflite-vx-delegate_git.bb deleted file mode 100644 index 82c8fc38e..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tflite-vx-delegate/tflite-vx-delegate_git.bb +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2020-2021 STMicroelectronics -DESCRIPTION = "Verisilicon TFLite VX Delegate for STM32 Devices" -LICENSE = "MIT" -LIC_FILES_CHKSUM = "file://LICENSE;md5=7d6260e4f3f6f85de05af9c8f87e6fb5" - -SRCBRANCH_vx = "main" -SRCREV_vx = "a975b7ed7a5797812d3c5bdb7310ee92164d0a35" - -SRCBRANCH_tf = "r2.11" -SRCREV_tf = "5d37bd0350f0144632629c1aa2ebaef6ca76300b" - -SRC_URI = "git://github.com/VeriSilicon/tflite-vx-delegate.git;branch=${SRCBRANCH_vx};name=vx;destsuffix=git_vx/;protocol=https \ - git://github.com/tensorflow/tensorflow;branch=${SRCBRANCH_tf};name=tf;destsuffix=git_tf/;protocol=https " -SRC_URI += "file://0001-tflite-vx-delegate-fix-to-support-tflite-2-11.patch;patchdir=${WORKDIR}/git_tf" - -PV = "2.11.0+git${SRCREV_vx}" -S = "${WORKDIR}/git_vx" -COMPATIBLE_MACHINE = "stm32mp25common" - -inherit cmake -DEPENDS += "tim-vx patchelf-native" - -python () { - #Get major of the PV variable - version = d.getVar('PV') - version = version.split("+") - version_base = version[0] - version = version_base.split(".") - major = version[0] - d.setVar('MAJOR', major) - d.setVar('PVB', version_base) -} - -do_configure[network] = "1" - -do_configure:prepend() { - if [ -n "${http_proxy}" ]; then - export HTTP_PROXY=${http_proxy} - export http_proxy=${http_proxy} - fi - if [ -n "${https_proxy}" ]; then - export HTTPS_PROXY=${https_proxy} - export https_proxy=${https_proxy} - fi - unset FC -} - -EXTRA_OECMAKE += " -DFETCHCONTENT_SOURCE_DIR_TENSORFLOW=${WORKDIR}/git_tf \ - -DTIM_VX_INSTALL=${STAGING_DIR_TARGET}/usr \ - -DTFLITE_ENABLE_XNNPACK=OFF \ - -DTFLITE_ENABLE_EXTERNAL_DELEGATE=ON \ - -DFETCHCONTENT_FULLY_DISCONNECTED=OFF \ -" - -do_install() { - # Install libvx_delegate.so into libdir - install -d ${D}${libdir} - install -d ${D}${includedir}/VX - install -m 0755 ${WORKDIR}/build/libvx_delegate.so ${D}${libdir}/libvx_delegate.so.${PVB} - patchelf --set-soname libvx_delegate.so ${D}${libdir}/libvx_delegate.so.${PVB} - ln -sf libvx_delegate.so.${PVB} ${D}${libdir}/libvx_delegate.so.${MAJOR} - ln -sf libvx_delegate.so.${PVB} ${D}${libdir}/libvx_delegate.so - - # Install cusom static lib - install -m 0755 libvx_custom_op.a ${D}${libdir}/libvx_custom_op.a - install -m 0644 ${S}/vsi_npu_custom_op.h ${D}${includedir}/VX/vsi_npu_custom_op.h -} - -FILES:${PN} += " ${libdir}/libvx_delegate.so.${MAJOR} \ - ${libdir}/libvx_delegate.so.${PVB} \ -" diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tim-vx/tim-vx/0001-tim-vx-tests-disable-AVG_ANDROID-tests.patch b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tim-vx/tim-vx/0001-tim-vx-tests-disable-AVG_ANDROID-tests.patch deleted file mode 100644 index 63c4e61d9..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tim-vx/tim-vx/0001-tim-vx-tests-disable-AVG_ANDROID-tests.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 23cdc22779175fea6d73848a98e85702d99051c9 Mon Sep 17 00:00:00 2001 -From: Maxence GUILHIN -Date: Mon, 4 Dec 2023 11:19:21 +0100 -Subject: [PATCH 1/1] tim-vx-tests : disable AVG_ANDROID tests which fails with - tensor HDL OFF - -Signed-off-by: Maxence GUILHIN ---- - src/tim/transform/average_pool_layout_infer_test.cc | 2 +- - src/tim/vx/ops/avg_pool_test.cc | 6 +++--- - 2 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/src/tim/transform/average_pool_layout_infer_test.cc b/src/tim/transform/average_pool_layout_infer_test.cc -index 0ff8115..07048f3 100644 ---- a/src/tim/transform/average_pool_layout_infer_test.cc -+++ b/src/tim/transform/average_pool_layout_infer_test.cc -@@ -4,7 +4,7 @@ - #include "tim/transform/layout_inference.h" - - #include "gtest/gtest.h" --TEST(AVG_ANDROID, layout_infer_) { -+TEST(AVG_ANDROID, DISABLED_layout_infer_) { - auto ctx = tim::vx::Context::Create(); - auto graph = ctx->CreateGraph(); - -diff --git a/src/tim/vx/ops/avg_pool_test.cc b/src/tim/vx/ops/avg_pool_test.cc -index 3a9aed8..3f3f17d 100644 ---- a/src/tim/vx/ops/avg_pool_test.cc -+++ b/src/tim/vx/ops/avg_pool_test.cc -@@ -463,7 +463,7 @@ TEST(AVG, shape_60_52_3_5_fp32_kernel_35_stride_5) { - ArraysMatch(golden, output,1e-4f); - } - --TEST(AVG_ANDROID, shape_60_52_3_5_fp32_kernel_35_stride_5) { -+TEST(AVG_ANDROID, DISABLED_shape_60_52_3_5_fp32_kernel_35_stride_5) { - auto ctx = tim::vx::Context::Create(); - auto graph = ctx->CreateGraph(); - -@@ -529,7 +529,7 @@ TEST(AVG_ANDROID, shape_60_52_3_5_fp32_kernel_35_stride_5) { - ArraysMatch(golden, output, 1e-5f); - } - --TEST(AVG_ANDROID, shape_60_52_3_5_fp32_kernel_50_stride_5) { -+TEST(AVG_ANDROID, DISABLED_shape_60_52_3_5_fp32_kernel_50_stride_5) { - auto ctx = tim::vx::Context::Create(); - auto graph = ctx->CreateGraph(); - -@@ -578,7 +578,7 @@ TEST(AVG_ANDROID, shape_60_52_3_5_fp32_kernel_50_stride_5) { - ArraysMatch(golden, output, 1e-5f); - } - --TEST(AVG_ANDROID, shape_60_52_3_5_uint8_kernel_35_stride_5) { -+TEST(AVG_ANDROID, DISABLED_shape_60_52_3_5_uint8_kernel_35_stride_5) { - auto ctx = tim::vx::Context::Create(); - auto graph = ctx->CreateGraph(); - --- -2.25.1 - diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tim-vx/tim-vx_git.bb b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tim-vx/tim-vx_git.bb deleted file mode 100644 index ed472b1cc..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-frameworks/tim-vx/tim-vx_git.bb +++ /dev/null @@ -1,105 +0,0 @@ -DESCRIPTION = "TIM-VX is a software integration module provided by VeriSilicon to facilitate \ -deployment of Neural-Networks on OpenVX enabled ML accelerators. It serves as the backend \ -binding for runtime frameworks such as Android NN, Tensorflow-Lite, MLIR, TVM and more." -SUMMARY = "Tensor Interface Module for OpenVX" -HOMEPAGE = "https://github.com/VeriSilicon/TIM-VX" -LICENSE = "MIT" - -LIC_FILES_CHKSUM = "file://LICENSE;md5=d72cd187d764d96d91db827cb65b48a7" - -SRCBRANCH_tim_vx = "main" -SRCREV_tim_vx = "33f3a4f176ff9c407479eaf6be78c52bb3c7a939" -SRC_URI ="git://github.com/VeriSilicon/TIM-VX.git;branch=${SRCBRANCH_tim_vx};name=tim_vx;destsuffix=tim_vx_git/;protocol=https" -SRC_URI += " file://0001-tim-vx-tests-disable-AVG_ANDROID-tests.patch" - - -SRCBRANCH_googletest = "main" -SRCREV_googletest = "eab0e7e289db13eabfc246809b0284dac02a369d" -SRC_URI +="git://github.com/google/googletest;branch=${SRCBRANCH_googletest};name=googletest;destsuffix=googletest/;protocol=https " - - -PV = "1.1.57+git${SRCREV_tim_vx}" -PV_googletest = "1.14.0" - -S = "${WORKDIR}/tim_vx_git" - -# Only compatible with stm32mp25 -COMPATIBLE_MACHINE = "stm32mp25common" - -python () { - #Get major of the PV variable - version = d.getVar('PV') - version = version.split("+") - version_base = version[0] - version = version_base.split(".") - major = version[0] - d.setVar('MAJOR', major) - d.setVar('PVB', version_base) -} - -inherit cmake -DEPENDS += " patchelf-native \ - gcnano-driver-stm32mp \ - gcnano-userland \ - gtest \ - googletest \ - " - -EXTRA_OECMAKE = " \ - -DCONFIG=YOCTO \ - -DCMAKE_SYSROOT=${RECIPE_SYSROOT} \ - -DTIM_VX_ENABLE_TEST=ON \ - -DCMAKE_SKIP_RPATH=TRUE \ - -DFETCHCONTENT_FULLY_DISCONNECTED=OFF \ - -DTIM_VX_USE_EXTERNAL_OVXLIB=ON \ - -DTIM_VX_DBG_ENABLE_TENSOR_HNDL=OFF \ - -DOVXLIB_INC=${S}/src/tim/vx/internal/include/ \ - -DOVXLIB_LIB=${STAGING_LIBDIR}/libovxlib.so \ - -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${WORKDIR}/googletest \ -" -do_configure[network] = "1" - -do_install() { - # Install libtim-vx.so into libdir - install -d ${D}${libdir} - install -d ${D}/usr/local/bin/${PN}-${PVB} - install -d ${D}/home/weston - - install -m 0755 ${WORKDIR}/build/src/tim/libtim-vx.so ${D}${libdir}/libtim-vx.so.${PVB} - patchelf --set-soname libtim-vx.so ${D}${libdir}/libtim-vx.so.${PVB} - - ln -sf libtim-vx.so.${PVB} ${D}${libdir}/libtim-vx.so.${MAJOR} - ln -sf libtim-vx.so.${PVB} ${D}${libdir}/libtim-vx.so - - # Install other libraries for benchmark - install -m 0755 ${WORKDIR}/build/lib/libgtest_main.so ${D}${libdir}/libgtest_main.so.${PV_googletest} - install -m 0755 ${WORKDIR}/build/lib/libgtest.so ${D}${libdir}/libgtest.so.${PV_googletest} - install -m 0755 ${WORKDIR}/build/lib/libgmock_main.so ${D}${libdir}/libgmock_main.so - install -m 0755 ${WORKDIR}/build/lib/libgmock.so ${D}${libdir}/libgmock.so - install -m 0755 ${WORKDIR}/build/src/tim/unit_test ${D}/usr/local/bin/${PN}-${PVB}/TIM-VX_test - - # Include - install -d ${D}${includedir} - cp -r ${S}/include/tim ${D}${includedir} - cp -r ${STAGING_INCDIR}/CL/cl_viv_vx_ext.h ${D}/usr/local/bin/${PN}-${PVB}/cl_viv_vx_ext.h - cp -r ${STAGING_INCDIR}/CL/cl_viv_vx_ext.h ${D}/home/weston/cl_viv_vx_ext.h -} - -PACKAGES =+ "${PN}-tools" -FILES_SOLIBSDEV = "" - -FILES:${PN}-tools = " /usr/local/bin/${PN}-${PVB}/TIM-VX_test \ - /usr/local/bin/${PN}-${PVB}/cl_viv_vx_ext.h \ - /home/weston/cl_viv_vx_ext.h \ - ${libdir}/libgtest_main.so.${PV_googletest} \ - ${libdir}/libgtest.so.${PV_googletest} \ - ${libdir}/libgmock_main.so \ - ${libdir}/libgmock.so \ -" - -FILES:${PN} += " ${libdir}/libtim-vx.so.${MAJOR} \ - ${libdir}/libtim-vx.so.${PVB} \ - ${libdir}/libtim-vx.so \ -" - -INSANE_SKIP:${PN} += " dev-so " \ No newline at end of file diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/coral-image-classification-cpp_5.0.0.bb b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/coral-image-classification-cpp_5.0.0.bb deleted file mode 100644 index 38b4bbd6a..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/coral-image-classification-cpp_5.0.0.bb +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (C) 2022, STMicroelectronics - All Rights Reserved -SUMMARY = "TensorFlowLite C++ API Computer Vision image classification application example running on the EdgeTPU" -LICENSE = "BSD-3-Clause & Apache-2.0" -LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9" -LIC_FILES_CHKSUM += "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" - -inherit pkgconfig - -DEPENDS += "tensorflow-lite libedgetpu gtk+3 opencv gstreamer1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-bad " - -SRC_URI = " file://tflite;subdir=${BPN}-${PV} " - -S = "${WORKDIR}/${BPN}-${PV}" - -do_configure[noexec] = "1" - -EXTRA_OEMAKE = 'SYSROOT="${RECIPE_SYSROOT}"' -EXTRA_OEMAKE += 'EDGETPU=TRUE' - -do_compile() { - #Check the version of OpenCV and fill OPENCV_VERSION accordingly - FILE=${RECIPE_SYSROOT}/${libdir}/pkgconfig/opencv4.pc - if [ -f "$FILE" ]; then - OPENCV_VERSION=opencv4 - else - OPENCV_VERSION=opencv - fi - - oe_runmake OPENCV_PKGCONFIG=${OPENCV_VERSION} -C ${S}/tflite/ -} - -do_install() { - install -d ${D}${prefix}/local/demo/application - install -d ${D}${prefix}/local/demo-ai/image-classification/coral/ - - # install applications into the demo launcher - install -m 0755 ${S}/tflite/111-coral-image-classification-cpp.yaml ${D}${prefix}/local/demo/application - - # install application binaries and launcher scripts - install -m 0755 ${S}/tflite/tflite_image_classification ${D}${prefix}/local/demo-ai/image-classification/coral/coral_image_classification - install -m 0755 ${S}/tflite/launch_coral_bin*.sh ${D}${prefix}/local/demo-ai/image-classification/coral -} - -FILES:${PN} += "${prefix}/local/" - -INSANE_SKIP:${PN} = "ldflags" - -RDEPENDS:${PN} += " \ - gstreamer1.0-plugins-bad-waylandsink \ - gstreamer1.0-plugins-bad-debugutilsbad \ - gstreamer1.0-plugins-base-app \ - gstreamer1.0-plugins-base-videorate \ - gstreamer1.0-plugins-good-video4linux2 \ - gstreamer1.0-plugins-base-videoconvertscale \ - gtk+3 \ - libedgetpu \ - libopencv-core \ - libopencv-imgproc \ - libopencv-imgcodecs \ - coral-models-mobilenetv1 \ - application-resources \ - bash \ -" diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/coral-image-classification-python_5.0.0.bb b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/coral-image-classification-python_5.0.0.bb deleted file mode 100644 index 508399834..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/coral-image-classification-python_5.0.0.bb +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2022, STMicroelectronics - All Rights Reserved -SUMMARY = "TensorFlowLite Python Computer Vision image classification application examples running on the EdgeTPU" -LICENSE = "BSD-3-Clause" -LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9" - -SRC_URI = " file://tflite;subdir=${BPN}-${PV} " - -S = "${WORKDIR}/${BPN}-${PV}" - -do_configure[noexec] = "1" -do_compile[noexec] = "1" - -do_install() { - install -d ${D}${prefix}/local/demo/application - install -d ${D}${prefix}/local/demo-ai/image-classification/coral - install -d ${D}${prefix}/local/demo-ai/image-classification/resources - - # install applications into the demo launcher - install -m 0755 ${S}/tflite/110-coral-image-classification-python.yaml ${D}${prefix}/local/demo/application - - # install application binaries and launcher scripts - install -m 0755 ${S}/tflite/tflite_image_classification.py ${D}${prefix}/local/demo-ai/image-classification/coral/coral_image_classification.py - install -m 0755 ${S}/tflite/launch_coral_python*.sh ${D}${prefix}/local/demo-ai/image-classification/coral/ -} - -FILES:${PN} += "${prefix}/local/" - -RDEPENDS:${PN} += " \ - python3-core \ - python3-numpy \ - python3-opencv \ - python3-pillow \ - python3-pygobject \ - python3-tensorflow-lite \ - libedgetpu \ - coral-models-mobilenetv1 \ - application-resources \ - bash \ -" diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/130-nbg-image-classification-C++.yaml b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/130-nbg-image-classification-C++.yaml deleted file mode 100644 index 56b587a27..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/130-nbg-image-classification-C++.yaml +++ /dev/null @@ -1,15 +0,0 @@ -Application: - Name: Image Classification - Description: Mobilenet v3 - Icon: ../demo-ai/resources/nbg_cpp.png - Board: - List: all - Type: script - Script: - Exist: - File: /usr/local/demo-ai/resources/check_camera_preview.sh - Msg_false: Camera is not connected - Start: ../demo-ai/image-classification/nbg/launch_bin_image_classification.sh - Action: - button_release_event: script_management - button_press_event: highlight_eventBox diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/Makefile b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/Makefile deleted file mode 100644 index 7ab7e1981..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -OPENCV_PKGCONFIG?="opencv4" -SYSROOT?="" -TARGET_BIN = nbg_image_classification - -CXXFLAGS += -Wall $(shell pkg-config --cflags gtk+-3.0 $(OPENCV_PKGCONFIG) gstreamer-plugins-base-1.0 gstreamer-wayland-1.0) -CXXFLAGS += -std=c++17 - -LDFLAGS = $(shell pkg-config --libs gtk+-3.0 gstreamer-plugins-base-1.0 gstreamer-wayland-1.0) -LDFLAGS += -lpthread -ldl -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -LDFLAGS += -L$(SYSROOT)/usr/lib -ljpeg -lovxlib -lOpenVX -lOpenVXU -LDFLAGS += -Wl,--no-as-needed - -ifeq ($(NEW_GST_WAYLAND_API), 1) - CXXFLAGS += -DNEW_GST_WAYLAND_API -endif - -SRCS = nbg_image_classification.cc vnn_utils.cc -OBJS = $(SRCS:.cc=.o) - -all: $(TARGET_BIN) - -$(TARGET_BIN): $(OBJS) - $(CXX) -o $@ $^ $(LDFLAGS) - -$(OBJS): $(SRCS) - $(CXX) $(CXXFLAGS) -c $^ - -clean: - rm -rf $(OBJS) $(TARGET_BIN) diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/launch_bin_image_classification.sh b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/launch_bin_image_classification.sh deleted file mode 100755 index 4a0c6813c..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/launch_bin_image_classification.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -weston_user=$(ps aux | grep '/usr/bin/weston '|grep -v 'grep'|awk '{print $1}') - -source /usr/local/demo-ai/resources/config_board.sh -cmd="/usr/local/demo-ai/image-classification/nbg/nbg_image_classification -m /usr/local/demo-ai/image-classification/models/mobilenet/$IMAGE_CLASSIFICATION_MODEL.nb -l /usr/local/demo-ai/image-classification/models/mobilenet/$IMAGE_CLASSIFICATION_LABEL\_nbg.txt --framerate $DFPS --frame_width $DWIDTH --frame_height $DHEIGHT" - -if [ "$weston_user" != "root" ]; then - echo "user : "$weston_user - script -qc "su -l $weston_user -c '$cmd'" -else - $cmd -fi diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/launch_bin_image_classification_testdata.sh b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/launch_bin_image_classification_testdata.sh deleted file mode 100755 index 88601ceb5..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/launch_bin_image_classification_testdata.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -weston_user=$(ps aux | grep '/usr/bin/weston '|grep -v 'grep'|awk '{print $1}') - -source /usr/local/demo-ai/resources/config_board.sh -cmd="/usr/local/demo-ai/image-classification/nbg/nbg_image_classification -m /usr/local/demo-ai/image-classification/models/mobilenet/$IMAGE_CLASSIFICATION_MODEL.nb -l /usr/local/demo-ai/image-classification/models/mobilenet/$IMAGE_CLASSIFICATION_LABEL\_nbg.txt -i /usr/local/demo-ai/image-classification/models/mobilenet/testdata/" - -if [ "$weston_user" != "root" ]; then - echo "user : "$weston_user - script -qc "su -l $weston_user -c '$cmd'" -else - $cmd -fi diff --git a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/nbg_image_classification.cc b/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/nbg_image_classification.cc deleted file mode 100644 index 5a7bd3739..000000000 --- a/meta-digi-dey/dynamic-layers/x-linux-ai/recipes-samples/image-classification/files/nbg/nbg_image_classification.cc +++ /dev/null @@ -1,1588 +0,0 @@ -/* - * label_nbg_gst_gtk.cc - * - * This application demonstrate a computer vision use case for image - * classification where frames are grabbed from a camera input (/dev/videox) and - * analyzed by a neural network model interpreted by OpenVX stack. - * - * Gstreamer pipeline is used to stream camera frames (using v4l2src), to - * display a preview (using waylandsink) and to execute neural network inference - * (using appsink). - * - * The result of the inference is displayed on the preview. The overlay is done - * using GTK widget with cairo. - * - * This combination is quite simple and efficient in term of CPU consumption. - * - * Author: Alexis Brisson for STMicroelectronics. - * - * Copyright (c) 2020 STMicroelectronics. All rights reserved. - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.opensource.org/licenses/BSD-3-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef GDK_WINDOWING_WAYLAND -#include -#else -#error "Wayland is not supported in GTK+" -#endif - -#include "wrapper_nbg.hpp" - -/* Application parameters */ -std::vector dir_files; -std::string model_file_str; -std::string labels_file_str; -std::string image_dir_str; -std::string video_device_str = ""; -std::string camera_fps_str = "15"; -std::string camera_width_str = "640"; -std::string camera_height_str = "480"; -std::string val_run_str = "50"; - -bool crop = false; -bool verbose = false; -bool validation = false; - -float input_mean = 127.5f; -float input_std = 127.5f; -cv::Rect cropRect(0, 0, 0, 0); - -/* NBG variables */ -struct wrapper_nbg::NBG_Wrapper nbg_wrapper; -struct wrapper_nbg::Config config; -struct wrapper_nbg::Label_Results results; -std::vector labels; - -bool gtk_main_started = false; -bool exit_application = false; - -/* Ressource directory on board */ -#define RESOURCES_DIRECTORY "/usr/local/demo-ai/resources/" - -/* Structure that contains frame size/position on the screen*/ -typedef struct _FramePosition { - int x; - int y; - int width; - int height; -} FramePosition; - -/* Structure that contains all camera configuration information */ -typedef struct _Config_camera { - std::string video_device; - std::string camera_caps; - std::string dcmipp_sensor; -} Config_camera; - -/* Structure that contains all information to pass around */ -typedef struct _CustomData { - /* The gstreamer pipeline */ - GstElement *pipeline; - - /* The GTK window widget */ - GtkWidget *window_main; - GtkWidget *window_overlay; - - /* The drawing area where the camera stream is shown */ - GtkWidget *video; - GstVideoOverlay *video_overlay; - GtkAllocation video_allocation; - - /* Camera information */ - Config_camera camera_info; - - /* Text widget to display info about - * - either the display framerate, and the inference time - * - in fps or ms and the accuracy of the model - */ - GtkWidget *info_inf_time; - GtkWidget *overlay_draw; - GtkWidget *info_inf_time_main; - std::stringstream label_sstr; - - /* window resolution */ - int window_width; - int window_height; - - /* UI parameters (values will depends on display size) */ - int ui_cairo_font_size_label; - int ui_cairo_font_size; - int ui_icon_exit_width; - int ui_icon_exit_height; - int ui_icon_st_width; - int ui_icon_st_height; - double ui_box_line_width; - int ui_weston_panel_thickness; - - /* ST icon widget */ - GtkWidget *st_icon_main; - GtkWidget *st_icon_ov; - std::stringstream st_icon_sstr; - - /* exit icon widget */ - GtkWidget *exit_icon_main; - GtkWidget *exit_icon_ov; - std::stringstream exit_icon_sstr; - - /* Preview camera enable (else still picture use case) */ - bool preview_enabled; - - /* NN input size */ - int nn_input_width; - int nn_input_height; - - /* Frame resolution (still picture or camera) */ - int frame_width; - int frame_height; - - /* Frame resolution and scaling factor */ - float x_scale; - float y_scale; - - /* drawing area resolution */ - int widget_draw_width; - int widget_draw_height; - int offset; - - /* For validation purpose */ - int valid_timeout_id; - int valid_draw_count; - int val_run; - std::vector valid_inference_time; - std::string file; - - /* aspect ratio */ - FramePosition frame_disp_pos; - - /* Still picture variables */ - bool new_inference; - cv::Mat img_to_display; - - /* ISP configuration */ - int cpt_frame = 0; - -} CustomData; - -/* Framerate statistics */ -gdouble display_avg_fps = 0; - -/** - * This function is used to get the display resolution - */ -auto get_display_resolution(CustomData *data){ - std::stringstream cmd; - cmd << "modetest -M stm -c > /tmp/display_resolution.txt"; - system(cmd.str().c_str()); - std::string display_info_pattern = "#0"; - std::ifstream file("/tmp/display_resolution.txt"); - std::string display_information; - std::string display_resolution; - std::string display_width; - std::string display_height; - if (file.is_open()) { - std::string line; - while (std::getline(file, line)) { - int found_resolution = line.find(display_info_pattern); - if (found_resolution != -1) { - display_information = line.substr((found_resolution + display_info_pattern.length())); - } - } - file.close(); - } - system("rm -rf /tmp/display_resolution.txt"); - std::stringstream display_resolution_ss(display_information); - while(std::getline(display_resolution_ss, display_resolution, ' ')) { - int found = display_resolution.find("x"); - if (found != -1) { - display_width = display_resolution.substr(0,found); - display_height = display_resolution.substr(found + 1); - } - } - g_print("display resolution is : %s x %s \n",display_width.c_str(),display_height.c_str()); - data->window_width = std::stoi(display_width); - data->window_height = std::stoi(display_height); - return 0; -} - -/** - * This function is used to setup the camera depending on the - * parameters defined by the user - */ -auto setup_camera() { - std::stringstream config_camera; - config_camera << RESOURCES_DIRECTORY << "setup_camera.sh " << camera_width_str << " " << camera_height_str << " " << camera_fps_str << " " << video_device_str << " > /tmp/camera_device.txt"; - system(config_camera.str().c_str()); - std::string video_device_pattern = "V4L_DEVICE="; - std::string camera_caps_pattern = "V4L2_CAPS="; - std::string dcmipp_sensor_pattern = "DCMIPP_SENSOR="; - Config_camera camera_info; - std::ifstream file("/tmp/camera_device.txt"); - if (file.is_open()) { - std::string line; - while (std::getline(file, line)) { - int found_device = line.find(video_device_pattern); - if (found_device != -1) { - camera_info.video_device = line.substr((found_device + video_device_pattern.length())); - } - int found_camera = line.find(camera_caps_pattern); - if (found_camera != -1) { - camera_info.camera_caps = line.substr((found_camera + camera_caps_pattern.length())); - } - int found_dcmipp = line.find(dcmipp_sensor_pattern); - if (found_dcmipp != -1) { - camera_info.dcmipp_sensor = line.substr((found_dcmipp + dcmipp_sensor_pattern.length())); - } - } - file.close(); - } - system("rm -rf /tmp/camera_device.txt"); - return camera_info; -} - -/** - * This function is called to for updating ISP configuration - */ - -auto update_isp_config(CustomData *data) -{ - std::stringstream isp_file; - std::stringstream isp_config; - isp_file << "/usr/local/demo/application/camera/bin/isp"; - isp_config << isp_file.str().c_str() << " -w > /dev/null"; - std::ifstream file(isp_file.str().c_str()); - if (data->cpt_frame == 0 && file.good() && data->camera_info.dcmipp_sensor.compare("imx335") == 0 ){ - system(isp_config.str().c_str()); - } - return TRUE; -} - -/** - * This function is called when the ST icon image is clicked - */ -static gboolean st_icon_cb(GtkWidget *event_box, - GdkEventButton *event, - CustomData *data) -{ - if (!data->preview_enabled){ - g_print("ST icon clicked: new inference\n"); - data->new_inference = true; - } - return TRUE; -} - -/** - * This function is called when the exit icon image is clicked - */ - -static gboolean exit_icon_cb(GtkWidget *event_box, - GdkEventButton *event, - CustomData *data) -{ - g_print("Exit icon clicked: exit\n"); - gtk_main_quit(); - return TRUE; -} - -/** - * In validation mode this function is called when timeout occurs - * Exit application if this function is called - */ -gint valid_timeout_callback(gpointer data) -{ - /* If timeout occurs that means that camera preview and the gtk is not - * behaving as expected */ - g_print("Timeout: application is not behaving has expected\n"); - exit(1); -} - -/** - * This function execute an NN inference - */ -static void nn_inference(uint8_t *img) -{ - nbg_wrapper.RunInference(img, &results); -} - -/** - * This function is an helper to get frame position on the display - */ -static void compute_frame_position(CustomData *data) -{ - int window_width = data->widget_draw_width; - int window_height = data->widget_draw_height; - int offset_x = 0; - int offset_y = 0; - - float width_ratio = (float)window_width / (float)data->frame_width; - float height_ratio = (float)window_height / (float)data->frame_height; - - if (width_ratio > height_ratio) { - data->frame_disp_pos.width = (int)((float)data->frame_width * height_ratio); - data->frame_disp_pos.height = (int)((float)data->frame_height * height_ratio); - data->frame_disp_pos.x = (window_width - data->frame_disp_pos.width) / 2; - data->frame_disp_pos.y = offset_y; - } else { - data->frame_disp_pos.width = (int)((float)data->frame_width * width_ratio); - data->frame_disp_pos.height = (int)((float)data->frame_height * width_ratio); - data->frame_disp_pos.x = offset_x; - data->frame_disp_pos.y = (window_height - data->frame_disp_pos.height) / 2; - } -} - -/** - * This function get a file randomly in a directory - */ -static std::string get_files_in_directory_randomly(std::string directory) -{ - std::stringstream file_path_sstr; - /* Get the list of all the file ins the directory if the list of the - * file is empty */ - if (dir_files.size() == 0) { - DIR* dirp; - /* checking if the directory can be opened */ - if ((dirp = opendir(directory.c_str())) == NULL) { - g_printerr("Cannot open %s\n",directory.c_str()); - exit (1); - } - struct dirent * dp; - while ((dp = readdir(dirp)) != NULL) { - if ((strcmp(dp->d_name, ".") !=0) && - (strcmp(dp->d_name, "..") != 0)) - dir_files.push_back(dp->d_name); - } - closedir(dirp); - } - - /* Check if directory is empty */ - if (dir_files.size() == 0) - return ""; - - int random = rand() % dir_files.size(); - file_path_sstr << directory << dir_files[random]; - dir_files.erase(dir_files.begin() + random); - - return file_path_sstr.str(); -} - -/** - * This function is an idle function waiting for a new picture - * to be infered - */ -bool first_call_validation = true; -static gboolean infer_new_picture(CustomData *data) -{ - if (exit_application) { - gtk_main_quit(); - return FALSE; - } - - if (data->new_inference){ - /* Select a picture in the directory */ - data->file = get_files_in_directory_randomly(image_dir_str); - /* Check the read and right permission of the selected file */ - int ret = access(data->file.c_str(),R_OK); - if (ret != 0){ - g_printerr("Read permission denied to the file %s\n",data->file.c_str()); - exit(1); - } - - /* Read and format the picture */ - cv::Mat img_bgr, img_bgra, img_tdp, img_nn; - - img_bgr = cv::imread(data->file); - cv::cvtColor(img_bgr, img_bgra, cv::COLOR_BGR2BGRA); - data->frame_width = img_bgra.size().width; - data->frame_height = img_bgra.size().height; - compute_frame_position(data); - - /* Get final frame position and dimension and resize it */ - cv::Size size(data->frame_disp_pos.width,data->frame_disp_pos.height); - cv::resize(img_bgra, img_tdp , size); - data->img_to_display = img_tdp.clone(); - /* prepare the inference */ - cv::Size size_nn(data->nn_input_width, data->nn_input_height); - cv::resize(img_bgr, img_nn, size_nn); - cv::cvtColor(img_nn, img_nn, cv::COLOR_BGR2RGB); - - nn_inference(img_nn.data); - - std::stringstream label_sstr; - std::stringstream inference_fps_sstr; - std::stringstream inference_time_sstr; - std::stringstream accuracy_sstr; - label_sstr << labels[results.index[0]]; - - if (results.inference_time != 0) - { - inference_fps_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << (1000 / results.inference_time); - inference_fps_sstr << std::right << std::setw(3) << " fps "; - - inference_time_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << results.inference_time; - inference_time_sstr << std::right << std::setw(2) << " ms "; - - accuracy_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << results.accuracy[0] * 100; - accuracy_sstr << std::right << std::setw(1) << " % "; - } - - /* Update labels */ - std::stringstream info_sstr; - info_sstr << " inf.fps : " << "\n" << inference_fps_sstr.str().c_str() << "\n" << " inf.time : " << "\n" << inference_time_sstr.str().c_str() << "\n" <<" accuracy : " << "\n" << accuracy_sstr.str().c_str(); - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time),label_to_display); - g_free(label_to_display); - - if (validation) { - /* Still picture use case */ - if (first_call_validation){ - /* Skip the first inference time in hardware - * accelerated mode which is the warmup time - * The warmup time is far more important than - * classic inference time and will make average - * inference time completly false - * */ - first_call_validation = false; - } else { - data->valid_inference_time.push_back(results.inference_time); - } - /* Reload the timeout */ - g_source_remove(data->valid_timeout_id); - data->valid_timeout_id = g_timeout_add(10000, - valid_timeout_callback, - NULL); - /* Get the name of the file without extension and underscore */ - std::string file_name = std::filesystem::path(data->file).stem(); - file_name = file_name.substr(0, file_name.find('_')); - - /* Verify that the inference output result matches the file - * name. Else exit the application: validation is failing */ - std::cout << "name extract from the picture file: " - << std::left << std::setw(32) << file_name - << "label: " << label_sstr.str() << std::endl; - - if (file_name.find(label_sstr.str()) == std::string::npos){ - std::cout << "Inference result mismatch the file name\n"; - exit(5); - } - - /* Continue over all files */ - if (dir_files.size() == 0) { - auto avg_inf_time = std::accumulate(data->valid_inference_time.begin(), - data->valid_inference_time.end(), 0.0) / - data->valid_inference_time.size(); - std::cout << "\navg inference time= " << avg_inf_time << " ms\n"; - g_source_remove(data->valid_timeout_id); - gtk_widget_queue_draw(data->window_main); - gtk_widget_queue_draw(data->window_overlay); - exit_application = true; - } else { - data->new_inference = true; - } - } else { - data->new_inference = false; - } - /* Refresh main window and overlay */ - gtk_widget_queue_draw(data->window_overlay); - gtk_widget_queue_draw(data->window_main); - } - return TRUE; -} - -/** - * This function display text is a black stroke and a white fill color - */ -void gui_display_outlined_text(cairo_t *cr, - const char* text) -{ - cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); - cairo_text_path(cr, text); - cairo_fill_preserve(cr); - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); - cairo_set_line_width(cr, 0.5); - cairo_stroke(cr); -} - -/** - * This function is used to load the CSS file for UI configuration - */ -static void gui_gtk_style(CustomData *data) -{ - std::stringstream css_sstr; - css_sstr << RESOURCES_DIRECTORY; - css_sstr << "Default.css"; - - /* checking the reading permission of the file */ - int ret = access(css_sstr.str().c_str(),R_OK); - if (ret != 0){ - g_printerr("Read permission denied to the file %s\n",css_sstr.str().c_str()); - exit(1); - } - GtkCssProvider *cssProvider = gtk_css_provider_new(); - gtk_css_provider_load_from_path (cssProvider, - css_sstr.str().c_str(), - NULL); - gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), - GTK_STYLE_PROVIDER(cssProvider), - GTK_STYLE_PROVIDER_PRIORITY_USER); -} - -/** - * This function is an helper to set UI variable according to the display size - */ -static void gui_set_ui_parameters(CustomData *data) -{ - - int window_constraint = 0; - if (data->window_height > data->window_width) - window_constraint = data->window_width; - else - window_constraint = data->window_height; - - if (window_constraint <= 272) { - /* Display 480x272 */ - g_print("Display config <= 272p \n"); - data->ui_cairo_font_size_label = 15; - data->ui_cairo_font_size = 10; - data->ui_icon_exit_width = 25; - data->ui_icon_exit_height = 25; - data->ui_icon_st_width = 42; - data->ui_icon_st_height = 52; - } else if (window_constraint <= 600) { - /* Display 800x480 */ - /* Display 1024x600 */ - g_print("Display config <= 600p \n"); - data->ui_cairo_font_size_label = 26; - data->ui_cairo_font_size = 16; - data->ui_icon_exit_width = 50; - data->ui_icon_exit_height = 50; - data->ui_icon_st_width = 65; - data->ui_icon_st_height = 80; - } else if (window_constraint <= 720) { - /* Display 1280x720 */ - g_print("Display config <= 720p \n"); - data->ui_cairo_font_size = 20; - data->ui_cairo_font_size_label = 35; - data->ui_icon_exit_width = 50; - data->ui_icon_exit_height = 50; - data->ui_icon_st_width = 130; - data->ui_icon_st_height = 160; - } else if (window_constraint <= 1080) { - /* Display 1920x1080 */ - g_print("Display config <= 1080p \n"); - data->ui_cairo_font_size_label = 45; - data->ui_cairo_font_size = 30; - data->ui_icon_exit_width = 50; - data->ui_icon_exit_height = 50; - data->ui_icon_st_width = 130; - data->ui_icon_st_height = 160; - } else { - /* Default UI parameter */ - g_print("Display config fallback \n"); - data->ui_icon_exit_width = 50; - data->ui_icon_exit_height = 50; - data->ui_icon_st_width = 130; - data->ui_icon_st_height = 160; - data->ui_cairo_font_size = 20; - data->ui_cairo_font_size_label = 35; - } -} - -/** - * This function is an helper to set UI icons sizes according to the display size - */ -static void gui_set_icons_parameters(CustomData *data) -{ - /* set the icons */ - data->st_icon_sstr << RESOURCES_DIRECTORY << "nbg_st_icon_"; - - if (!data->preview_enabled) - data->st_icon_sstr << "next_inference_"; - data->st_icon_sstr << data->ui_icon_st_width << "x" << data->ui_icon_st_height << ".png"; - - /* checking the reading permission of the file */ - int ret = access(data->st_icon_sstr.str().c_str(),R_OK); - if (ret != 0){ - g_printerr("Read permission denied to the file %s\n",data->st_icon_sstr.str().c_str()); - exit(1); - } - - data->exit_icon_sstr << RESOURCES_DIRECTORY << "exit_"; - data->exit_icon_sstr << data->ui_icon_exit_width << "x" << data->ui_icon_exit_height << ".png"; - - /* checking the reading permission of the file */ - ret = access(data->exit_icon_sstr.str().c_str(),R_OK); - if (ret != 0){ - g_printerr("Read permission denied to the file %s\n",data->exit_icon_sstr.str().c_str()); - exit(1); - } -} - -/** - * This function is called each time the GTK UI is redrawn - */ -bool first_call_overlay = true; -static gboolean gui_draw_overlay_cb(GtkWidget *widget, - cairo_t *cr, - CustomData *data) -{ - /* Get drawing area informations */ - int draw_width = gtk_widget_get_allocated_width(widget); - int draw_height= gtk_widget_get_allocated_height(widget); - - /* Updating the information with the new inference results */ - std::stringstream display_fps_sstr; - std::stringstream inference_time_sstr; - std::stringstream inference_fps_sstr; - std::stringstream accuracy_sstr; - float inf_time = 0; - - if (results.inference_time != 0) - { - /* Updating the information with the new inference results */ - display_fps_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << display_avg_fps; - display_fps_sstr << std::right << std::setw(3) << " fps "; - - inference_fps_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << (1000 / results.inference_time); - inference_fps_sstr << std::right << std::setw(3) << " fps "; - - inference_time_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << results.inference_time; - inference_time_sstr << std::right << std::setw(2) << " ms "; - - accuracy_sstr << std::right << std::setw(5) << std::fixed << std::setprecision(1) << results.accuracy[0] * 100; - accuracy_sstr << std::right << std::setw(1) << " % "; - } - - /* set the font and the size for the label*/ - cairo_select_font_face (cr, "monospace", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (cr, data->ui_cairo_font_size_label); - - /* Update the gtk labels with latest information */ - if (data->preview_enabled) { - /* Camera preview use case */ - if (first_call_overlay){ - first_call_overlay = false; - return FALSE; - } else { - /* Update labels */ - std::stringstream info_sstr; - info_sstr << " disp.fps : " << "\n" << display_fps_sstr.str().c_str() << "\n" << " inf.fps : " << "\n" << inference_fps_sstr.str().c_str() << "\n" << " inf.time : " << "\n" << inference_time_sstr.str().c_str() << "\n" <<" accuracy : " << "\n" << accuracy_sstr.str().c_str(); - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time),label_to_display); - g_free(label_to_display); - } - if(exit_application) - gtk_main_quit(); - } else { - /* Still picture use case */ - if (first_call_overlay){ - first_call_overlay = false; - /* add the inference function in idlle after the initialization of - * the GUI */ - g_idle_add((GSourceFunc)infer_new_picture,data); - data->new_inference = true; - return FALSE; - } else { - /* Update labels */ - std::stringstream info_sstr; - info_sstr << " inf.fps : " << "\n" << inference_fps_sstr.str().c_str() << "\n" << " inf.time : " << "\n" << inference_time_sstr.str().c_str() << "\n" <<" accuracy : " << "\n" << accuracy_sstr.str().c_str(); - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time),label_to_display); - g_free(label_to_display); - } - } - - /* Display the label centered in the preview area */ - std::stringstream label_sstr; - cairo_text_extents_t extents; - double x, y; - label_sstr << labels[results.index[0]]; - if (!data->preview_enabled) { - draw_width = data->widget_draw_width; - draw_height= data->widget_draw_height; - } - - cairo_text_extents(cr, label_sstr.str().c_str(), &extents); - x = (draw_width/ 2) - ((extents.width / 2) + extents.x_bearing); - y = draw_height + (extents.y_bearing / 2); - cairo_move_to(cr, x, y); - gui_display_outlined_text(cr, label_sstr.str().c_str()); - cairo_fill (cr); - - /* Validation mode */ - if(validation){ - if (data->preview_enabled) { - if (data->valid_draw_count < 5){ - g_source_remove(data->valid_timeout_id); - data->valid_timeout_id = g_timeout_add(100000, - valid_timeout_callback, - NULL); - data->valid_draw_count++; - } else { - data->valid_inference_time.push_back(results.inference_time); - /* Reload the timeout */ - g_source_remove(data->valid_timeout_id); - data->valid_timeout_id = g_timeout_add(100000, - valid_timeout_callback, - NULL); - data->valid_draw_count++; - if (data->valid_draw_count > data->val_run) { - auto avg_inf_time = std::accumulate(data->valid_inference_time.begin(), - data->valid_inference_time.end(), 0.0) / - data->valid_inference_time.size(); - /* Stop the timeout and properly exit the - * application */ - std::cout << "avg display fps= " << display_avg_fps << std::endl; - std::cout << "avg inference fps= " << (1000 / avg_inf_time) << std::endl; - std::cout << "avg inference time= " << avg_inf_time << std::endl; - g_source_remove(data->valid_timeout_id); - gtk_main_quit(); - } - } - } - } - return TRUE; -} -/** - * This function is creating GTK widget to create the window to overlay UI - * information - */ -static void gui_create_overlay(CustomData *data) -{ - /*Gtk Widget used for the window */ - GtkWidget *main_box; - GtkWidget *drawing_box; - GtkWidget *drawing_area; - GtkWidget *still_pict_draw; - GtkWidget *info_box; - GtkWidget *exit_box; - GtkWidget *st_icon_event_box; - GtkWidget *exit_icon_event_box; - - /* Create the window */ - data->window_overlay = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_set_app_paintable(data->window_overlay, TRUE); - g_signal_connect(G_OBJECT(data->window_overlay), "delete-event", - G_CALLBACK(gtk_main_quit), NULL); - g_signal_connect(G_OBJECT(data->window_overlay), "destroy", - G_CALLBACK(gtk_main_quit), NULL); - - /* Remove title bar */ - gtk_window_set_decorated(GTK_WINDOW(data->window_overlay), FALSE); - - /* Maximize the window size */ - gtk_window_maximize(GTK_WINDOW(data->window_overlay)); - - /* Create the ST icon widget */ - data->st_icon_ov = gtk_image_new(); - st_icon_event_box = gtk_event_box_new(); - gtk_container_add(GTK_CONTAINER(st_icon_event_box), data->st_icon_ov); - g_signal_connect(G_OBJECT(st_icon_event_box),"button_press_event",G_CALLBACK(st_icon_cb), data); - - /* Create the exit icon widget */ - data->exit_icon_ov = gtk_image_new(); - exit_icon_event_box = gtk_event_box_new(); - gtk_container_add(GTK_CONTAINER(exit_icon_event_box), data->exit_icon_ov); - g_signal_connect(G_OBJECT(exit_icon_event_box),"button_press_event",G_CALLBACK(exit_icon_cb), data); - - gtk_image_set_from_file(GTK_IMAGE(data->st_icon_ov), data->st_icon_sstr.str().c_str()); - gtk_image_set_from_file(GTK_IMAGE(data->exit_icon_ov), data->exit_icon_sstr.str().c_str()); - - if (data->preview_enabled) { - /* Camera preview use case */ - /* Create the drawing area to draw text on it using cairo */ - drawing_area = gtk_drawing_area_new(); - gtk_widget_set_app_paintable(drawing_area, TRUE); - g_signal_connect(G_OBJECT(drawing_area), "draw", - G_CALLBACK(gui_draw_overlay_cb), data); - - data->info_inf_time = gtk_label_new(NULL); - gtk_label_set_justify(GTK_LABEL(data->info_inf_time),GTK_JUSTIFY_CENTER); - /* initialize labels */ - std::stringstream info_sstr; - info_sstr << " disp.fps : " << "\n" << " inf.fps : " << "\n" << " inf.time : " << "\n" <<" accuracy : " << "\n"; - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time),label_to_display); - g_free(label_to_display); - - } else { - /* Still picture use case */ - /* Create the video widget */ - still_pict_draw = gtk_drawing_area_new(); - gtk_widget_set_app_paintable(still_pict_draw, TRUE); - g_signal_connect(still_pict_draw, "draw", - G_CALLBACK(gui_draw_overlay_cb), data); - - data->info_inf_time = gtk_label_new(NULL); - gtk_label_set_justify(GTK_LABEL(data->info_inf_time),GTK_JUSTIFY_CENTER); - /* initialize labels */ - std::stringstream info_sstr; - info_sstr << " inf.fps : " << "\n" << " inf.time : " << "\n" <<" accuracy : " << "\n"; - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time),label_to_display); - g_free(label_to_display); - } - - /* Set the boxes */ - info_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(info_box , "gui_overlay_stbox"); - if (data->preview_enabled){ - /* Camera preview use case */ - gtk_box_pack_start(GTK_BOX(info_box), st_icon_event_box, FALSE, FALSE, 4); - gtk_box_pack_start(GTK_BOX(info_box), data->info_inf_time, FALSE, FALSE, 4); - - } else { - /* Still picture use case */ - gtk_box_pack_start(GTK_BOX(info_box), st_icon_event_box, FALSE, FALSE, 4); - gtk_box_pack_start(GTK_BOX(info_box), data->info_inf_time, FALSE, FALSE, 4); - - } - - drawing_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_set_name(drawing_box, "gui_overlay_draw"); - if (data->preview_enabled){ - /* Camera preview use case */ - gtk_box_pack_start(GTK_BOX(drawing_box), drawing_area, TRUE, TRUE, 0); - } else { - /* Still picture use case */ - gtk_box_pack_start(GTK_BOX(drawing_box), still_pict_draw, TRUE, TRUE, 0); - } - - exit_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(exit_box , "gui_overlay_exit"); - gtk_box_pack_start(GTK_BOX(exit_box), exit_icon_event_box, FALSE, FALSE, 2); - - main_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_set_name(main_box, "gui_overlay"); - gtk_box_pack_start(GTK_BOX(main_box), info_box, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(main_box), drawing_box, TRUE, TRUE, 2); - gtk_box_pack_start(GTK_BOX(main_box), exit_box , FALSE, FALSE, 2); - - /* Push the UI into the window_overlay */ - gtk_container_add(GTK_CONTAINER(data->window_overlay), main_box); - gtk_widget_show_all(data->window_overlay); -} - -static gboolean gui_draw_main_cb(GtkWidget *widget, - cairo_t *cr, - CustomData *data) -{ - int offset = 0; - if (data->preview_enabled) { - /* Camera preview use case */ - data->widget_draw_width = gtk_widget_get_allocated_width(widget); - data->widget_draw_height= gtk_widget_get_allocated_height(widget); - } else { - /* Still picture use case */ - data->widget_draw_width = gtk_widget_get_allocated_width(widget); - data->widget_draw_height = gtk_widget_get_allocated_height(widget); - data->offset = (data->widget_draw_width - data->frame_disp_pos.width)/2; - - if(data->img_to_display.data){ - /* Display the resized picture */ - /* Generate the cairo surface */ - int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, - data->frame_disp_pos.width); - - cairo_surface_t *picture = cairo_image_surface_create_for_data(data->img_to_display.data, - CAIRO_FORMAT_RGB24, - data->frame_disp_pos.width, - data->frame_disp_pos.height, - stride); - cairo_set_source_surface(cr,picture,data->offset,0); - cairo_paint(cr); - cairo_surface_destroy(picture); - } else { - /* Set the black background */ - cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); - cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - cairo_paint(cr); - data->new_inference = true; - } - } - return FALSE; -} - -/** - * This function is creating GTK widget to create the main window use to render - * the preview. - * Title label are also used in the main window in order to create boxes with - * sizes that match the label width. - */ -static void gui_create_main(CustomData *data) -{ - /*Gtk Widget used for the window */ - GtkWidget *main_box; - GtkWidget *video_box; - GtkWidget *still_pict_draw; - GtkWidget *overlay; - GtkWidget *info_box; - GtkWidget *exit_box; - GtkWidget *st_icon_event_box; - GtkWidget *exit_icon_event_box; - - /* Create the window */ - data->window_main = gtk_window_new(GTK_WINDOW_TOPLEVEL); - /* Remove title bar */ - gtk_window_set_decorated(GTK_WINDOW(data->window_main), FALSE); - - /* Maximize the window size */ - gtk_window_maximize(GTK_WINDOW(data->window_main)); - - gtk_widget_set_app_paintable(data->window_main, TRUE); - g_signal_connect(G_OBJECT(data->window_main), "delete-event",G_CALLBACK(gtk_main_quit), NULL); - g_signal_connect(G_OBJECT(data->window_main), "destroy",G_CALLBACK(gtk_main_quit), NULL); - - /* Create the ST icon widget */ - data->st_icon_main = gtk_image_new(); - st_icon_event_box = gtk_event_box_new(); - gtk_container_add(GTK_CONTAINER(st_icon_event_box), data->st_icon_main); - g_signal_connect(G_OBJECT(st_icon_event_box),"button_press_event",G_CALLBACK(st_icon_cb), data); - - /* Create the exit icon widget */ - data->exit_icon_main = gtk_image_new(); - exit_icon_event_box = gtk_event_box_new(); - gtk_container_add(GTK_CONTAINER(exit_icon_event_box), data->exit_icon_main); - g_signal_connect(G_OBJECT(exit_icon_event_box),"button_press_event",G_CALLBACK(exit_icon_cb), data); - - gtk_image_set_from_file(GTK_IMAGE(data->st_icon_main), data->st_icon_sstr.str().c_str()); - gtk_image_set_from_file(GTK_IMAGE(data->exit_icon_main), data->exit_icon_sstr.str().c_str()); - - data->overlay_draw = gtk_drawing_area_new(); - gtk_widget_set_app_paintable(data->overlay_draw, TRUE); - if (data->preview_enabled) { - g_signal_connect(data->overlay_draw, "draw",G_CALLBACK(gui_draw_main_cb), data); - } - if (data->preview_enabled) { - /* Camera preview use case */ - /* Create the video widget */ - GstElement *sink = gst_bin_get_by_name (GST_BIN (data->pipeline), "gtkwsink"); - if (!sink && !g_strcmp0 (G_OBJECT_TYPE_NAME (data->pipeline), "GstPlayBin")) { - g_object_get (data->pipeline, "video-sink", &sink, NULL); - if (sink && g_strcmp0 (G_OBJECT_TYPE_NAME (sink), "GstGtkWaylandSink") != 0 - && GST_IS_BIN (sink)) { - GstBin *sinkbin = GST_BIN (sink); - sink = gst_bin_get_by_name (sinkbin, "gtkwsink"); - gst_object_unref (sinkbin); - } - } - g_assert (sink); - g_assert (!g_strcmp0 (G_OBJECT_TYPE_NAME (sink), "GstGtkWaylandSink")); - g_object_get (sink, "widget", &data->video, NULL); - gtk_widget_set_app_paintable(GTK_WIDGET(data->video), TRUE); - - data->info_inf_time_main = gtk_label_new(NULL); - gtk_label_set_justify(GTK_LABEL(data->info_inf_time_main),GTK_JUSTIFY_CENTER); - /* initialize labels */ - std::stringstream info_sstr; - info_sstr << " disp.fps : " << "\n" << " inf.fps : " << "\n" << " inf.time : " << "\n" << " accuracy : " << "\n"; - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time_main),label_to_display); - g_free(label_to_display); - - } else { - /* Still picture preview use case */ - /* Create the drawing widget */ - still_pict_draw = gtk_drawing_area_new(); - gtk_widget_set_app_paintable(still_pict_draw, TRUE); - g_signal_connect(still_pict_draw, "draw", - G_CALLBACK(gui_draw_main_cb), data); - - data->info_inf_time_main = gtk_label_new(NULL); - gtk_label_set_justify(GTK_LABEL(data->info_inf_time_main),GTK_JUSTIFY_CENTER); - /* initialize labels */ - std::stringstream info_sstr; - info_sstr << " inf.fps : " << "\n" << " inf.time : " << "\n" << " accuracy : " << "\n"; - char *label_to_display = g_strdup_printf ("""%s\n""",data->ui_cairo_font_size,info_sstr.str().c_str()); - gtk_label_set_markup(GTK_LABEL(data->info_inf_time_main),label_to_display); - g_free(label_to_display); - } - /* Set the boxes */ - info_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(info_box, "gui_main_stbox"); - if (data->preview_enabled){ - /* Camera preview use case */ - gtk_box_pack_start(GTK_BOX(info_box), st_icon_event_box, FALSE, FALSE, 4); - gtk_box_pack_start(GTK_BOX(info_box), data->info_inf_time_main, TRUE, FALSE, 4); - } else { - /* Still picture use case */ - gtk_box_pack_start(GTK_BOX(info_box), st_icon_event_box, FALSE, FALSE, 4); - gtk_box_pack_start(GTK_BOX(info_box), data->info_inf_time_main, TRUE, FALSE, 4); - } - video_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_set_app_paintable(GTK_WIDGET(video_box), TRUE); - gtk_widget_set_name(video_box, "gui_main_video"); - if (data->preview_enabled){ - /* Camera preview use case */ - gtk_box_pack_start(GTK_BOX(video_box), GTK_WIDGET(data->video), TRUE, TRUE, 0); - } else { - /* Still picture use case */ - gtk_box_pack_start(GTK_BOX(video_box), still_pict_draw, TRUE, TRUE, 0); - } - exit_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_name(exit_box, "gui_main_exit"); - gtk_box_pack_start(GTK_BOX(exit_box), exit_icon_event_box, FALSE, FALSE, 2); - - main_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_set_app_paintable(GTK_WIDGET(main_box), TRUE); - gtk_widget_set_name(main_box, "gui_main"); - gtk_box_pack_start(GTK_BOX(main_box), info_box, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(main_box), video_box, TRUE, TRUE, 2); - gtk_box_pack_start(GTK_BOX(main_box), exit_box, FALSE, FALSE, 2); - - overlay = gtk_overlay_new(); - gtk_container_add(GTK_CONTAINER(overlay),main_box); - gtk_overlay_add_overlay(GTK_OVERLAY(overlay), data->overlay_draw); - gtk_container_add(GTK_CONTAINER(data->window_main),overlay); - gtk_widget_show_all(data->window_main); -} - -/** - * This function is called when appsink Gstreamer element receives a buffer - */ -static GstFlowReturn gst_new_sample_cb(GstElement *sink, CustomData *data) -{ - GstSample *sample; - GstBuffer *app_buffer, *buffer; - GstMapInfo info; - - /* Retrieve the buffer */ - g_signal_emit_by_name (sink, "pull-sample", &sample); - if (sample) { - - update_isp_config(data); - data->cpt_frame += 1; - if (data->cpt_frame == 30) - data->cpt_frame = 0; - - buffer = gst_sample_get_buffer (sample); - - /* Make a copy */ - app_buffer = gst_buffer_ref (buffer); - - gst_buffer_map(app_buffer, &info, GST_MAP_READ); - - /* Execute the inference */ - nn_inference(info.data); - - gst_buffer_unmap(app_buffer, &info); - gst_buffer_unref (app_buffer); - - /* We don't need the appsink sample anymore */ - gst_sample_unref (sample); - - /* Call application callback only in playing state */ - gst_element_post_message(sink, - gst_message_new_application(GST_OBJECT(sink), - gst_structure_new_empty("inference-done"))); - return GST_FLOW_OK; - } - return GST_FLOW_ERROR; -} - -/** - * This function is called by Gstreamer fpsdisplaysink to get fps measurment - * of display - */ -void gst_fps_measure_display_cb(GstElement *fpsdisplaysink, - gdouble fps, - gdouble droprate, - gdouble avgfps, - gpointer data) -{ - display_avg_fps = avgfps; -} - -/** - * This function is called when a Gstreamer error message is posted on the bus. - */ -static void gst_error_cb (GstBus *bus, GstMessage *msg, CustomData *data) -{ - GError *err; - gchar *debug_info; - - /* Print error details on the screen */ - gst_message_parse_error (msg, &err, &debug_info); - g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); - g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none"); - g_clear_error(&err); - g_free(debug_info); - - /* Set the pipeline to READY (which stops camera streaming) */ - gst_element_set_state(data->pipeline, GST_STATE_READY); -} - -/** - * This function is called when a Gstreamer End-Of-Stream message is posted on - * the bus. We just set the pipeline to READY (which stops camera streaming). - */ -static void gst_eos_cb (GstBus *bus, GstMessage *msg, CustomData *data) -{ - g_print("End-Of-Stream reached.\n"); - gst_element_set_state(data->pipeline, GST_STATE_READY); -} - -static void gst_state_changed_cb (GstBus *bus, GstMessage *msg, CustomData *data) { - GstState oldState; - GstState newState; - gst_message_parse_state_changed(msg, &oldState, &newState, 0); - if (newState == GST_STATE_PLAYING && oldState == GST_STATE_PAUSED) { - gst_debug_bin_to_dot_file(GST_BIN(data->pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline_cpp_PAUSED_PLAYING"); - } -} - -/** - * This function is called when a Gstreamer "application" message is posted on - * the bus. - * Here we retrieve the message posted by the appsink gst_new_sample_cb callback. - */ -static void gst_application_cb (GstBus *bus, GstMessage *msg, CustomData *data) -{ - if (g_strcmp0(gst_structure_get_name(gst_message_get_structure(msg)), "inference-done") == 0) { - /* If the message is the "inference-done", update the GTK UI */ - gtk_widget_queue_draw(data->window_overlay); - } -} - -/** - * Construct the Gstreamer pipeline used to stream camera frame and to run - * TensorFlow Lite inference engine using appsink. - */ -static int gst_pipeline_camera_creation(CustomData *data) -{ - GstStateChangeReturn ret; - GstElement *pipeline, *source, *dispsink, *tee, *scale, *framerate; - GstElement *queue1, *queue2, *convert, *convert2, *appsink, *framecrop; - GstElement *fpsmeasure1; - GstBus *bus; - - /* Create the pipeline */ - pipeline = gst_pipeline_new("Image classification live camera"); - data->pipeline = pipeline; - - /* Create gstreamer elements */ - source = gst_element_factory_make_full("v4l2src","name","camera-source","io-mode",0,NULL); - tee = gst_element_factory_make("tee", "frame-tee"); - queue1 = gst_element_factory_make("queue", "queue-1"); - queue2 = gst_element_factory_make("queue", "queue-2"); - convert = gst_element_factory_make("videoconvert", "video-convert"); - convert2 = gst_element_factory_make("videoconvert", "video-convert-wayland"); - framecrop = gst_element_factory_make("videocrop", "videocrop"); - scale = gst_element_factory_make("videoscale", "videoscale"); - dispsink = gst_element_factory_make_full("gtkwaylandsink", "name", "gtkwsink", "drm-device",NULL,NULL); - appsink = gst_element_factory_make("appsink", "app-sink"); - framerate = gst_element_factory_make("videorate", "video-rate"); - fpsmeasure1 = gst_element_factory_make("fpsdisplaysink", "fps-measure1"); - - if (!pipeline || !source || !tee || !queue1 || !queue2 || !convert || !convert2 || - !scale || !dispsink || !appsink || !framerate || !fpsmeasure1 || !framecrop) { - g_printerr("One element could not be created. Exiting.\n"); - return -1; - } - - /* Configure the source element */ - std::stringstream device_sstr; - device_sstr << "/dev/" << data->camera_info.video_device; - g_object_set(G_OBJECT(source), "device", device_sstr.str().c_str(), NULL); - - g_print("video sink used : gtkwaylandsink \n"); - - /* Configure the queue elements */ - g_object_set(G_OBJECT(queue1), "max-size-buffers", 1, "leaky", 2 /* downstream */, NULL); - g_object_set(G_OBJECT(queue2), "max-size-buffers", 1, "leaky", 2 /* downstream */, NULL); - - /* Create caps based on application parameters */ - std::stringstream sourceCaps_sstr; - sourceCaps_sstr << data->camera_info.camera_caps << ",framerate=" << camera_fps_str << "/1"; - g_print("camera pipeline configuration : %s \n",sourceCaps_sstr.str().c_str()); - GstCaps *sourceCaps = gst_caps_from_string(sourceCaps_sstr.str().c_str()); - std::stringstream scaleCaps_sstr; - scaleCaps_sstr << "video/x-raw,format=RGB,width=" << data->nn_input_width << ",height=" << data->nn_input_height; - GstCaps *scaleCaps = gst_caps_from_string(scaleCaps_sstr.str().c_str()); - - /* Configure fspdisplaysink */ - g_object_set(fpsmeasure1, "signal-fps-measurements", TRUE, - "fps-update-interval", 2000, "text-overlay", FALSE, - "video-sink", dispsink, NULL); - g_signal_connect(fpsmeasure1, "fps-measurements", G_CALLBACK(gst_fps_measure_display_cb), NULL); - - /* Configure the videocrop */ - if (crop) { - /* Crop requested */ - int left = cropRect.x; - int right = data->frame_width - left - cropRect.width; - int top = cropRect.y; - int bottom = data->frame_height - top - cropRect.height; - g_object_set(framecrop, "left", left, "right", right, - "top", top, "bottom", bottom, NULL); - } else { - /* No crop requested */ - g_object_set(framecrop, "left", 0, "right", 0, - "top", 0, "bottom", 0, NULL); - } - - /* Configure appsink */ - g_object_set(appsink, "emit-signals", TRUE, "sync", FALSE, - "max-buffers", 1, "drop", TRUE, "caps", scaleCaps, NULL); - g_signal_connect(appsink, "new-sample", G_CALLBACK(gst_new_sample_cb), data); - - /* Add all elements into the pipeline */ - gst_bin_add_many(GST_BIN(pipeline), - source, framerate, tee, convert, convert2, queue1, queue2, scale, - framecrop, fpsmeasure1, appsink, NULL); - - /* Link the elements together */ - if (!gst_element_link_many(source, framerate, NULL)) { - g_error("Failed to link elements (1)"); - return -2; - } - if (!gst_element_link_filtered(framerate, tee, sourceCaps)) { - g_error("Failed to link elements (2)"); - return -2; - } - if (!gst_element_link_many(tee, queue2, convert, framecrop, scale, appsink, NULL)) { - g_error("Failed to link elements (3)"); - return -2; - } - if (!gst_element_link_many(tee, queue1, convert2, fpsmeasure1, NULL)) { - g_error("Failed to link elements (4)"); - return -2; - } - - gst_caps_unref(sourceCaps); - gst_caps_unref(scaleCaps); - - /* Instruct the bus to emit signals for each received message, and - * connect to the interesting signals */ - bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); - gst_bus_add_signal_watch(bus); - g_signal_connect(G_OBJECT(bus), "message::error", (GCallback)gst_error_cb, data); - g_signal_connect(G_OBJECT(bus), "message::eos", (GCallback)gst_eos_cb, data); - g_signal_connect(G_OBJECT(bus), "message::application", (GCallback)gst_application_cb, data); - g_signal_connect(G_OBJECT(bus), "message::state-changed", (GCallback)gst_state_changed_cb, data); - gst_object_unref(bus); - return 0; -} - -/** - * This function display the help when -h or --help is passed as parameter. - */ -static void print_help(int argc, char** argv) -{ - std::cout << - "Usage: " << argv[0] << " -m -l