Deep Java Library (DJL) Documentation

repository·master·Indexed 26 days ago

https://github.com/deepjavalibrary/djl

An open-source, high-level, engine-agnostic Java framework for deep learning that enables Java developers to build, train, and deploy machine learning models. It includes a core API for inference, training, and neural network operations, as well as specialized modules such as DJL Android for mobile inference (supporting PyTorch and ONNXRuntime), DJL Zero for simplified deep learning tasks, and djl_spark for Spark support.

Tokens
54.8K
Snippets
149
Records
313
Agent score
89%

What's inside Deep Java Library (DJL)

  1. Overview of DJL Timeseries Package

    master

    The DJL timeseries package is designed for Java developers to perform time series forecasting using deep learning engines like PyTorch, MXNet, and TensorFlow. It provides two primary capabilities:

    1. GluonTS Integration: Allows direct loading of pretrained models from the gluonTS Python package (built with MXNet or PyTorch) into a Java environment for inference and deployment. Parameter naming conventions are kept consistent with gluonTS.
    2. Native Training: Enables users to build, modify, and train time series deep learning models directly within the Java environment using DJL.
  2. Overview of DJL Core API Packages

    master

    The DJL core API is organized into several functional packages:

    • engine: Classes for loading deep learning engines.
    • inference: Classes for implementing inference tasks.
    • metric: Classes for collecting metrics information.
    • modality: Utility classes for predefined modalities.
    • ndarray: Classes and interfaces for n-dimensional arrays.
    • nn: Classes for defining neural network operations.
    • training: Classes for implementing training tasks.
    • translate: Interfaces and classes for translating between Java objects and NDArrays.
  3. Overview of fastText NLP support in DJL

    master

    The fastText module provides NLP capabilities within DJL. Note the following architectural details and limitations:

    • Not a standard Engine: Unlike other DJL engines, this implementation does not support the standard Trainer and Predictor interfaces.
    • Training: Training is performed exclusively using the TrainFastText class. This produces a special block capable of standalone inference or inference via a model and predictor.
    • Inference: Pre-trained FastText models can be loaded using standard DJL Criteria.
    • Dataset Requirement: Training datasets must strictly comply with the fastText format.
    • Model Compatibility: Saved models are fastText-specific and can only be loaded using this module.
  4. Explore PyTorch Engine Modules

    master

    The PyTorch engine implementation is divided into several specialized modules:

    • PyTorch Engine: The core DJL implementation for the PyTorch Engine.
    • PyTorch Model Zoo: A collection of pre-exported models from PyTorch ready for use.
    • Pytorch native library: A utility module used for building pytorch-native JARs that contain the necessary native binaries.
  5. Understand the DJL Model Zoo concept

    master

    The DJL Model Zoo acts as a bridge between model vendors and consumers. A ZooModel is a standardized unit that is:

    • Globally unique: Identified by a unique group ID and artifact ID (similar to Maven packages).
    • Versioned: Supports versioning schemes to allow updates without breaking backward compatibility.
    • Ready to use out of the box: Includes predefined pre-processing and post-processing logic, allowing users to perform inference using plain Java objects.
    • Portable: Can be published to various locations including S3 buckets, web servers, or local folders.
  6. Understand DJL Engines and Architecture

    master

    DJL is built on a tree of interfaces (including NDArray, NDManager, and Model) where the root is the Engine class. Implementations are provided by specific engines via a Java service loader. This architecture allows DJL to leverage hardware-specific optimizations from various backends and enables switching between engines by simply changing dependencies.

    Because DJL uses the same engines that Python-based training frameworks use, you can import models trained in Python and run them in Java without loss of performance or accuracy.

  7. DJL Android Module Overview

    master

    DJL Android provides inference capabilities on Android devices through several specialized modules:

    • Core package (ai.djl.android:core): Contains image processing toolkits for Android users.
    • PyTorch Native (ai.djl.android:pytorch-native): The DJL PyTorch Android native package.
    • ONNXRuntime (ai.djl.android:onnxruntime): The DJL ONNXRuntime Android package.
  8. Load models from the ModelZoo repository

    master

    DJL can automatically locate and load models from built-in ModelZoos available on the classpath. This allows for version management without code changes.

    Built-in ModelZoos include:

    • ai.djl:model-zoo: Engine-agnostic imperative model zoo
    • ai.djl.mxnet:mxnet-model-zoo: MXNet symbolic model zoo
    • ai.djl.pytorch:pytorch-model-zoo: PyTorch torch script model zoo
    • ai.djl.tensorflow:tensorflow-model-zoo: TensorFlow saved bundle model zoo
  9. Use the Apache MXNet Engine with DJL

    master

    The Apache MXNet Engine provides a Deep Java Library (DJL) EngineProvider for the Apache MXNet deep learning framework. It allows developers to run MXNet models within Java applications using the DJL API.

    Key components include:

    • MXNet Engine: The core DJL implementation for Apache MXNet.
    • MXNet Model Zoo: A collection of pre-trained models exported from Apache MXNet that are compatible with DJL.