I'm new to CMake and ROS.
I've been following the tutorial on setting up tensorflow on ubuntu 20.0.4 (server) and rpi4, as well as building tensorflow lite with CMake for my turtlebot3 project.
I added the following code to my CMakeLists.txt and modified my tensorflow source directory from "${TENSORFLOW_SOURCE_DIR}/tensorflow/lite" to "${TENSORFLOW_SOURCE_DIR}/ubuntu/tensorflow/tensorflow/lite"
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project" )
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"${CMAKE_CURRENT_LIST_DIR}/../../../../" ABSOLUTE)
endif()
add_subdirectory(
"${TENSORFLOW_SOURCE_DIR}/ubuntu/tensorflow/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
add_executable(MobileNetV1 src/scripts/MobileNetV1.cpp)
target_link_libraries(MobileNetV1 ${catkin_LIBRARIES} ${OpenCV_INCLUDE_DIRS} tensorflow-lite)
After building I experience the error below.
CMake Error at /home/ubuntu/tensorflow/tensorflow/lite/CMakeLists.txt:449 (add_executable):
Cannot find source file:
/home/tensorflow/core/util/stats_calculator.cc
Tried extensions .c .C .c .cc .cpp .cxx .cu .m .M .mm .h .hh .h .hm
.hpp .hxx .in .txx
CMake Error at /home/ubuntu/tensorflow/tensorflow/lite/CMakeLists.txt:449 (add_executable):
No SOURCES given to target: benchmark_model
The files exist under /home/ubuntu/tensorflow/tensorflow/core/util/stats_calculator.cc. I don't know why its not being detected.
I don't know what to do next can some help me and explain why its giving me this error please.
Code example that I want to compile and run come from this github if you want to replicate.
And if you have links on easy to follow tutorials on how to setup tensorflow-lite on c that would be awesome!
CodePudding user response:
As stated in your code, directory TENSORFLOW_SOURCE_DIR
contains the TensorFlow project. In other words, content of this directory should look like that: https://github.com/tensorflow/tensorflow. And path to the tensorflow-lite should be exactly as written in the tutorial:
${TENSORFLOW_SOURCE_DIR}/tensorflow/lite
If expression "${CMAKE_CURRENT_LIST_DIR}/../../../../"
doesn't denote root of TensorFlow project on your machine, then modify that expression but remain meaning of TENSORFLOW_SOURCE_DIR
variable.
You may print value of variable TENSORFLOW_SOURCE_DIR
after your computations and check that it actually refers to the root of Tensorflow project on your machine.
Actually, the variable TENSORFLOW_SOURCE_DIR
is used in the TensorFlow project itself. And exactly that usage causes problems when your setting of TENSORFLOW_SOURCE_DIR
doesn't corresponds to expectations of its meaning in Tensorflow project.
I wonder why the tutorial suggests to set TENSORFLOW_SOURCE_DIR
variable but does not note about the variable's usage in the TensorFlow project.
Instead of TENSORFLOW_SOURCE_DIR
variable your code could use any other variable which isn't used by Tensorflow. You could even hardcode the path to TensorFlow lite in your code:
# Do not define and do not use `TENSORFLOW_SOURCE_DIR` variable at all
add_subdirectory(
"/home/ubuntu/tensorflow/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
When find variable TENSORFLOW_SOURCE_DIR
being not set, the script tensorflow/lite/CMakeLists.txt
will correctly set it automatically: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/CMakeLists.txt#L42