tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone
https://tensorflow.org
Apache License 2.0
183.85k stars 74.04k forks source link

TensorFlow Lite label_image fails to build with cmake #70659

Open NobuoTsukamoto opened 2 days ago

NobuoTsukamoto commented 2 days ago

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

v2.17.0-rc0

Custom code

No

OS platform and distribution

Linux (Raspberry Pi OS)

Mobile device

Raspberry Pi 4

Python version

3.11.2

Bazel version

No response

GCC/compiler version

12.2.0

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

I get the error

tensorflow/lite/profiling/proto/profiling_info.pb.h: No such file or directory.

Standalone code to reproduce the issue

$ git clone -b v2.17.0-rc0 https://github.com/tensorflow/tensorflow
$ mkdir tflite_build && tflite_build
$ cmake ../tensorflow/tensorflow/lite/
$ cmake --build . -j3
$ cmake --build . -t label_image
In file included from /home/pi/tensorflow/tensorflow/lite/profiling/profile_summarizer.h:28,
                 from /home/pi/tensorflow/tensorflow/lite/profiling/profile_summarizer.cc:16:
/home/pi/tensorflow/tensorflow/lite/profiling/profile_summary_formatter.h:31:10: fatal error: tensorflow/lite/profiling/proto/profiling_info.pb.h: No such file or directory
   31 | #include "tensorflow/lite/profiling/proto/profiling_info.pb.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.


### Relevant log output

_No response_
NobuoTsukamoto commented 2 days ago

The problem is that tensorflow/lite/profiling/proto/profiling_info.pb.h is generated under CMAKE_BINARY_DIR, but there is no include_directories setting.

Adding the following modification to tensorflow/lite/examples/label_image/CMakeLists.txt will resolve the error,

$ git diff tensorflow/lite/examples/label_image/CMakeLists.txt
diff --git a/tensorflow/lite/examples/label_image/CMakeLists.txt b/tensorflow/lite/examples/label_image/CMakeLists.txt
index 9874801f34f..5acbae31565 100644
--- a/tensorflow/lite/examples/label_image/CMakeLists.txt
+++ b/tensorflow/lite/examples/label_image/CMakeLists.txt
@@ -61,6 +61,11 @@ if(TFLITE_ENABLE_EXTERNAL_DELEGATE)
           ${TFLITE_SOURCE_DIR}/tools/delegates/external_delegate_provider.cc)
 endif()

+include_directories(label_image
+  PUBLIC
+  ${CMAKE_BINARY_DIR}
+)
+
 add_executable(label_image
   ${TFLITE_LABEL_IMAGE_SRCS}
 )

but a new error will occur.


