paint-brush
DJL: Deep Java Library and How To Get Startedby@dhruveshpatel
1,830 reads
1,830 reads

DJL: Deep Java Library and How To Get Started

by Dhruvesh Patel
Dhruvesh Patel HackerNoon profile picture

Dhruvesh Patel

@dhruveshpatel

A seasoned Cloud Solution Architect and hands-on Cloud-native backend developer

October 25th, 2020
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

DJL: Deep Java Library is an open-source library to build and deploy deep learning models in Java. DJL is built by AWS and is open source. It provides a native Java library & expedite machine learning and deep learning journey. Developers can use their existing Eclipse/ IntelliJ to build, train and deploy models and DJL makes it easy to integrate these models with Java Apps. We will learn how to implement inference code with a ModelZoo model to detect dogs in an image.

Company Mentioned

Mention Thumbnail
Few
featured image - DJL: Deep Java Library and How To Get Started
1x
Read by Dr. One voice-avatar

Listen to this story

Dhruvesh Patel HackerNoon profile picture
Dhruvesh Patel

Dhruvesh Patel

@dhruveshpatel

A seasoned Cloud Solution Architect and hands-on Cloud-native backend developer

Learn More
LEARN MORE ABOUT @DHRUVESHPATEL'S
EXPERTISE AND PLACE ON THE INTERNET.

Want to get your hands dirty with Machine Learning / Deep Learning, but have a Java background and not sure where to start? Then read on! This article is about using an 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 these 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". A developer can develop a 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 here.

Local Software Setup

  1. Install JDK 8 (DJL has some known issues with JDK 11)
  2. Install IntelliJ a IDE
  3. Import DJL project using IntelliJ

For more details: https://docs.djl.ai/docs/development/setup.html

For Java source code for ObjectDetection.java class, which is using DJL can be found here.

Run the Object Detection Example:

Input image is used as below:

image

Build the project and run

Use the following command to run the project:

cd examples
./gradlew run -Dmain=ai.djl.examples.inference.ObjectDetection

Output should look like the following:

[INFO ] - Detected objects image has been saved in: build/output/detected-dog_bike_car.png
[INFO ] - [
          	class: "car", probability: 0.99991, bounds: [x=0.611, y=0.137, width=0.293, height=0.160]
          	class: "bicycle", probability: 0.95385, bounds: [x=0.162, y=0.207, width=0.594, height=0.588]
          	class: "dog", probability: 0.93752, bounds: [x=0.168, y=0.350, width=0.274, height=0.593]
          ]

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

image

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 very few sources for Java. Thanks to the AWS team, DJL provides open-source tools to train and serve Deep learning models in Java and make it easy to start your deep learning journey.

Happy coding!

Please like, share and comment with your views/opinions.

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

L O A D I N G
. . . comments & more!

About Author

Dhruvesh Patel HackerNoon profile picture
Dhruvesh Patel@dhruveshpatel
A seasoned Cloud Solution Architect and hands-on Cloud-native backend developer

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Viblo
2kvn
Coffee-web
Hashnode
X REMOVE AD