tongtybj / edgetpu_roscpp

Use Edge TPU (Coral) with ROS based on C++
12 stars 2 forks source link

cannot find -ltensorflow-lite #5

Open zlg9folira opened 3 years ago

zlg9folira commented 3 years ago

I am building edgetpu_roscpp on arm64 Debian buster (pi4) with all dependencies installed. It is not able to locate tensorflow-lite:

catkin_make --only-pkg-with-deps edgetpu_roscpp --make-args -j1

Output:

.
.
[ 97%] Built target JSK_NODELET_jsk_perception_flow_velocity_thresholding
[ 97%] Built target JSK_NODELET_jsk_perception_lab_decomposer
[ 98%] Built target JSK_NODELET_jsk_perception_colorize_float_image
No handlers could be found for logger "rosout"
[ 98%] Built target install_test_data
[ 98%] Built target link_test_data
[ 98%] Built target link_scripts
[ 98%] Linking CXX shared library /.../catkin_ws/devel/lib/libedgetpu_engine.so
/usr/bin/ld: cannot find -ltensorflow-lite
/usr/bin/ld: skipping incompatible /.../catkin_ws/src/edgetpu_roscpp/edgetpu/libedgetpu/direct/k8/libedgetpu.so.1.0 when searching for -l:libedgetpu.so.1.0
/usr/bin/ld: skipping incompatible /.../catkin_ws/src/edgetpu_roscpp/edgetpu/libedgetpu/direct/k8/libedgetpu.so.1.0 when searching for -l:libedgetpu.so.1.0
collect2: error: ld returned 1 exit status
make[2]: *** [edgetpu_roscpp/CMakeFiles/edgetpu_engine.dir/build.make:1240: /.../catkin_ws/devel/lib/libedgetpu_engine.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:78176: edgetpu_roscpp/CMakeFiles/edgetpu_engine.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Invoking "make -j1" failed

How to address this linker issue ?

tongtybj commented 3 years ago

Thank you for your effort to test in aarch64. Current CMakeLists.txt only supports x64 arch:

But, we can also support aarch64 by changing above link_directories. I will test with my aarch64 environment, which will take few days. BTW, could you tell me what kind of directory you can see under edgetpu_roscpp/tensorflow/tensorflow/lite/tools/make/gen/

zlg9folira commented 3 years ago

I see this path in my directory structure: /tensorflow/lite/tools/make/gen/aarch64/lib/ And inside that I got two .a including tensorflow-lite.a. Would updating line 44 in CMakelist fix this issue ?

tongtybj commented 3 years ago

Would updating line 44 in CMakelist fix this issue?

Yes. change to ${TENSORFLOW_DIR}/tensorflow/lite/tools/make/gen/aarch64/lib in this line. Besides, please update the path in 60 to link_directories(${EDGETPU_DIR}/libedgetpu/direct/aarch64

These should solve the build failure.

zlg9folira commented 3 years ago

Thanks. The issue with libtensorflow-lite in build is gone and it gets completed:

[ 97%] Built target linemod
[ 97%] Built target JSK_NODELET_jsk_perception_flow_velocity_thresholding
[ 97%] Built target JSK_NODELET_jsk_perception_lab_decomposer
[ 98%] Built target JSK_NODELET_jsk_perception_colorize_float_image
No handlers could be found for logger "rosout"
edgetpu_roscpp is not found in ['rosconsole', 'catkin', 'angles', ....]
Package [edgetpu_roscpp] is not found in current workspace. Skipping download
[ 98%] Built target install_test_data
[ 98%] Built target link_test_data
[ 98%] Built target link_scripts
[ 98%] Linking CXX shared library /.../catkin_ws/devel/lib/libedgetpu_engine.so
...
[100%] Built target edgetpu_minimal
Scanning dependencies of target JSK_NODELET_edgetpu_roscpp_deep_object_detection
[100%] Building CXX object edgetpu_roscpp/CMakeFiles/JSK_NODELET_edgetpu_roscpp_deep_object_detection.dir/JSK_NODELET_edgetpu_roscpp_deep_object_detection.cpp.o
[100%] Linking CXX executable /.../catkin_ws/devel/lib/edgetpu_roscpp/deep_object_detection
[100%] Built target JSK_NODELET_edgetpu_roscpp_deep_object_detection

I am not sure why I see Package [edgetpu_roscpp] is not found in current workspace while it was already there that I could build it via catkin_make. Anyway, that may not be in issue with the build.

Now I am trying to run either nodes, for example: roslaunch edgetpu_roscpp object_detection_test.launch The output for this node and others (classify_image_test.launch, ...) show an issue with loading EdgeTPU:

... logging to /home/.../.ros/log/00735192-ba60-11eb-a019-dca6328321c0/roslaunch-...-19993.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://...:43441/

SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.17

NODES
  /
    object_detection (edgetpu_roscpp/object_detection)

ROS_MASTER_URI=http://localhost:11311

process[object_detection-1]: started with pid [20032]
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0521 14:17:29.552183 20032 basic_engine.cc:8] Internal: Unsupported data type in custom op handler: 0Node number 0 (edgetpu-custom-op) failed to prepare.
Failed to allocate tensors.
*** Check failure stack trace: ***
[object_detection-1] process has died [pid 20032, exit code -6, cmd /.../catkin_ws/devel/lib/edgetpu_roscpp/object_detection --model_path=/.../catkin_ws/src/edgetpu_roscpp/test/data/edgetpu/ssd_mobilenet_v1_fine_tuned_edgetpu.tflite --image_path=/.../catkin_ws/src/edgetpu_roscpp/test/data/edgetpu/pets.jpg --labels_path=/.../catkin_ws/src/edgetpu_roscpp/test/data/edgetpu/pet_labels.txt --keep_aspect_ratio=false __name:=object_detection __log:=/....ros/log/00735192-ba60-11eb-a019-dca6328321c0/object_detection-1.log].
log file: /.../.ros/log/00735192-ba60-11eb-a019-dca6328321c0/object_detection-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

I think my edgeTPU package is alright. Here is the output of dpkg -l | grep edgetpu:

ii  libedgetpu-dev                         15.0                                    arm64        Development files for libedgetpu
ii  libedgetpu1-std:arm64                  15.0                                    arm64        Support library for Edge TPU

I am also able to run all the Coral examples using the same hardware. My python3-tflite-runtime is version 2.5.0. The error could be because of a version incompatibility issue.

tongtybj commented 3 years ago

I found similar issue here and here. It seems like they solve the same problem by using another commit version of tensorflow: https://github.com/Namburger/edgetpu-minimal-example/blob/master/CMakeLists.txt#L12

Could you replace https://github.com/tongtybj/edgetpu_roscpp/blob/master/CMakeLists.txt#L20 with 5d0b55dd4a00c74809e5b32217070a26ac6ef823 (you have to remove the directory of tensorflow under edgetpu_rospp first) Or you can directly try https://github.com/Namburger/edgetpu-minimal-example first.

zlg9folira commented 3 years ago

You mean replace with d855adfc5a0195788bf5f92c3c7352e638aa1109 ? Cause https://github.com/tongtybj/edgetpu_roscpp/blob/master/CMakeLists.txt#L20 already includes 5d0b55dd4a00c74809e5b32217070a26ac6ef823. So I am going to buildedgetpu-minimal-example first as the other commit (...aa1109) is used. I will post the result if older tf solves the issue.

tongtybj commented 3 years ago

You mean replace with d855adfc5a0195788bf5f92c3c7352e638aa110

Sorry for my wrong paste. You are right.

Looking forward to your result.

zlg9folira commented 3 years ago

Setting TENSORFLOW_COMMIT to d855adfc5a0195788bf5f92c3c7352e638aa1109 will cause edgetpu_roscpp build to stuck at compiling tensorflow with this error:

In file included from tensorflow/lite/kernels/activations.cc:25:
./tensorflow/lite/kernels/internal/common.h:24:10: fatal error: fixedpoint/fixedpoint.h: No such file or directory
 #include "fixedpoint/fixedpoint.h"

Also I noticed this commit has a bug which is fixed in tensorflow/tensorflow@72cd947 - I observed similar errors as reported there. But getting back to edgetpu_roscpp, since the defined directory structure is different, CMakeList.txt will require further edits to be able to find TF header files during the build. To save time, I built edgetpu-minimal-example using 72cd947f231950d7ecd1406b5a67388fef7133ea commit and copied directoryedgetpu-minimal-example/build/tensorflow/src/tf/tensorflow to /catkin_ws/src/edgetpu_roscpp/tensorflow. This solved the issues with missing header files.

Building edgetpu_roscpp now terminates with undefined reference to "rdft":

[100%] Building CXX object edgetpu_roscpp/CMakeFiles/edgetpu_engine.dir/edgetpu/src/cpp/posenet/posenet_decoder_op.cc.o
[100%] Linking CXX shared library /home/pi/catkin_ws/devel/lib/libedgetpu_engine.so
[100%] Built target edgetpu_engine
Scanning dependencies of target object_detection
[100%] Building CXX object edgetpu_roscpp/CMakeFiles/object_detection.dir/src/object_detection.cpp.o
[100%] Linking CXX executable /.../catkin_ws/devel/lib/edgetpu_roscpp/object_detection
/usr/bin/ld: /.../catkin_ws/devel/lib/libedgetpu_engine.so: undefined reference to `rdft'
collect2: error: ld returned 1 exit status
make[2]: *** [edgetpu_roscpp/CMakeFiles/object_detection.dir/build.make:1106: /.../catkin_ws/devel/lib/edgetpu_roscpp/object_detection] Error 1
make[1]: *** [CMakeFiles/Makefile2:77875: edgetpu_roscpp/CMakeFiles/object_detection.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

I couldn't find any reference to fix this. Probably re-producing the error on an arm64 could be a good idea if you have access to one.

zlg9folira commented 3 years ago

Finally, built and ran without error using the following specific tensorflow and libedgetpu commits on arm64. These two work nicely. tensorflow: 582c8d236cb079023657287c318ff26adb239002 libedgetpu: 14eee1a076aa1af7ec1ae3c752be79ae2604a708

I built these two from source and out of catkin_ws, otherwise, the CMakeLists.txt would require a complete reconstruction (executables in edgetpu no longer exist and links to a few libraries are missing). This way, I just needed to update line 60 to point to /usr/lib/aarch64-linux-gnu/libedgetpu.so.1.

Thank you @tongtybj. Hope the info help others. If I get some time, I will optimize the C++ rosnode for arm64 and share here.

tongtybj commented 3 years ago

@zlg9folira

Thank you for your great effort to use my code in arm64. I will update CMakeLists.txt to support arm64 in the near future following your comments.

gsirocco commented 1 year ago

In terms of the rdft error, referenced below, in this issue, I'm not clear what the exact fix is for the 'rdft' undefined reference? I am currently facing the same error in my build with edgetpu and tensorflowlite. Btw, my build target is k8 (x86_64). Thanks!!

Is it specific versions of tensorflow and edgetpu that have an issue?

I am trying to incorporate edgetpu functionality into an existing application which already has it's own build system that uses Cmake. The 'rdft' undefined reference is more of a build issue or a specific version of tensorflow or edgetpu code?

Finally, built and ran without error using the following specific tensorflow and libedgetpu commits on arm64. These two work nicely. tensorflow: 582c8d236cb079023657287c318ff26adb239002 libedgetpu: 14eee1a076aa1af7ec1ae3c752be79ae2604a708

I built these two from source and out of catkin_ws, otherwise, the CMakeLists.txt would require a complete reconstruction (executables in edgetpu no longer exist and links to a few libraries are missing). This way, I just needed to update line 60 to point to /usr/lib/aarch64-linux-gnu/libedgetpu.so.1.

Thank you @tongtybj. Hope the info help others. If I get some time, I will optimize the C++ rosnode for arm64 and share here.

Building edgetpu_roscpp now terminates with undefined reference to "rdft":