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 = NeuralNetImageClassifier.builder() .inputClass(BufferedImage.class) .imageHeight(28) .imageWidth(28) .labelsFile(dataSet.getLabelsFile()) .trainingFile(dataSet.getTrainingFile()) .networkArchitecture(new File("mnist.json")) .modelFile(new File("mnist.dnet")) .maxError(1.4f) .maxEpochs(100) .learningRate(0.01f) .build(); BufferedImage image = ImageIO.read(new File(input.getFile())); Map<String, Float> results = classifier.classify(image);
For detailed step-by-step instructions and examples, see the getting started guide.