Foojay Today

Quick Start with Machine Learning in Java

October 07, 2020

So you're a Java developer and you want to do some machine learning. Some of the questions that you might be wondering about are—what can machine learning do for me anyway, which library to use, which algorithms, and is there a common standard API?

Since recently there is a standard API that was created to address exactly these questions. Meet JSR 381, a standard Java API for Visual Recognition using machine learning.

VisRec API was designed to be used for machine learning tasks for Java developers with a minimum background in machine learning and to be intuitive for Java developers getting started with machine learning.

Beside basic visual recognition tasks, such as image classification and object detection, it provides support for common machine learning tasks, such as classification and regression.

Since it is an official Java technology standard, multiple implementations are possible and currently there are two available:

Here is an example of Java code based on the VisRec API to build and use a classifier. Without any explanations, it should be clear to you what is happening:

ImageClassifier<BufferedImage> classifier = 
   .networkArchitecture(new File("mnist.json"))
   .modelFile(new File("mnist.dnet"))

BufferedImage image = File(input.getFile()));
Map<String, Float> results = classifier.classify(image);

For detailed step-by-step instructions and examples, see the getting started guide.

Related Articles

View All


  • Avatar photo
    Zoran Sevarac

    Artificial intelligence software developer, entrepreneur, Java Champion, and researcher. Creator of popular and award winning educational Java open source neural network software Neuroph and deep learning platform Deep Netts.

Comments (0)

Your email address will not be published.

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

Save my name, email, and website in this browser for the next time I comment.

Subscribe to foojay updates:
Copied to the clipboard