Java AI libraries with Gluon Mobile


One of the advantages of Java is the huge ecosystem. Many Java developers, both individuals as well as large companies and anything in between, create and maintain Java libraries and frameworks that complement the Java core platform. Thanks to the cross-platform nature of Java, these libraries are typically very portable. Because Gluon has enabled Java 8 through to Java 15 to run on mobile thanks to Gluon Mobile, there exists an absolute abundance of Java libraries for developing mobile applications in Java – because it’s the exact same libraries used for standard Java development!

Today we wanted to cover off a fascinating area of development: Artificial Intelligence (AI). Fortunately for Java developers, there are a number of interesting Java libraries related to AI. One of those is Eclipse DeepLearning4J which builds on top of ND4J, which provides numerical algorithms for Java, implemented on top of native low-level, high performant algebraic libraries. This project leverages JavaCPP, which makes it easier to bridge the gap between Java code and existing C++ libraries.

The fact that developers can use JavaCPP, ND4J and DL4J on client devices (mobile and embedded) opens a huge array of possibilities. One of the screenshots below shows a simple JavaFX application that renders a chart displaying the required time to compute matrix multiplications with an increasing number of elements.

Earlier this week, Oracle released Tribuo, a machine learning library written in Java. We looked at its sample code and decided to give it a try on mobile devices. In just a few hours, we created a simple sample application that reads a data set, trains a model, and evaluates that model. All of this is done on the client, regardless of whether it is a desktop, a laptop, a mobile device, or an embedded device. The screenshot below shows the sample application running on an iPhone, showing the 3 possible outcomes, and for each outcome the number of correct predictions (TP) as well as the wrong predictions (FP) are shown.

The potential for machine learning on mobile is huge. By doing parts of the training on the client, the need for sending private data to a server is massively reduced. With the increased attention in the world today around user privacy, this is a huge advantage. Thanks to Java libraries, it is very easy to do this in Java on desktop, but also on mobile and embedded devices. The Gluon Mobile product, which includes the Gluon Substrate tooling, makes this very trivial.