Table Of Contents


Built with 🛠 MkDocs - Theme 🖤 Github.

JSR 381 and Deep Netts

JSR 381, also known as the Visual Recognition or VisRec specification, defines a standard Java API for building Machine Learning and visual-recognition applications. Deep Netts provides the concrete neural-network functionality used to load data, train models, evaluate them, and make predictions.

The useful distinction is the same one Java developers encounter in APIs such as JDBC: an application can program against shared contracts, while a provider supplies working classes behind those contracts.

At a glance

Standard JSR 381: Visual Recognition (VisRec)
API package javax.visrec
Contracts DataSet, Classifier, Regressor, ImageClassifier, evaluation types and SPI services
Implementation layer VisRec Reference Implementation or another compatible provider
ML engine used here Deep Netts
Final release JSR 381 1.0

Specification, implementation, and engine

These layers have different responsibilities:

Java application
      |
      v
JSR 381 / javax.visrec contracts
      |
      v
VisRec implementation or adapter
      |
      v
Deep Netts neural-network engine

JSR 381 reached Final Release in February 2022. The official JCP page links the specification, Reference Implementation, and TCK: JSR 381 Final Release.

Important interfaces

The API contains small contracts that describe common Machine Learning operations:

import javax.visrec.ml.classification.Classifier;
import javax.visrec.ml.classification.ImageClassifier;
import javax.visrec.ml.data.DataSet;
import javax.visrec.ml.regression.Regressor;

Classifier<Input, Result> classifier;
ImageClassifier<Image> imageClassifier;
Regressor<Input, Number> regressor;
DataSet<Sample> dataSet;

Conceptually:

The complete list of API types is available in the VisRec API Javadoc.

Where Deep Netts fits

Deep Netts 4 exposes its own concrete model API while interoperating with standard VisRec types where they are useful. For example, the cookbook loads a Deep Netts TabularDataSet, then stores the training and test partitions through the JSR 381 DataSet interface:

import deepnetts.data.MLDataItem;
import deepnetts.data.TabularDataSet;
import deepnetts.data.TrainTestSplit;
import javax.visrec.ml.data.DataSet;

TabularDataSet<MLDataItem> dataSet = loadDataSet();
TrainTestSplit split = dataSet.trainTestSplit(0.8);

DataSet<MLDataItem> trainingSet = split.getTrainingSet();
DataSet<MLDataItem> testSet = split.getTestSet();

TabularDataSet extends the VisRec BasicDataSet implementation, so the Deep Netts dataset can be used through the standard DataSet contract. A Deep Netts network then accepts that dataset directly:

FeedForwardNetwork neuralNet = FeedForwardNetwork.builder()
        .addInputLayer(numInputs)
        .addFullyConnectedLayer(16, ActivationType.RELU)
        .addOutputLayer(numOutputs, ActivationType.SIGMOID)
        .build();

neuralNet.train(trainingSet);
EvaluationMetrics metrics = neuralNet.test(testSet);

This is the practical relationship used in the current examples: standard types provide familiar Java contracts, while Deep Netts provides the actual model construction and execution.

Do not confuse API with implementation

Adding visrec-api gives a project the JSR 381 interfaces and shared types. Interfaces alone do not train a neural network. The application also needs a compatible implementation and Machine Learning engine, such as the Deep Netts-based stack.

Why this matters

Continue with Loading Data to see these types in a working Deep Netts workflow, or review the public JSR 381 API repository and Reference Implementation.

No. It defines standard Java contracts and service-provider interfaces; a concrete implementation and Machine Learning engine perform the actual work.

The examples commonly use javax.visrec.ml.data.DataSet as the shared contract for training and test samples.

Was this helpful?