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:
- TensorFlow core api: the TensorFlow 2.x java binding.
- TensorFlow engine: TensorFlow engine adapter for DJL high level APIs. (NDArray, Model, Predictor, etc)
- TensorFlow model zoo: Includes pre-trained TensorFlow models and built-int translators for direct import and use.
- 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.
You can pull the TensorFlow engine from the central Maven repository by including the following dependency:
- ai.djl.tensorflow:tensorflow-engine:0.9.0
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-engine</artifactId>
<version>0.9.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.
- ai.djl.tensorflow:tensorflow-native-auto:2.3.1
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-native-auto</artifactId>
<version>2.3.1</version>
<scope>runtime</scope>
</dependency>
For macOS, you can use the following library:
- ai.djl.tensorflow:tensorflow-native-cpu:2.3.1:osx-x86_64
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-native-cpu</artifactId>
<classifier>osx-x86_64</classifier>
<version>2.3.1</version>
<scope>runtime</scope>
</dependency>
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:
- ai.djl.tensorflow:tensorflow-native-cu101:2.3.1:linux-x86_64 - CUDA 10.1
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-native-cu101</artifactId>
<classifier>linux-x86_64</classifier>
<version>2.3.1</version>
<scope>runtime</scope>
</dependency>
*Note: If you have gcc version less than 7.0, you will need to upgrade your gcc to gcc7+. you can use the following commands:
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
- ai.djl.tensorflow:tensorflow-native-cpu:2.3.1:linux-x86_64
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-native-cpu</artifactId>
<classifier>linux-x86_64</classifier>
<scope>runtime</scope>
<version>2.3.1</version>
</dependency>
TensorFlow requires Visual C++ Redistributable Packages. If you encounter an UnsatisfiedLinkError while using DJL on Windows, please download and install Visual C++ 2019 Redistributable Packages and reboot.
For the Windows platform, you have to use Automatic package if you want to use GPU.
-
ai.djl.tensorflow:tensorflow-native-auto:2.3.1
This package supports CUDA 10.1 for Windows.
- ai.djl.tensorflow:tensorflow-native-cpu:2.3.1:win-x86_64
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-native-cpu</artifactId>
<classifier>win-x86_64</classifier>
<version>2.3.1</version>
<scope>runtime</scope>
</dependency>