UStackUStack
Deeplearning4j icon

Deeplearning4j

Deeplearning4j is a JVM deep learning suite for Java model training and execution, with Python interop via cpython bindings and runtime support like TensorFlow-Java/ONNX Runtime.

Deeplearning4j

What is Deeplearning4j?

Deeplearning4j is a suite of tools for running deep learning on the JVM. It provides Java-based training and model execution while also supporting interoperability with the Python ecosystem through Python execution via cpython bindings, model import support, and interop with runtimes such as tensorflow-java and onnxruntime.

The project is designed to fit both as a complement to existing Python or C++ workflows and as a standalone option for building and deploying models to environments where JVM-based execution is useful.

Key Features

  • JVM-first deep learning execution: Train and run deep learning models on the JVM as the primary target runtime.
  • Python ecosystem interoperability via cpython bindings: Execute Python components through cpython bindings, enabling integration with parts of the Python workflow.
  • Model import and retraining support: Import and retrain models originating from common Python frameworks such as Pytorch, Tensorflow, and Keras.
  • Graph execution via Samediff: Use Samediff as a lower-level framework for executing complex computation graphs, with it serving as the base API for running ONNX and TensorFlow graphs.
  • ND4J numerical computing for Java: Use Nd4j as a Java-based tensor/numerical library combining numpy-style operations with TensorFlow/PyTorch-style operations.
  • Cross-device C++ math core (Libnd4j): Use Libnd4j, a lightweight standalone C++ library intended to enable math code to run on different devices and be optimized across device types.
  • Production-oriented Python script execution (Python4j): Use Python4j to execute Python scripts in production contexts.
  • Apache Spark integration: Run deep learning pipelines with Apache Spark using the provided integration.
  • Data transformation to tensors (Datavec): Convert raw inputs into tensors suitable for neural network training and execution.

How to Use Deeplearning4j

  1. Start with the site’s Quickstart (recommended by the project) to understand where to begin.
  2. If you hit dependency issues, use the site’s Required Dependencies guide to align your environment.
  3. Choose the component that matches your level of abstraction:
    • Use Deeplearning4j documentation for higher-level APIs such as multi-layer networks and computation graphs.
    • Use Samediff if you want a lower-level, PyTorch/TensorFlow-like workflow with built-in automatic differentiation.
  4. For data preparation and model inputs, consult Datavec documentation.
  5. For deployment or pipeline execution in specific environments, follow the Python4j, Apache Spark, and other integration documentation sections where relevant.

Use Cases

  • Import and retrain models built in Python: Bring models from Pytorch, Tensorflow, or Keras into a JVM workflow, retrain as needed, and continue model development with Deeplearning4j components.
  • Deploy models in JVM microservices: Package trained or imported models for JVM-based services, using Deeplearning4j as the runtime layer for inference or serving logic.
  • Run deep learning pipelines on Apache Spark: Use the Apache Spark integration to execute deep learning pipelines in a Spark environment.
  • Execute or integrate TensorFlow/ONNX graphs: Use Samediff as a graph execution framework and its role as a base API for ONNX and TensorFlow graph execution.
  • Convert raw data to tensors for training: Use Datavec to transform raw inputs into tensor formats suitable for neural network training and execution.

FAQ

Is Deeplearning4j only for Java, or can it work with Python?

Deeplearning4j is a JVM suite, but the project describes interoperability with the Python ecosystem through cpython bindings, model import support, and interoperability with other runtimes such as tensorflow-java and onnxruntime.

Which submodule should I use for lower-level graph work?

The site describes Samediff as a lower-level framework similar in spirit to PyTorch or TensorFlow for building neural networks with built-in automatic differentiation.

What is Nd4j used for?

Nd4j is described as a Java-based “numpy++” library that provides numpy operations as well as operations in the style of TensorFlow/PyTorch.

Does the project support data preprocessing?

Yes. The Datavec submodule is a data transformation library that converts raw input data to tensors suitable for neural network execution.

How does Spark fit into the stack?

The site includes an Apache Spark Integration documentation section, indicating that you can execute deep learning pipelines in Spark using the provided integration.

Alternatives

  • PyTorch / TensorFlow (native Python): If you want a Python-native workflow without JVM-based execution, these frameworks focus on model definition and training in Python.
  • TensorFlow Java or ONNX Runtime (runtime-focused approaches): If your primary goal is running exported models (e.g., TensorFlow or ONNX) rather than a full JVM deep learning workflow, these runtime libraries emphasize execution in their respective ecosystems.
  • General-purpose ML pipelines on Spark (without a specific JVM deep learning suite): You could run preprocessing and distributed processing in Spark and rely on other model execution components, but you would assemble more parts yourself compared with a single integrated stack.
  • NumPy-like Java tensor libraries (without the full deep learning stack): For tensor math only, alternatives may cover numerical operations, but they won’t necessarily include the deep learning graph, data transformation, and interoperability pieces described here.