djl

DJL TensorFlow Engine

This directory contains the Deep Java Library (DJL) EngineProvider for TensorFlow.

It is based off the TensorFlow Deep Learning Framework.

The DJL TensorFlow Engine allows you to run prediction with TensorFlow or Keras models using Java. It has the following 4 modules:

  1. TensorFlow core api: the TensorFlow 2.x java binding.
  2. TensorFlow engine: TensorFlow engine adapter for DJL high level APIs. (NDArray, Model, Predictor, etc)
  3. TensorFlow model zoo: Includes pre-trained TensorFlow models and built-int translators for direct import and use.
  4. TensorFlow native auto: A placeholder to automatically detect your platform and download the correct native TensorFlow libraries for you.

Refer to How to import TensorFlow models for loading TF models in DJL.

Installation

You can pull the TensorFlow engine from the central Maven repository by including the following dependency:

<dependency>
    <groupId>ai.djl.tensorflow</groupId>
    <artifactId>tensorflow-engine</artifactId>
    <version>0.8.0</version>
    <scope>runtime</scope>
</dependency>

Besides the tensorflow-engine library, you may also need to include the TensorFlow native library in your project.

Choose a native library based on your platform and needs:

We offer an automatic option that will download the native libraries into cache folder the first time you run DJL. It will automatically determine the appropriate jars for your system based on the platform and GPU support.

<dependency>
    <groupId>ai.djl.tensorflow</groupId>
    <artifactId>tensorflow-native-auto</artifactId>
    <version>2.3.0</version>
    <scope>runtime</scope>
</dependency>

macOS

For macOS, you can use the following library:

<dependency>
    <groupId>ai.djl.tensorflow</groupId>
    <artifactId>tensorflow-native-cpu</artifactId>
    <classifier>osx-x86_64</classifier>
    <version>2.3.0</version>
    <scope>runtime</scope>
</dependency>

Linux

For the Linux platform, you can choose between CPU, GPU. If you have NVIDIA CUDA installed on your GPU machine, you can use one of the following library:

Linux GPU

<dependency>
    <groupId>ai.djl.tensorflow</groupId>
    <artifactId>tensorflow-native-cu101</artifactId>
    <classifier>linux-x86_64</classifier>
    <version>2.3.0</version>
    <scope>runtime</scope>
</dependency>

*Note: If you have gcc version less than 7.0, you will need to do either one of the following because TensorFlow requires a higher version of libstdc++:

export LD_LIBRARY_PATH=$HOME/.tensorflow/cache/2.3.0-cu101-linux-x86_64/:$LD_LIBRARY_PATH
sudo apt-get update && \
sudo apt-get install -y software-properties-common && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \
sudo apt-get update && \
sudo apt-get install -y gcc-7 g++-7 && \
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 60 && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60

Linux CPU

<dependency>
    <groupId>ai.djl.tensorflow</groupId>
    <artifactId>tensorflow-native-cpu</artifactId>
    <classifier>linux-x86_64</classifier>
    <scope>runtime</scope>
    <version>2.3.0</version>
</dependency>