"Fossies" - the Fresh Open Source Software Archive

Member "tensorflow-2.9.1/tensorflow/java/README.md" (22 May 2022, 3791 Bytes) of package /linux/misc/tensorflow-2.9.1.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field. See also the last Fossies "Diffs" side-by-side code changes report for "README.md": 2.6.2_vs_2.8.0.

TensorFlow for Java

WARNING: The TensorFlow Java API is not currently covered by the TensorFlow API stability guarantees.

For using TensorFlow on Android refer instead to TensorFlow Lite.


Nightly builds

Releases built from release branches are available on Maven Central. Additionally, every day binaries are built from the master branch on GitHub:

Building from source

If the quickstart instructions above do not work out, the TensorFlow Java and native libraries will need to be built from source.

  1. Install bazel

  2. Setup the environment to build TensorFlow from source code (Linux or macOS). If you'd like to skip reading those details and do not care about GPU support, try the following:

    # On Linux
    sudo apt-get install python swig python-numpy
    # On Mac OS X with homebrew
    brew install swig
  3. Configure (e.g., enable GPU support) and build:

    bazel build --config opt \
      //tensorflow/java:tensorflow \

The command above will produce two files in the bazel-bin/tensorflow/java directory:

To compile Java code that uses the TensorFlow Java API, include libtensorflow.jar in the classpath. For example:

javac -cp bazel-bin/tensorflow/java/libtensorflow.jar ...

To execute the compiled program, include libtensorflow.jar in the classpath and the native library in the library path. For example:

java -cp bazel-bin/tensorflow/java/libtensorflow.jar \
  -Djava.library.path=bazel-bin/tensorflow/java \

Installation on Windows requires the more experimental bazel on Windows. Details are omitted here, but find inspiration in the script used for building the release archive: tensorflow/tools/ci_build/windows/libtensorflow_cpu.sh.


If your project uses bazel for builds, add a dependency on //tensorflow/java:tensorflow to the java_binary or java_library rule. For example:

bazel run -c opt //tensorflow/java/src/main/java/org/tensorflow/examples:label_image