Home > database >  How can I create a cmake configuration for tensorflow lite?
How can I create a cmake configuration for tensorflow lite?

Time:10-11

I want to create a cmake configuration for my tensorflow lite project. The problem is that I do not know how to link my project with tensorflow. Here is my project tree:

.
├── app
│   ├── include
│   └── src
│       └── main.cpp
├── build
├── CMakeLists.txt
├── README.md
└── tensorflow # <-- submodule of the tensorflow/tensorflow.git repo

I want to within ./build run cmake -G Ninja .. to create the build files for ninja. This is the simple CMakeLists.txt I have right now, not linked to tensorflow and therefor won't build:

cmake_minimum_required(VERSION 3.2.2)
project(trash-finder-tf LANGUAGES CXX)

option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${FORCE_COLORED_OUTPUT})
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
       add_compile_options (-fdiagnostics-color=always)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
       add_compile_options (-fcolor-diagnostics)
    endif ()
endif ()

add_executable(main
    src/main.cpp
)

include_directories(main PRIVATE
    include/
)

CodePudding user response:

This website answers the question: https://www.tensorflow.org/lite/guide/build_cmake#create_a_cmake_project_which_uses_tensorflow_lite

For anyone in the future, here is my cmakelists.txt:

cmake_minimum_required(VERSION 3.2.2)
project(app LANGUAGES CXX)

option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${FORCE_COLORED_OUTPUT})
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
       add_compile_options (-fdiagnostics-color=always)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
       add_compile_options (-fcolor-diagnostics)
    endif ()
endif ()

add_subdirectory(
    "tensorflow/tensorflow/lite"
    "$(CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)

add_executable(main
    src/main.cpp
)

include_directories(main PRIVATE
    include/
)

target_link_libraries(main
    tensorflow-lite)

Though this is without the directory app/ which I chose to remove.

  • Related