JAX Developers Puzzle deadline approaching: Play for a chance to win a complimentary JAX London 2018 ticket!
Head south to the isle of Java for the winter

How to migrate TensorFlow into Deeplearning4j

Jane Elizabeth
© Shutterstock / Protasov AN

Get your bags packed, it’s time to migrate your machine learning models from TensorFlow into Deeplearning4j. This trip is a lot easier than you’d think, but there are still some pitfalls for the unwary.

Are you looking to migrate your machine learning models from TensorFlow to Deeplearning4j? Not to fear, this migration is significantly easier than you’d think. For one thing, TensorFlow and Deeplearning4j are complementary.

But why would you want to migrate in the first place? TensorFlow is written in a Python API over a C++ engine. While there is a Java API, it’s experimental and not stable enough for production in Java or Scala. It’s not the fastest framework out on the market, and it works best with Google Cloud services.

Deeplearning4j offers a number of advantages for data scientists and developers alike. It’s the open source, deep learning library for the JVM, meaning that it works with all the JVM languages, including Scala, Clojure, and Kotlin. All of its code is freely available and it doesn’t require any heavy lifting from paid products. And, to be frank, it’s faster than TensorFlow.

To start, Deeplearning4j already has a model import function that focuses heavily on machine learning models built with Keras 1, Keras 2, and TensorFlow. So, if you’re a TensorFlow 1.4+ user and you want to deploy your model on a JVM stack, Deeplearning4j has got you covered.

SEE ALSO: Skymind’s Deeplearning4j, the Eclipse Foundation, and scientific computing in the JVM

Additionally, if you are interested, there is a specific project for generating, persisting, and loading TensorFlow graphs for tests – TFOpTests. It’s dead simple to use.

1. Clone the DL4J test resources repos into a folder of your choice:

git clone
cd dl4j-test-resources 

2. Put DL4DL4J_TEST_RESOURCES on your path. (They suggest adding it to your .zshrc or .bashrc)

echo "export DL4J_TEST_RESOURCES=$(pwd)" >> $HOME/.zshrc 

3. Install the library locally and run python develop

And go! It’s that easy.

However, as with much of life, there are some limitations for migrating TensorFlow into Deeplearning4j. Many of the commonly used base operations and high-level layers used in practice are supported. That being said, op coverage is still limited. In the future, Deeplearning4j intends to achieve feature parity soon and fully support import for all TF graphs.

Jane Elizabeth
Jane Elizabeth is an assistant editor for

Leave a Reply

Be the First to Comment!

Notify of