24 breaking releases

0.24.0 Aug 15, 2023
0.23.0 Feb 14, 2023
0.22.1 Sep 6, 2022
0.21.0 Apr 13, 2022
0.4.1 Jul 23, 2016

#936 in Machine learning

Download history 1097/week @ 2024-07-22 1317/week @ 2024-07-29 1044/week @ 2024-08-05 932/week @ 2024-08-12 847/week @ 2024-08-19 946/week @ 2024-08-26 940/week @ 2024-09-02 1057/week @ 2024-09-09 991/week @ 2024-09-16 1319/week @ 2024-09-23 1000/week @ 2024-09-30 772/week @ 2024-10-07 1131/week @ 2024-10-14 1163/week @ 2024-10-21 736/week @ 2024-10-28 748/week @ 2024-11-04

3,806 downloads per month
Used in 20 crates (via tensorflow)

Apache-2.0

94KB
3K SLoC

tensorflow-sys Version

The package provides bindings to TensorFlow.

Requirements

The build prerequisites can be found on the corresponding page of TensorFlow’s documentation. In particular, Bazel, NumPy, and SWIG are assumed to be installed.

GPU Support

To enable GPU support, use the tensorflow_gpu feature in your Cargo.toml:

[dependencies]
tensorflow-sys = { version = "0.24.0", features = ["tensorflow_gpu"] }

Manual TensorFlow Compilation

If you want to work against unreleased/unsupported TensorFlow versions or use a build optimized for your machine, manual compilation is the way to go.

See TensorFlow from source first. The Python/pip steps are not necessary, but building tensorflow:libtensorflow.so is.

In short:

  1. Install SWIG and NumPy. The version from your distro's package manager should be fine for these two.

  2. Install Bazel, which you may need to do from source. You will likely need an up-to-date version.

  3. git clone https://github.com/tensorflow/tensorflow

  4. cd tensorflow

  5. ./configure

  6. bazel build --compilation_mode=opt --copt=-march=native --jobs=1 tensorflow:libtensorflow.so

    Using --jobs=1 is recommended unless you have a lot of RAM, because TensorFlow's build is very memory intensive.

Copy $TENSORFLOW_SRC/bazel-bin/tensorflow/libtensorflow.so and libtensorflow_framework.so to /usr/local/lib. You may need to run ldconfig to reset ld's cache after copying libtensorflow.so.

Generate tensorflow.pc by running the following (where $TENSORFLOW_VERSION is the version number of TensorFlow that you compiled, not the version number of the Rust crate):

$TENSORFLOW_SRC/tensorflow/c/generate-pc.sh --prefix=/usr/local --version=$TENSORFLOW_VERSION

This generates tensorflow.pc in the current folder. Copy this to your PKG_CONFIG_PATH (may be /usr/lib/pkgconfig). To verify that the library is installed correctly, run pkg-config --libs tensorflow.

If you previously compiled this crate, you may need to run cargo clean before the manually compiled library will be picked up.

macOS Note: Via Homebrew, you can just run brew install libtensorflow.

Resources

Dependencies

~0–3MB
~47K SLoC