我如何为tensorflow lite创建一个cmake配置?

dbf7pr2w  于 2022-11-11  发布在  其他
关注(0)|答案(1)|浏览(164)

我想为我的tensorflow lite项目创建一个cmake配置。问题是我不知道如何将我的项目与tensorflow链接起来。下面是我的项目树:

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

我想在./build中运行cmake -G Ninja ..来创建ninja的构建文件。这是我现在拥有的简单的CMakeLists.txt,没有链接到tensorflow,因此不会构建:

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/
)
jv2fixgn

jv2fixgn1#

此网站回答了以下问题:https://www.tensorflow.org/lite/guide/build_cmake#create_a_cmake_project_which_uses_tensorflow_lite
对于未来的任何人,这里是我的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)

虽然这是没有目录app/,我选择删除。

相关问题