Let's touch on Deep Java Library (DJL), a library that can handle Deep Learning in Java released from AWS.

Overview

03/12/2019 AWS has announced the Deep Java Library for developing and deploying machine learning models in Java.

DJL - Deep Java Library

It's just a little, but I've touched it so I'll introduce it. As for prior knowledge, I usually use Java, but my knowledge of ML / DL is almost zero.

Deep Java Library の発表: Java で機械学習モデルを開発およびデプロイする

here,

Announcing DJL, an open source library for developing deep learning models in Java. DJL provides a user-friendly API for training, testing, and deploying deep learning models. If you are a Java user interested in deep learning, DJL is a great starting point. For Java developers working on deep learning models, DJL makes it easy to train and execute predictions.

So I'm hoping to touch it.

The official page is below, but the Amazon / AWS colors are not very visible. https://djl.ai/

Try

Anyway, let's move it according to the tutorial.

https://github.com/awslabs/djl.git

It seems good to clone from and move the example and below.

#Run in a suitable folder
 git clone https://github.com/awslabs/djl/

After cloning, go to the example folder and take a look at the README.md there.

There are various kinds of examples as below, so let's try the first one first.

image.png

Let's do a Single-shot Object Detection example.

First of all, you are asked to set it up, but since it is only used with Java 11+, environment variables, and IntelliJ as an option, it seems that people who usually do Java can proceed without reading too much.

In this example, we use a pre-prepared ZooModel, hit an image against it to express what animal is reflected in it, and make an image with the recognized part surrounded by a square. It becomes an example.

Suddenly, you can check the operation below. (Quoted from object_detection.md)

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

The following is displayed as the execution result. It will take some time for the first time to download the library, but it will take about 10 seconds after the second time.

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

> Task :run
Loading:     100% |████████████████████████████████████████|
[22:02:10] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.5.0. Attempting to upgrade...
[22:02:10] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded!
[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]
]

BUILD SUCCESSFUL in 11s
3 actionable tasks: 1 executed, 2 up-to-date

The result is that a car, a bicycle and a dog are shown.

Although it will be a retrofit, [ai.djl.examples.inference.ObjectDetection](https://github.com/awslabs/djl/blob/master/examples/src/main/java/ai/djl/examples/inference/ If you look at the ObjectDetection.java) class

Path imageFile = Paths.get("src/test/resources/dog_bike_car.jpg ");

You can see that this image is Input. image.png

After execution, the output image is in build / output / detected-dog_bike_car.png. (Implemented in the same class)

image.png

You can do it properly.

By replacing the Input image, it seems that Object Detection can be performed with another image.

again ai.djl.examples.inference.ObjectDetection If you look at it, you can see that even myself, who only understands Java, is doing something. The logger settings are familiar and give you a sense of familiarity.

I read the general flow as follows.

--Logger settings --Reading the input image --Setting of various parameters to be passed to the model --Pass parameters and images to a pre-prepared model called MxModelZoo (MxNet based model) --Implementation of forecast --Reflect the prediction result on the image --Output the prediction result to the standard output

It's like that. It is necessary to confirm in detail what each parameter means, but I honestly thought that Object Detection using the prepared model is a low hurdle.

Check dependent libraries

The dependent library of the project that included the example looked like the following. There seems to be no duplication with the Spring system, so it seems that it can be used together without conflicts. image.png

Summary

For the time being, I tried only one example using DJL.

I used to think about touching DeepLearning4J, but I was stumbling around the environment construction and shelving it, but this time it was smooth.

All ML / DL systems in Java! I could not reach the feeling, but when using ML / DL for only one function of a general Web system, I thought that it might be good to try using this with a small start. ..

Recommended Posts

Let's touch on Deep Java Library (DJL), a library that can handle Deep Learning in Java released from AWS.
[JavaScript] Java programmers! You can understand JavaScript closures very easily!
Write a class that can be ordered in Java
Problems that can easily be mistaken for Java and JavaScript
Let's touch on Deep Java Library (DJL), a library that can handle Deep Learning in Java released from AWS.
[Deep Learning from scratch] in Java 3. Neural network
Let's touch on Java
Write a class that can be ordered in Java
A library that realizes multi-line strings in Java multiline-string
With [AWS] CodeStar, you can build a Spring (Java) project running on Lambda in just 3 minutes! !!
Deep Learning Java from scratch 6.4 Regularization
I made a class that can use JUMAN and KNP from Java
First steps for deep learning in Java
Deep Learning Java from scratch Chapter 1 Introduction
Deep Learning Java from scratch 6.1 Parameter update
Deep Learning Java from scratch Chapter 2 Perceptron
Deep Learning Java from scratch 6.3 Batch Normalization
[Java] Let's make a DB access library!
Let's create a versatile file storage (?) Operation library by abstracting file storage / acquisition in Java
[Deep Learning from scratch] in Java 1. For the time being, differentiation and partial differentiation