/usr/bin/ld: CMakeFiles/label_image.dir/__/__/profiling/profile_summary_formatter.cc.o: in function `tflite::profiling::ProfileSummaryProtoFormatter::GenerateOpProfileDataFromDetail(tsl::StatsCalculator::Detail const*, tsl::StatsCalculator const*, tflite::profiling::OpProfileData*) const [clone .part.0]':
profile_summary_formatter.cc:(.text+0x9c): undefined reference to `google::protobuf::internal::ArenaStringPtr::Set(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x218): undefined reference to `google::protobuf::internal::ArenaStringPtr::Set(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x2e8): undefined reference to `tflite::profiling::OpProfilingStat* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::OpProfilingStat>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x304): undefined reference to `tflite::profiling::OpProfilingStat* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::OpProfilingStat>(google::protobuf::Arena*)'
/usr/bin/ld: CMakeFiles/label_image.dir/__/__/profiling/profile_summary_formatter.cc.o: in function `tflite::profiling::ProfileSummaryProtoFormatter::GenerateSubGraphProfilingData(tsl::StatsCalculator const*, int, std::map<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&, tflite::profiling::SubGraphProfilingData*) const':
profile_summary_formatter.cc:(.text+0x3748): undefined reference to `google::protobuf::internal::ArenaStringPtr::Set(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x384c): undefined reference to `tflite::profiling::OpProfileData* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::OpProfileData>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3858): undefined reference to `google::protobuf::internal::RepeatedPtrFieldBase::AddOutOfLineHelper(void*)'
/usr/bin/ld: CMakeFiles/label_image.dir/__/__/profiling/profile_summary_formatter.cc.o: in function `tflite::profiling::ProfileSummaryProtoFormatter::GenerateDelegateProfilingData(tsl::StatsCalculator const*, tflite::profiling::DelegateProfilingData*) const':
profile_summary_formatter.cc:(.text+0x3a24): undefined reference to `tflite::profiling::OpProfileData* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::OpProfileData>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3a30): undefined reference to `google::protobuf::internal::RepeatedPtrFieldBase::AddOutOfLineHelper(void*)'
/usr/bin/ld: CMakeFiles/label_image.dir/__/__/profiling/profile_summary_formatter.cc.o: in function `tflite::profiling::ProfileSummaryProtoFormatter::GetOutputString(std::map<unsigned int, std::unique_ptr<tsl::StatsCalculator, std::default_delete<tsl::StatsCalculator> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::unique_ptr<tsl::StatsCalculator, std::default_delete<tsl::StatsCalculator> > > > > const&, tsl::StatsCalculator const&, std::map<unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) const':
profile_summary_formatter.cc:(.text+0x3ab8): undefined reference to `tflite::profiling::ModelProfilingData::ModelProfilingData(google::protobuf::Arena*, bool)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3b2c): undefined reference to `tflite::profiling::SubGraphProfilingData* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::SubGraphProfilingData>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3b38): undefined reference to `google::protobuf::internal::RepeatedPtrFieldBase::AddOutOfLineHelper(void*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3b8c): undefined reference to `google::protobuf::MessageLite::SerializeAsString[abi:cxx11]() const'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3b94): undefined reference to `tflite::profiling::ModelProfilingData::~ModelProfilingData()'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3bbc): undefined reference to `tflite::profiling::DelegateProfilingData* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::DelegateProfilingData>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3bc8): undefined reference to `google::protobuf::internal::RepeatedPtrFieldBase::AddOutOfLineHelper(void*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3bdc): undefined reference to `tflite::profiling::ModelProfilingData::~ModelProfilingData()'
/usr/bin/ld: CMakeFiles/label_image.dir/__/__/profiling/profile_summary_formatter.cc.o: in function `tflite::profiling::ProfileSummaryProtoFormatter::HandleOutput(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) const':
profile_summary_formatter.cc:(.text+0x3cf4): undefined reference to `tflite::profiling::BenchmarkProfilingData::BenchmarkProfilingData(google::protobuf::Arena*, bool)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3d18): undefined reference to `google::protobuf::MessageLite::SerializeToOstream(std::ostream*) const'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3d28): undefined reference to `tflite::profiling::BenchmarkProfilingData::~BenchmarkProfilingData()'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3dc0): undefined reference to `google::protobuf::MessageLite::ParseFromString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3de4): undefined reference to `google::protobuf::MessageLite::ParseFromString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3f28): undefined reference to `google::protobuf::Message::DebugString[abi:cxx11]() const'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3f7c): undefined reference to `tflite::profiling::ModelProfilingData* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::ModelProfilingData>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3f94): undefined reference to `tflite::profiling::ModelProfilingData* google::protobuf::Arena::CreateMaybeMessage<tflite::profiling::ModelProfilingData>(google::protobuf::Arena*)'
/usr/bin/ld: profile_summary_formatter.cc:(.text+0x3fc4): undefined reference to `tflite::profiling::BenchmarkProfilingData::~BenchmarkProfilingData()'
collect2: error: ld returned 1 exit status
gmake[3]: *** [examples/label_image/CMakeFiles/label_image.dir/build.make:409: examples/label_image/label_image] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:7751: examples/label_image/CMakeFiles/label_image.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:7758: examples/label_image/CMakeFiles/label_image.dir/rule] Error 2
gmake: *** [Makefile:2600: label_image] Error 2
NobuoTsukamoto commented 2 days ago

tensorflow/lite/profiling/proto/profiling_info.pb.cc and the link of the libprotobuf library are missing from label_image's CMakeLists.txt.

I was able to confirm that label_image can be built successfully with the following corrections.

 git diff tensorflow/lite/examples/label_image/CMakeLists.txt
diff --git a/tensorflow/lite/examples/label_image/CMakeLists.txt b/tensorflow/lite/examples/label_image/CMakeLists.txt
index 9874801f34f..4e3cf86daf6 100644
--- a/tensorflow/lite/examples/label_image/CMakeLists.txt
+++ b/tensorflow/lite/examples/label_image/CMakeLists.txt
@@ -31,6 +31,7 @@ list(APPEND TFLITE_LABEL_IMAGE_SRCS
   ${TFLITE_SOURCE_DIR}/tools/delegates/delegate_provider.cc
   ${TFLITE_SOURCE_DIR}/tools/evaluation/utils.cc
   ${TFLITE_SOURCE_DIR}/tools/tool_params.cc
+  ${CMAKE_BINARY_DIR}/tensorflow/lite/profiling/proto/profiling_info.pb.cc
 )

 if(TFLITE_ENABLE_XNNPACK)
@@ -61,6 +62,11 @@ if(TFLITE_ENABLE_EXTERNAL_DELEGATE)
           ${TFLITE_SOURCE_DIR}/tools/delegates/external_delegate_provider.cc)
 endif()

+include_directories(label_image
+  PUBLIC
+  ${CMAKE_BINARY_DIR}
+)
+
 add_executable(label_image
   ${TFLITE_LABEL_IMAGE_SRCS}
 )
@@ -78,4 +84,5 @@ target_compile_options(label_image
 )
 target_link_libraries(label_image
   tensorflow-lite
+  ${CMAKE_BINARY_DIR}/_deps/protobuf-build/libprotobuf.a
 )
NobuoTsukamoto commented 2 days ago

I'm not sure if modifying label_image's CMakeLists.txt is the correct approach, but I have confirmed that it can be built with the following modifications.

$ git diff tensorflow/lite/examples/label_image/CMakeLists.txt
diff --git a/tensorflow/lite/examples/label_image/CMakeLists.txt b/tensorflow/lite/examples/label_image/CMakeLists.txt
index 9874801f34f..2fcb09ce96e 100644
--- a/tensorflow/lite/examples/label_image/CMakeLists.txt
+++ b/tensorflow/lite/examples/label_image/CMakeLists.txt
@@ -61,6 +61,11 @@ if(TFLITE_ENABLE_EXTERNAL_DELEGATE)
           ${TFLITE_SOURCE_DIR}/tools/delegates/external_delegate_provider.cc)
 endif()

+include_directories(label_image
+  PUBLIC
+  ${CMAKE_BINARY_DIR}
+)
+
 add_executable(label_image
   ${TFLITE_LABEL_IMAGE_SRCS}
 )
@@ -78,4 +83,6 @@ target_compile_options(label_image
 )
 target_link_libraries(label_image
   tensorflow-lite
+  profiling_info_proto
+  protobuf
 )
NobuoTsukamoto commented 1 day ago

The latest commit (775c84d11596da38120a9443dca87ca5d7930ead) still gives the error I reported.