DJL - Deep Java Library 
Tags: opensource, java, machinelearning
Published: 2020-10-24 03:41:41

Want to get hands dirty with Machine Learning / Deep Learning, but have got Java background and do not know where to start? Then read on, this post is about using existing Java skillset and ramp-up your journey to start building deep learning models. 

**What is DJL?**

DJL is an open source library to build and deploy deep learning in Java. DJL is built by AWS and is open source. 

DJL provides a native Java development experience and functions like any other regular Java library & expedite machine learning and deep learning journey. Developers can use their existing IDE (Eclipse/ IntelliJ) to build, train and deploy models and DJL makes it easy to integrate this models with Java Apps. 

The simple APIs abstract away the complexity involved in developing Deep learning models. With the bundled set of pre-trained models from ModelZoo, users can immediately start integrating Deep learning into their Java applications. 

DJL is engine-agnostic and goes with Java fundamental "Write once, run anywhere". Developer can develop model using DJL and run it on an engine of your choice - MXNet, Pytorch, TensorFlow. 

**DJL Example for Object Detection**

Object detection is a computer vision technique for locating instances of objects in images or videos.

In this example, we will learn how to implement inference code with a ModelZoo model to detect dogs in an image. Source code for this model is available [here](https://github.com/awslabs/djl/blob/master/docs/model-zoo.md).

**Local software setup**

* Install JDK 8 (DJL has some known issues with JDK 11)
* Install IntelliJ a IDE
* Import DJL project using IntelliJ

Refer setup related more details [here](https://docs.djl.ai/docs/development/setup.html).

For Java source code for ObjectDetection.java class, which is using DJL can be found [here] (https://github.com/awslabs/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/ObjectDetection.java).

**Run the Object Detection Example:**

* Input image is used as below. 

![DJL - Input Image](https://dev-to-uploads.s3.amazonaws.com/i/rmdx0z3wc7xb9xbxy3tq.JPG)

* Build the project and run
Use the following command to run the project:

![Build project](https://dev-to-uploads.s3.amazonaws.com/i/inet8va1jad80i8hf4lt.JPG)

* Output should look like the following:

![DJL Output](https://dev-to-uploads.s3.amazonaws.com/i/pna0nyp0nfrqzllmsbty.JPG)

An output image with bounding box will be saved as build/output/detected-dog_bike_car.png:

![DJL - Output](https://dev-to-uploads.s3.amazonaws.com/i/h4tvh26sqrtv00yha10o.JPG)

**Conclusion**

Within Deep learning landscape, there are lots of resources for Python users like NumPy for data analysis or frameworks such as MXNet, TensorFlow. But, the very few sources for Java. Thanks to AWS team, DJL provides open source tools to train and serve Deep learning models in Java and makes it easy to start deep learning journey. 

Enjoy building machine learning applications with power of DJL ! 

Please like, share and comment your views/ opinion.

Disclaimer - This post is my personal opinion and does not reflect those of any of my past, present or future employers or affiliations.