Skip to content

Latest commit

 

History

History
 
 

examples

DJL - examples

This module contains examples to demonstrate use of the Deep Java Library (DJL).

The following examples are included for training:

The following examples are included for inference:

These examples focus on the overall experience of training and inference. We keep components that are reusable within separate modules for other users to take advantage of in their own applications. For examples and references on creating datasets, look at the basic dataset module. For examples and references on building models and translators, look in our main model zoo.

You may be able to find more translator examples in our engine specific model zoos: mxnet, pytorch, and tensorflow.

More examples and demos of applications featuring DJL are located in our demo repository.

Prerequisites

  • You need to have Java Development Kit version 8 or later installed on your system. For more information, see Setup.
  • You should be familiar with the API documentation in the DJL Javadoc.

Getting started: 30 seconds to run an example

Building with the command line

This example supports building with both Gradle and Maven. To build, use either of the following commands:

  • Gradle build

    cd examples
    ./gradlew jar
  • Maven build

    cd examples
    mvn package -DskipTests

Run example code

With the gradle application plugin you can execute example code directly. For more information on running each example, see the example's documentation.

The following command executes an object detection example:

  • Gradle

    cd examples
    ./gradlew run
  • Maven

    cd examples
    mvn package -DskipTests
    mvn exec:java -Dexec.mainClass="ai.djl.examples.inference.ObjectDetection"

Engine selection

DJL is engine agnostic, so it's capable of supporting different backends.

With MXNet and PyTorch, you can choose different builds of the native library. We recommend the automatic engine selection which downloads the best engine for your platform and available hardware during the first runtime. Activate the automatic selection by adding ai.djl.mxnet:mxnet-native-auto:1.6.0-SNAPSHOT for mxnet and ai.djl.pytorch:pytorch-native-auto:1.4.0-SNAPSHOT as a dependency. You can also see MXNet Engine and PyTorch Engine for further options.