tensorflow_ros_cpp package from tensorflow_ros_cpp repotensorflow_ros_cpp |
|
Package Summary
Tags | No category tags. |
Version | 3.2.0 |
License | BSD |
Build type | CATKIN |
Use | RECOMMENDED |
Repository Summary
Checkout URI | https://github.com/tradr-project/tensorflow_ros_cpp.git |
VCS Type | git |
VCS Version | master |
Last Updated | 2022-06-08 |
Dev Status | MAINTAINED |
CI status | No Continuous Integration |
Released | UNRELEASED |
Tags | No category tags. |
Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Package Description
Additional Links
Maintainers
- Martin Pecka
Authors
tensorflow_ros_cpp
A Catkin-friendly package for utilizing the C++ API of Tensorflow.
Get Tensorflow C++ API into ROS as easy as
find_package(catkin REQUIRED COMPONENTS
... your other packages ...
tensorflow_ros_cpp
)
See the usage example at [https://github.com/tradr-project/tensorflow_ros_test].
New: Support for Noetic and TensorFlow 2.x!
Supported Tensorflow installations
You can choose either one of the following options to install Tensorflow
.
-
As a pip (Python) package: The easiest way on Ubuntu 14.04 and 20.04, Just
pip install tensorflow
and that’s it. GPU version supported! Can be used on Ubuntu 16.04 and 18.04, too, but with important limitations. -
Using
tensorflow_catkin
package: Easily compile Tensorflow for your platform. A convenient way on newer systems. Supports GPU version. - Using a custom build of Tensorflow built by bazel: The least comfortable, yet most powerful way. Compile Tensorflow yourself using bazel and tell this package where to find it.
See below for more detail about each of the installation types and how to set them up.
Note for rosdep
users
If you’re managing dependencies via rosdep
, it is likely that you do not want it to try to install the optional dependencies (currently python-tensorflow-pip
and tensorflow_catkin
). In such case, add the following to the rosdep call:
rosdep install ... --skip-keys=tensorflow_catkin --skip-keys=python-tensorflow-pip
Tested compatible versions
If you successfully used this package on an untested configuration (marked with ?
), please, tell us.
Ubuntu 14.04 64bits, Python 2.7.6, ROS Indigo
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
0.12.1 | no | no | ✓ | ✓ | ? | ? | N/A | N/A |
1.0.0 | no | no | ✓ | ✓ | ? | ? | N/A | N/A |
1.1.0 | 8 | 5 | ✓ | ✓ | ? | ? | N/A | N/A |
1.2.0 | 8 | 5 | ✓ | ✓ | ? | ? | N/A | N/A |
1.3.0 | 8 | 6 | ✓ | ✓ | ? | ? | N/A | N/A |
1.4.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.5.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.6.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.7.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ✓ | ✓ | ✓ | ✓ |
1.8.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.14.0 | 8 | 6 | ✓ | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
1.15.0 | 8 | 6 | X (link error) | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
Ubuntu 14.04 64bits, Python 3.4, ROS Indigo
Had to set TF_PYTHON_LIBRARY
manually since CMake was only finding Python 2.7 libraries.
TF | CUDA | pip3 tensorflow | pip3 tensorflow-gpu |
---|---|---|---|
1.8.0 | 8 | ✓ | N/A (wants CUDA 9) |
Ubuntu 16.04 64bits, Python 2.7.6, ROS Kinetic
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
0.12.1 | 8.0 | no | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.0.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.1.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.2.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.3.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.4.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.5.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.6.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.7.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ✓ | ✓ | ✓ |
1.8.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ✓ | N/A | N/A |
1.14.0 | 9.0 | 7.0 | ✓, see ABI difference problems | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
1.15.0 | 9.0 | 7.0 | ✓, see ABI difference problems | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
Ubuntu 16.04 64bits, Python 3.5, ROS Kinetic
Had to set TF_PYTHON_LIBRARY
manually since CMake was only finding Python 2.7 libraries.
TF | CUDA | CUDNN | pip3 tensorflow | pip3 tensorflow-gpu |
---|---|---|---|---|
1.8.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems |
Ubuntu 18.04 64bits, Python 2.7.6, ROS Melodic
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
1.0.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.1.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.2.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.3.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.4.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.5.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.6.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.7.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | ✓ | ✓ |
1.7.0 | 9.1 | 7.1 | N/A | N/A | ? | ? | ✓ | ✓ |
1.8.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ✓ | N/A | N/A |
1.8.0 | 9.1 | 7.1 | N/A | N/A | ✓ | ✓ | N/A | N/A |
1.14.0 | 10.0 | 7.4 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ? | ? | ? |
1.14.0 | 10.0 | 7.4 | ✓, see ABI difference problems | ? | ? | ? | ? | ? |
Ubuntu 18.04 64bits, Python 3.6, ROS Melodic
Had to set TF_PYTHON_LIBRARY
manually since CMake was only finding Python 2.7 libraries.
TF | CUDA | CUDNN | pip3 tensorflow | pip3 tensorflow-gpu |
---|---|---|---|---|
1.8.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems |
1.14.0 | 10.0 | 7.4 | ✓, see ABI difference problems | ✓, see ABI difference problems |
Ubuntu 20.04 64bits, Python 3.8, ROS Noetic
TF | CUDA | CUDNN | pip3 tensorflow | |
---|---|---|---|---|
2.9.1 | no | no | ✓ | ✓ |
Debian Jessie 64bits, Python 2.7.6, ROS Indigo
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
1.3.0 | 8.0 | 6 | ✓ | ✓ | ? | ? | ? | ? |
Debian Stretch 64bits, Python 2.7.6, ROS Indigo (compiled from source)
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
1.4.0 | 8.0 | 6 | C++ ABI problems | C++ ABI problems | ✓ | ? | ? | ? |
Exported CMake variables
Except for the standard catkin variables (tensorflow_ros_cpp_INCLUDE_DIRS
, tensorflow_ros_cpp_LIBRARIES
, tensorflow_ros_cpp_DEPENDS
and tensorflow_ros_cpp_CATKIN_DEPENDS
), the following variables can be used from packages that find_package
this package:
-
tensorflow_ros_cpp_USES_CXX11_ABI
(bool): Whether the used Tensorflow library is built using C++11 ABI or not. -
tensorflow_ros_cpp_TF_LIBRARY_VERSION
(int): Whether the found library is TF 1 or 2.
Configuration-time CMake variables
These variables are read when configuring the package:
-
TF_LIBRARY_VERSION
(int): Either 1 or 2 depending on whether you want TF 1.x or 2.x. This will not modify the search behavior, but it will check whatever is found, and if it does not satisfy the major version, another search method is tried.
Pip installation
Prerequisites
Assumes tensorflow
or tensorflow-gpu
pip package is installed. Ideally via pip, but custom installs are also supported (if they’re either on PYTHON_PACKAGE_PATH
or if you manually specify environment variable TF_PIP_PATH
).
Install either using rosdep, or by calling
sudo pip install tensorflow
# or
pip install --user tensorflow
# or in a virtualenv
pip install tensorflow
Note
This package uses a “hack” to link against the library that’s installed by pip. I have no idea if this is currently an officially supported way of accessing the C++ API, but it seems to work.
CMake variables:
You can change these variables either in the CMake cache file, or from commandline passing e.g. -DTF_PIP_PATH=/my/path
-
FORCE_TF_PIP_SEARCH:BOOL
(defaultOFF
): Search for the pip-installed Tensorflow even if using a system with C++11 ABI (see below for explanation). -
DISABLE_TF_PIP_SEARCH:BOOL
(defaultOFF
): Do not search for pip-installed Tensorflow at all. -
TF_PYTHON_VERSION:STRING
(default2.7
): The python version used by the Tensorflow installation. -
TF_PYTHON_LIBRARY:STRING
(default""
): If nonempty, specifies path to libpythonx.y.so. Needed in some cases where CMake finds the wrong library, e.g. when using Python 3 pip. -
TF_PIP_EXECUTABLE:STRING
(defaultpip${TF_PYTHON_VERSION}
): Path to thepip
executable that should be used (important to distinguishpip2
for Python 2 andpip3
for Python 3). -
TF_PIP_DISABLE_SEARCH_FOR_GPU_VERSION:BOOL
(defaultOFF
): Only regards thetensorflow
pip package, even if the GPU version is installed. -
TF_PIP_PATH:STRING
(default""
): If the automated search process fails, manually specify path to the folder(site|dist)-packages/tensorflow
containing e.g.python/pywrap_tensorflow.py
.
C++ ABI difference problems
Ubuntu systems starting with 16.04 (Xenial) are using the new C++11 ABI for all system libraries. Until pip bug 1707002 gets resolved (if ever!), the pip-distributed Tensorflow is built againts an older C++ ABI, which is incompatible with the C++11 ABI. This means linking to the Tensorflow library will fail on such systems and there’s no way around it. This only affects TF 1.x, because TF 2.x is always built with C++11 ABI.
The only “workaround” is to wrap all tensorflow code into a library that exposes its functions using C API (so no std::string
s, std::vector
s or Eigen types) and which does not link to any system library with a C++ API.
Such library can then be built separately with -D_GLIBCXX_USE_CXX11_ABI=0
.
Then you can freely link the rest of your code using ROS, Eigen and so on to this library.
An example of this approach can be found at kinetic-devel branch of tensorflow_ros_test.
A library created this way is “backwards compatible” with older systems, so it can be used everywhere.
However, separating all Tensorflow code can be a pain in the ***, so we only suggest it as a last resort option.
This is why searching for the pip-installed Tensorflow is disabled by default on systems using the new C++11 ABI (you can force it using -DFORCE_TF_PIP_SEARCH=ON
).
tensorflow_catkin
installation
Prerequisites
Add package tensorflow_catkin
to your Catkin workspace.
Read its readme to correctly set the required CMake variables (no setup needed for the CPU version).
Be prepared that the compilation will eat up a lot of RAM and take a long time. On my system with 8 concurrent build jobs, it ate around 20 GBs in the peak.
You can add BUILD_COMMAND make -j2
and INSTALL_COMMAND make -j2 install
to its CMakeLists.txt/ExternalProject_Add
to limit the number of concurrent build jobs, which also decreases memory requierements.
CMake variables
-
FORCE_TF_CATKIN_SEARCH:BOOL
(defaultOFF
): Search fortensorflow_catkin
even if Tensorflow has already been found. -
DISABLE_TF_CATKIN_SEARCH:BOOL
(defaultOFF
): Do not search fortensorflow_catkin
at all.
Custom compilation of Tensorflow using Bazel
Prerequisites
Follow the Installing TensorFlow from Sources guide up to “Configure the installation” (including), and build the C++ library with the following command:
bazel build --config=opt --define framework_shared_object=false tensorflow:libtensorflow_cc.so
You don’t need to continue with the guide building or installing the pip package (but you might be interested, because a custom-built tensorflow can provide you with higher performance even in Python).
If you encounter memory problems during the build, you can limit the used resources using the --local_resources
bazel option.
CMake variables
-
FORCE_TF_BAZEL_SEARCH:BOOL
(defaultOFF
): Search for bazel-compiled Tensorflow even if Tensorflow has already been found. -
DISABLE_TF_BAZEL_SEARCH:BOOL
(defaultOFF
): Do not search for bazel-compiled Tensorflow at all. -
TF_BAZEL_LIBRARY:STRING
(default"${CATKIN_DEVEL_PREFIX}/../libtensorflow_cc.so"
): Full path to the buildlibtensorflow_cc.so
library. If you put a symlink in your Catkin workspace root, it will be picked up by the default value. -
TF_BAZEL_SRC_DIR:STRING
(default"${CATKIN_DEVEL_PREFIX}/../tensorflow-include-base"
): Path to the sources folder of Tensorflow (your clone of the Git repository). If you put a symlink namedtensorflow-include-base
in your Catkin workspace root, it will be picked up by the default value. -
TF_BAZEL_USE_SYSTEM_PROTOBUF:BOOl
(defaultOFF
): Whether to use system-installed protobuf includes or those distributed with Tensorflow.
Possible problems
If you encounter crashes when running the TF-using application, or it errors out with Not found: No session factory registered for the given session options
, try the change to tensorflow/BUILD
suggested in https://github.com/tradr-project/tensorflow_ros_cpp/issues/9#issuecomment-604692643, clean the bazel workspace, and build it again.
Tensorflow 1.15+ is not compatible with ROS Indigo. You will get linking errors when using the library. Please use TF 1.14 or older on Indigo.
Changelog for package tensorflow_ros_cpp
3.2.0 (2022-06-08)
- Switch to Github Actions CI
- Noetic and TF2 support
- Removed support for TF 1.15 on Indigo as it is known to have problems and Indigo is EOL.
- Better way of detecting CUDA support in pip-found TF.
- Do not output progressbars of pip in travis, the log gets too long then.
- Added support for TF 1.15.
- Update CI to test TF 1.0, 1.8, 1.14 and latest 1.x (not 2.x as before)
- Added possible problem description derived from #9
- Contributors: Martin Pecka
3.1.2 (2019-08-29)
- Merge branch 'master' of git@github.com:tradr-project/tensorflow_ros_cpp.git # Conflicts: # CHANGELOG.md
- Added support for bazel-based build with framework_shared_object=true.
- 3.1.1
- Changelog
- Contributors: Martin Pecka
3.1.1 (2019-07-17)
- Compatibility with TF 1.14.
- Updated tensorflow_catkin link, removed the rename warning.
- Contributors: Martin Pecka
3.1.0 (2018-06-25 16:55)
- Some more informative CMake messages.
- Export tensorflow_ros_cpp_CMAKE_CXX_FLAGS_PRIVATE.
- Export tensorflow_ros_cpp_USES_CXX11_ABI which tells whether the found TF library uses C++11 ABI or not.
- Contributors: Martin Pecka
3.0.1 (2018-06-25 14:45)
- Leave the tensorflow_catkin dependency in package.xml
- Added repository URLs.
- Removed dependency on swig. It should be handled upstream by tensorflow_catkin.
- Contributors: Isaac I.Y. Saito, Martin Pecka
3.0.0 (2018-06-15)
- Fixed travis badge.
- tensorflow_ros -> tensorflow_ros_cpp
- Create CHANGELOG.md
- Rename CONTRIBUTORS to CONTRIBUTORS.md
- Create CONTRIBUTORS
- Update issue templates
- Added license
- Added travis badge
- Contributors: Martin Pecka
2.1.0 (2018-06-14 11:25:04 +0200)
- Added more tests.
- readme update to clarify the options to install TensorFlow.
- Implemented CI.
- Fixed installation of pip-detected TF libraries.
- Updated compatibility list.
- Contributors: Isaac I.Y. Saito, Martin Pecka
2.0.4 (2018-05-04)
- Fixed bazel TF include dir and GPU version detection
- Updated compatibility list.
- Contributors: Martin Pecka
2.0.3 (2018-05-03)
- Updated compatibility list.
- Few improvements in pip and catkin detection
- Improved bazel detection script
- Tested bazel GPU on Xenial
- Contributors: Martin Pecka
2.0.2 (2018-04-27 22:05)
- Adjusted bazel build to GPU version
- Contributors: Martin Pecka
2.0.1 (2018-04-27 19:49)
- Simplified searching for nsync and Eigen
- Contributors: Martin Pecka
2.0.0 (2018-04-27 17:58)
- Polishing.
- Added Ubuntu Xenial test results.
- Final gomp fix.
- Better documentation, testing for Trusty finished.
- Fail if no search strategy succeeded.
- Added nsync as explicit include dir for tensorflow_catkin (needed in GPU build).
- Added -Wl,--no-as-needed to tensorflow-extras.cmake.in because otherwise it might happen that pywrap_tensorflow_internal is left out from linking because nothing uses its methods, but it contains some important globals.
- Fixed bazel protobuf includes.
- Added support for tensorflow_catkin.
- Fixed CUDA support detection.
- Create symlink also to the library with its original name.
- Fixed pip show output processing.
- Fallback if pip2.7 is not installed and pip2 is.
- Added a warning when different ABIs are detected.
- Fixed search for python libraries.
- Fixed symlinking the bazel library.
- Fixed Eigen dependency.
- Refactored, improved bazel-searching code.
- Refactored, much more fine-grained control over the search process.
- Contributors: Martin Pecka
1.2.1 (2017-11-21)
- Added nsync include dirs in TF 1.4
- Contributors: Martin Pecka
1.2.0 (2017-11-20)
- Added support for tensorflow 1.4
- Added support for tensorflow-gpu
- Making sure Python2 pip is called.
- Fixed support for building with catkin tools.
- Updated for tensorflow 1.1
- Removed setup.py and pointed to the now existing python-tensorflow-pip package.
- pip command fixed
- Changed the way tensorflow is searched for.
- Initial commit.
- Contributors: Martin Pecka
Wiki Tutorials
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged tensorflow_ros_cpp at Robotics Stack Exchange
tensorflow_ros_cpp package from tensorflow_ros_cpp repotensorflow_ros_cpp |
|
Package Summary
Tags | No category tags. |
Version | 3.2.0 |
License | BSD |
Build type | CATKIN |
Use | RECOMMENDED |
Repository Summary
Checkout URI | https://github.com/tradr-project/tensorflow_ros_cpp.git |
VCS Type | git |
VCS Version | master |
Last Updated | 2022-06-08 |
Dev Status | MAINTAINED |
CI status | No Continuous Integration |
Released | UNRELEASED |
Tags | No category tags. |
Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Package Description
Additional Links
Maintainers
- Martin Pecka
Authors
tensorflow_ros_cpp
A Catkin-friendly package for utilizing the C++ API of Tensorflow.
Get Tensorflow C++ API into ROS as easy as
find_package(catkin REQUIRED COMPONENTS
... your other packages ...
tensorflow_ros_cpp
)
See the usage example at [https://github.com/tradr-project/tensorflow_ros_test].
New: Support for Noetic and TensorFlow 2.x!
Supported Tensorflow installations
You can choose either one of the following options to install Tensorflow
.
-
As a pip (Python) package: The easiest way on Ubuntu 14.04 and 20.04, Just
pip install tensorflow
and that’s it. GPU version supported! Can be used on Ubuntu 16.04 and 18.04, too, but with important limitations. -
Using
tensorflow_catkin
package: Easily compile Tensorflow for your platform. A convenient way on newer systems. Supports GPU version. - Using a custom build of Tensorflow built by bazel: The least comfortable, yet most powerful way. Compile Tensorflow yourself using bazel and tell this package where to find it.
See below for more detail about each of the installation types and how to set them up.
Note for rosdep
users
If you’re managing dependencies via rosdep
, it is likely that you do not want it to try to install the optional dependencies (currently python-tensorflow-pip
and tensorflow_catkin
). In such case, add the following to the rosdep call:
rosdep install ... --skip-keys=tensorflow_catkin --skip-keys=python-tensorflow-pip
Tested compatible versions
If you successfully used this package on an untested configuration (marked with ?
), please, tell us.
Ubuntu 14.04 64bits, Python 2.7.6, ROS Indigo
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
0.12.1 | no | no | ✓ | ✓ | ? | ? | N/A | N/A |
1.0.0 | no | no | ✓ | ✓ | ? | ? | N/A | N/A |
1.1.0 | 8 | 5 | ✓ | ✓ | ? | ? | N/A | N/A |
1.2.0 | 8 | 5 | ✓ | ✓ | ? | ? | N/A | N/A |
1.3.0 | 8 | 6 | ✓ | ✓ | ? | ? | N/A | N/A |
1.4.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.5.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.6.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.7.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ✓ | ✓ | ✓ | ✓ |
1.8.0 | 8 | 6 | ✓ | N/A (wants CUDA 9) | ? | ? | N/A | N/A |
1.14.0 | 8 | 6 | ✓ | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
1.15.0 | 8 | 6 | X (link error) | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
Ubuntu 14.04 64bits, Python 3.4, ROS Indigo
Had to set TF_PYTHON_LIBRARY
manually since CMake was only finding Python 2.7 libraries.
TF | CUDA | pip3 tensorflow | pip3 tensorflow-gpu |
---|---|---|---|
1.8.0 | 8 | ✓ | N/A (wants CUDA 9) |
Ubuntu 16.04 64bits, Python 2.7.6, ROS Kinetic
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
0.12.1 | 8.0 | no | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.0.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.1.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.2.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.3.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.4.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.5.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.6.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.7.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ✓ | ✓ | ✓ |
1.8.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ✓ | N/A | N/A |
1.14.0 | 9.0 | 7.0 | ✓, see ABI difference problems | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
1.15.0 | 9.0 | 7.0 | ✓, see ABI difference problems | N/A (wants CUDA 10) | ? | ? | N/A | N/A |
Ubuntu 16.04 64bits, Python 3.5, ROS Kinetic
Had to set TF_PYTHON_LIBRARY
manually since CMake was only finding Python 2.7 libraries.
TF | CUDA | CUDNN | pip3 tensorflow | pip3 tensorflow-gpu |
---|---|---|---|---|
1.8.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems |
Ubuntu 18.04 64bits, Python 2.7.6, ROS Melodic
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
1.0.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.1.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.2.0 | 8.0 | 5.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.3.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.4.0 | 8.0 | 6.0 | ✓, see ABI difference problems | ? | ? | ? | N/A | N/A |
1.5.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.6.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | N/A | N/A |
1.7.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ? | ? | ✓ | ✓ |
1.7.0 | 9.1 | 7.1 | N/A | N/A | ? | ? | ✓ | ✓ |
1.8.0 | 9.0 | 7.1 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ✓ | N/A | N/A |
1.8.0 | 9.1 | 7.1 | N/A | N/A | ✓ | ✓ | N/A | N/A |
1.14.0 | 10.0 | 7.4 | ✓, see ABI difference problems | ✓, see ABI difference problems | ✓ | ? | ? | ? |
1.14.0 | 10.0 | 7.4 | ✓, see ABI difference problems | ? | ? | ? | ? | ? |
Ubuntu 18.04 64bits, Python 3.6, ROS Melodic
Had to set TF_PYTHON_LIBRARY
manually since CMake was only finding Python 2.7 libraries.
TF | CUDA | CUDNN | pip3 tensorflow | pip3 tensorflow-gpu |
---|---|---|---|---|
1.8.0 | 9.0 | 7.0 | ✓, see ABI difference problems | ✓, see ABI difference problems |
1.14.0 | 10.0 | 7.4 | ✓, see ABI difference problems | ✓, see ABI difference problems |
Ubuntu 20.04 64bits, Python 3.8, ROS Noetic
TF | CUDA | CUDNN | pip3 tensorflow | |
---|---|---|---|---|
2.9.1 | no | no | ✓ | ✓ |
Debian Jessie 64bits, Python 2.7.6, ROS Indigo
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
1.3.0 | 8.0 | 6 | ✓ | ✓ | ? | ? | ? | ? |
Debian Stretch 64bits, Python 2.7.6, ROS Indigo (compiled from source)
TF | CUDA | CUDNN | pip tensorflow | pip tensorflow-gpu | bazel (CPU) | bazel (GPU) | tensorflow_catkin (CPU) | tensorflow_catkin (GPU) |
---|---|---|---|---|---|---|---|---|
1.4.0 | 8.0 | 6 | C++ ABI problems | C++ ABI problems | ✓ | ? | ? | ? |
Exported CMake variables
Except for the standard catkin variables (tensorflow_ros_cpp_INCLUDE_DIRS
, tensorflow_ros_cpp_LIBRARIES
, tensorflow_ros_cpp_DEPENDS
and tensorflow_ros_cpp_CATKIN_DEPENDS
), the following variables can be used from packages that find_package
this package:
-
tensorflow_ros_cpp_USES_CXX11_ABI
(bool): Whether the used Tensorflow library is built using C++11 ABI or not. -
tensorflow_ros_cpp_TF_LIBRARY_VERSION
(int): Whether the found library is TF 1 or 2.
Configuration-time CMake variables
These variables are read when configuring the package:
-
TF_LIBRARY_VERSION
(int): Either 1 or 2 depending on whether you want TF 1.x or 2.x. This will not modify the search behavior, but it will check whatever is found, and if it does not satisfy the major version, another search method is tried.
Pip installation
Prerequisites
Assumes tensorflow
or tensorflow-gpu
pip package is installed. Ideally via pip, but custom installs are also supported (if they’re either on PYTHON_PACKAGE_PATH
or if you manually specify environment variable TF_PIP_PATH
).
Install either using rosdep, or by calling
sudo pip install tensorflow
# or
pip install --user tensorflow
# or in a virtualenv
pip install tensorflow
Note
This package uses a “hack” to link against the library that’s installed by pip. I have no idea if this is currently an officially supported way of accessing the C++ API, but it seems to work.
CMake variables:
You can change these variables either in the CMake cache file, or from commandline passing e.g. -DTF_PIP_PATH=/my/path
-
FORCE_TF_PIP_SEARCH:BOOL
(defaultOFF
): Search for the pip-installed Tensorflow even if using a system with C++11 ABI (see below for explanation). -
DISABLE_TF_PIP_SEARCH:BOOL
(defaultOFF
): Do not search for pip-installed Tensorflow at all. -
TF_PYTHON_VERSION:STRING
(default2.7
): The python version used by the Tensorflow installation. -
TF_PYTHON_LIBRARY:STRING
(default""
): If nonempty, specifies path to libpythonx.y.so. Needed in some cases where CMake finds the wrong library, e.g. when using Python 3 pip. -
TF_PIP_EXECUTABLE:STRING
(defaultpip${TF_PYTHON_VERSION}
): Path to thepip
executable that should be used (important to distinguishpip2
for Python 2 andpip3
for Python 3). -
TF_PIP_DISABLE_SEARCH_FOR_GPU_VERSION:BOOL
(defaultOFF
): Only regards thetensorflow
pip package, even if the GPU version is installed. -
TF_PIP_PATH:STRING
(default""
): If the automated search process fails, manually specify path to the folder(site|dist)-packages/tensorflow
containing e.g.python/pywrap_tensorflow.py
.
C++ ABI difference problems
Ubuntu systems starting with 16.04 (Xenial) are using the new C++11 ABI for all system libraries. Until pip bug 1707002 gets resolved (if ever!), the pip-distributed Tensorflow is built againts an older C++ ABI, which is incompatible with the C++11 ABI. This means linking to the Tensorflow library will fail on such systems and there’s no way around it. This only affects TF 1.x, because TF 2.x is always built with C++11 ABI.
The only “workaround” is to wrap all tensorflow code into a library that exposes its functions using C API (so no std::string
s, std::vector
s or Eigen types) and which does not link to any system library with a C++ API.
Such library can then be built separately with -D_GLIBCXX_USE_CXX11_ABI=0
.
Then you can freely link the rest of your code using ROS, Eigen and so on to this library.
An example of this approach can be found at kinetic-devel branch of tensorflow_ros_test.
A library created this way is “backwards compatible” with older systems, so it can be used everywhere.
However, separating all Tensorflow code can be a pain in the ***, so we only suggest it as a last resort option.
This is why searching for the pip-installed Tensorflow is disabled by default on systems using the new C++11 ABI (you can force it using -DFORCE_TF_PIP_SEARCH=ON
).
tensorflow_catkin
installation
Prerequisites
Add package tensorflow_catkin
to your Catkin workspace.
Read its readme to correctly set the required CMake variables (no setup needed for the CPU version).
Be prepared that the compilation will eat up a lot of RAM and take a long time. On my system with 8 concurrent build jobs, it ate around 20 GBs in the peak.
You can add BUILD_COMMAND make -j2
and INSTALL_COMMAND make -j2 install
to its CMakeLists.txt/ExternalProject_Add
to limit the number of concurrent build jobs, which also decreases memory requierements.
CMake variables
-
FORCE_TF_CATKIN_SEARCH:BOOL
(defaultOFF
): Search fortensorflow_catkin
even if Tensorflow has already been found. -
DISABLE_TF_CATKIN_SEARCH:BOOL
(defaultOFF
): Do not search fortensorflow_catkin
at all.
Custom compilation of Tensorflow using Bazel
Prerequisites
Follow the Installing TensorFlow from Sources guide up to “Configure the installation” (including), and build the C++ library with the following command:
bazel build --config=opt --define framework_shared_object=false tensorflow:libtensorflow_cc.so
You don’t need to continue with the guide building or installing the pip package (but you might be interested, because a custom-built tensorflow can provide you with higher performance even in Python).
If you encounter memory problems during the build, you can limit the used resources using the --local_resources
bazel option.
CMake variables
-
FORCE_TF_BAZEL_SEARCH:BOOL
(defaultOFF
): Search for bazel-compiled Tensorflow even if Tensorflow has already been found. -
DISABLE_TF_BAZEL_SEARCH:BOOL
(defaultOFF
): Do not search for bazel-compiled Tensorflow at all. -
TF_BAZEL_LIBRARY:STRING
(default"${CATKIN_DEVEL_PREFIX}/../libtensorflow_cc.so"
): Full path to the buildlibtensorflow_cc.so
library. If you put a symlink in your Catkin workspace root, it will be picked up by the default value. -
TF_BAZEL_SRC_DIR:STRING
(default"${CATKIN_DEVEL_PREFIX}/../tensorflow-include-base"
): Path to the sources folder of Tensorflow (your clone of the Git repository). If you put a symlink namedtensorflow-include-base
in your Catkin workspace root, it will be picked up by the default value. -
TF_BAZEL_USE_SYSTEM_PROTOBUF:BOOl
(defaultOFF
): Whether to use system-installed protobuf includes or those distributed with Tensorflow.
Possible problems
If you encounter crashes when running the TF-using application, or it errors out with Not found: No session factory registered for the given session options
, try the change to tensorflow/BUILD
suggested in https://github.com/tradr-project/tensorflow_ros_cpp/issues/9#issuecomment-604692643, clean the bazel workspace, and build it again.
Tensorflow 1.15+ is not compatible with ROS Indigo. You will get linking errors when using the library. Please use TF 1.14 or older on Indigo.
Changelog for package tensorflow_ros_cpp
3.2.0 (2022-06-08)
- Switch to Github Actions CI
- Noetic and TF2 support
- Removed support for TF 1.15 on Indigo as it is known to have problems and Indigo is EOL.
- Better way of detecting CUDA support in pip-found TF.
- Do not output progressbars of pip in travis, the log gets too long then.
- Added support for TF 1.15.
- Update CI to test TF 1.0, 1.8, 1.14 and latest 1.x (not 2.x as before)
- Added possible problem description derived from #9
- Contributors: Martin Pecka
3.1.2 (2019-08-29)
- Merge branch 'master' of git@github.com:tradr-project/tensorflow_ros_cpp.git # Conflicts: # CHANGELOG.md
- Added support for bazel-based build with framework_shared_object=true.
- 3.1.1
- Changelog
- Contributors: Martin Pecka
3.1.1 (2019-07-17)
- Compatibility with TF 1.14.
- Updated tensorflow_catkin link, removed the rename warning.
- Contributors: Martin Pecka
3.1.0 (2018-06-25 16:55)
- Some more informative CMake messages.
- Export tensorflow_ros_cpp_CMAKE_CXX_FLAGS_PRIVATE.
- Export tensorflow_ros_cpp_USES_CXX11_ABI which tells whether the found TF library uses C++11 ABI or not.
- Contributors: Martin Pecka
3.0.1 (2018-06-25 14:45)
- Leave the tensorflow_catkin dependency in package.xml
- Added repository URLs.
- Removed dependency on swig. It should be handled upstream by tensorflow_catkin.
- Contributors: Isaac I.Y. Saito, Martin Pecka
3.0.0 (2018-06-15)
- Fixed travis badge.
- tensorflow_ros -> tensorflow_ros_cpp
- Create CHANGELOG.md
- Rename CONTRIBUTORS to CONTRIBUTORS.md
- Create CONTRIBUTORS
- Update issue templates
- Added license
- Added travis badge
- Contributors: Martin Pecka
2.1.0 (2018-06-14 11:25:04 +0200)
- Added more tests.
- readme update to clarify the options to install TensorFlow.
- Implemented CI.
- Fixed installation of pip-detected TF libraries.
- Updated compatibility list.
- Contributors: Isaac I.Y. Saito, Martin Pecka
2.0.4 (2018-05-04)
- Fixed bazel TF include dir and GPU version detection
- Updated compatibility list.
- Contributors: Martin Pecka
2.0.3 (2018-05-03)
- Updated compatibility list.
- Few improvements in pip and catkin detection
- Improved bazel detection script
- Tested bazel GPU on Xenial
- Contributors: Martin Pecka
2.0.2 (2018-04-27 22:05)
- Adjusted bazel build to GPU version
- Contributors: Martin Pecka
2.0.1 (2018-04-27 19:49)
- Simplified searching for nsync and Eigen
- Contributors: Martin Pecka
2.0.0 (2018-04-27 17:58)
- Polishing.
- Added Ubuntu Xenial test results.
- Final gomp fix.
- Better documentation, testing for Trusty finished.
- Fail if no search strategy succeeded.
- Added nsync as explicit include dir for tensorflow_catkin (needed in GPU build).
- Added -Wl,--no-as-needed to tensorflow-extras.cmake.in because otherwise it might happen that pywrap_tensorflow_internal is left out from linking because nothing uses its methods, but it contains some important globals.
- Fixed bazel protobuf includes.
- Added support for tensorflow_catkin.
- Fixed CUDA support detection.
- Create symlink also to the library with its original name.
- Fixed pip show output processing.
- Fallback if pip2.7 is not installed and pip2 is.
- Added a warning when different ABIs are detected.
- Fixed search for python libraries.
- Fixed symlinking the bazel library.
- Fixed Eigen dependency.
- Refactored, improved bazel-searching code.
- Refactored, much more fine-grained control over the search process.
- Contributors: Martin Pecka
1.2.1 (2017-11-21)
- Added nsync include dirs in TF 1.4
- Contributors: Martin Pecka
1.2.0 (2017-11-20)
- Added support for tensorflow 1.4
- Added support for tensorflow-gpu
- Making sure Python2 pip is called.
- Fixed support for building with catkin tools.
- Updated for tensorflow 1.1
- Removed setup.py and pointed to the now existing python-tensorflow-pip package.
- pip command fixed
- Changed the way tensorflow is searched for.
- Initial commit.
- Contributors: Martin Pecka