SlideShare a Scribd company logo
JSR 381
Visual Recognition for Java
Finally,
A Java-Friendly ML API
Gran Sasso
Frank Greco
@frankgreco
Chair
NYJavaSIG - NY Java User Group
JC, Cloud/Mobile Architect
Zoran Severac
@neuroph
AI Researcher
Univ of Belgrade, Serbia
JC, Apache NetBeans PMC
NullPointerExceptional
Session Topics
● Patterns and Machine Learning (ML)
● Why is ML Different than Conventional Programming
● Java and ML
● VisRec JSR 381
● VisRec Architecture and Implementation
● Examples
Patterns
And
Machine Learning
Machine Learning - Huge Impact on Everything...
Patterns...
jChampions   JSR381 Visual recognition for java
“One of the most interesting aspects of
the world is that it can be considered to
be made up of patterns”
Norbert Wiener - 1894-1964 - MIT
Cybernetics (1948) - early steps to modern AI
This was AI before it was called “AI”
jChampions   JSR381 Visual recognition for java
https://en.wikipedia.org/wiki/Christopher_Alexander
Learning a Foreign Language
Understand All Rules Observe/Follow Patterns
Where Else Does This Apply?
Where Else Does This Apply?
Any application that has a
large number of parameters
and lots of data
Weather
Trading
Cybersecurity
Medical
Diagnosis
Drug Discovery
Anti Spam
Agriculture
Ecommerce
Language
Translation
Autonomous
Transportation
Online Search
Call Centers
Social Media
Monitoring
Session Topics
● Patterns and Machine Learning (ML)
● Why is ML Different than Conventional Programming
● Java and ML
● VisRec JSR 381
● VisRec Architecture and Implementation
● Examples
T F
T F
T F
T F
FT FT
FT
FT
FT
T
F
jChampions   JSR381 Visual recognition for java
jChampions   JSR381 Visual recognition for java
jChampions   JSR381 Visual recognition for java
ML - Basic Workflow
Obtaining, Organizing,
Cleaning, Removing Bias,
etc.
Selecting ML Algorithm, Parameter
Experimentation, Analyze Errors
Deploy Model
with jar/container
ML - Basic Workflow
Obtaining, Organizing,
Cleaning, Removing Bias,
etc.
Selecting ML Algorithm, Parameter
Experimentation, Analyze Errors
Deploy Model
with jar/container
ML - Basic Workflow
Obtaining, Organizing,
Cleaning, Removing Bias,
etc.
Selecting ML Algorithm, Parameter
Experimentation, Analyze Errors
Deploy Model
with jar/container
Session Topics
● Patterns and Machine Learning (ML)
● Why is ML Different than Conventional Programming
● Java and ML
● VisRec JSR 381
● VisRec Architecture and Implementation
● Examples
You can write your Machine
Learning app in any language
you want as long as its Python.
You can write your Machine
Learning app in any language
you want as long as its Python.
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
What the Hey!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
HEY!
12M Java Devs
Java Needs to be a First Class Citizen for ML
● Don’t want another JavaScript “Doomsday” Scenario occurring in
our Lifetime
● Python is a very good language. There should be others to
express the ML world’s creativity
● Java is a great language with a huge ecosystem with 12M
developers
● Existing ML APIs aren’t Java-friendly or AppDev-friendly
Everyone we talked was interested to collaborate
Session Topics
● Patterns and Machine Learning (ML)
● Why is ML Different than Conventional Programming
● Java and ML
● VisRec JSR 381
● VisRec Architecture and Implementation
● Examples
Don’t boil the ocean… [heat up some coffee first]
VisRec - JSR #381 Visual Recognition for Java
Spec Leads and Expert Group
Zoran Sevarac (ML researcher - Univ of Belgrade)
Frank Greco (NYJavaSIG, Consultant)
Kevin Berendsen (OpenValue, Senior Software Eng)
Other contributors and Advisors
● Frank Liu (Amazon)
● Constantin Drabo
● Amit Nagesh
● Marissa Staller
● Eric Bruno
● Anakar Parida
● Nikita Ivanov (Gridgain)
● James Weaver (IBM)
● Werner Keil
● Jyoti Buddha
● Guillaume Laforge (Google)
● Ed Burns (fmr Oracle)
● Nishant Raut (Mumbai JUG)
● Sandhya Kapoor (fmr IBM)
JSR 381 API,
Architecture, Implementations,
and Examples
JSR #381 - Visual Recognition API
���
●
●
●
●
● More readable and easier to use
VisRec JSR #381
https://github.com/JavaVisRec/visrec-api/wiki/Getting-Started-Guide
Issues with Existing Offerings
●
●
●
●
VisRec Design goals and principles
●
●
●
●
What Can you Do with It?
1) Classify images and data/objects
classification task
2) Estimate numeric value
regression task
3) Object Detection
classification + regression(position)
Generic ML Layer
Visual
Recognition
Image
Abstraction
VisRec Public API
Apps/Libs
Visual Recognition Layer
JSR381
Service Provider Interface
ML Engine 1
Service Provider Impl
ML Engine 2
Service Provider Impl
JSR 381
Architecture
Core Classes & Design
Generic ML Layer
(common abstractions,
interfaces for general ML
tasks)
Visual Rec Layer
(specialization of generic ML tasks for
specific objects / domain)
Implementation
Based on specific ML engine
DataSet<E> ImageSet extends
DataSet<ExampleImage>
Classifier<T, R>
BinaryClassifier<T>
MutliClassClassifier<T, R>
ImageClassifier<IMAGE_CLASS>
AbstractImageClassifier<IMAGE_CLASS
, MODEL> implements
ImageClassifier<IMAGE_CLASS>
ImageClassifierNetwork extends
AbstractImageClassifier<BufferedImage,
ConvolutionalNetwork>
Regressor<T, R>
SimpleLinearRegression<
MODEL_CLASS>
implements
Regressor<Float, Float>,
SimpleLinearRegressionNetwork extends
SimpleLinearRegression<FeedForwardN
etwork>
How to classify image
Build Classifier
ImageClassifier<BufferedImage> dukeClassifier =
NeuralNetImageClassifier.builder()
.inputClass(BufferedImage.class)
.imageHeight(64)
.imageWidth(64)
.labelsFile(new File("labels.txt"))
.trainingFile(new File("index.txt"))
.networkArchitecture(new File("duke_net.json"))
.exportModel(Paths.get("duke.dnet"))
.maxError(0.05f)
.maxEpochs(1000)
.learningRate(0.01f)
.build()
Use Classifier
BufferedImage image = ...
Map<String, Float> results = classifier.classify(image);
Full Example on GitHub
Running the Demo
Epoch:1, Time:686ms, TrainError:0.68538016, TrainErrorChange:0.68538016, TrainAccuracy: 0.91150445
Epoch:2, Time:505ms, TrainError:0.4474997, TrainErrorChange:-0.23788047, TrainAccuracy: 0.96460176
Epoch:3, Time:506ms, TrainError:0.28403035, TrainErrorChange:-0.16346934, TrainAccuracy: 0.96460176
Epoch:4, Time:479ms, TrainError:0.1824384, TrainErrorChange:-0.101591945, TrainAccuracy: 0.9734513
Epoch:5, Time:486ms, TrainError:0.123548426, TrainErrorChange:-0.058889978, TrainAccuracy: 0.99115044
Epoch:6, Time:493ms, TrainError:0.08493269, TrainErrorChange:-0.038615733, TrainAccuracy: 1.0
Minimal Configuration
● Image class
● Image dimensions
● Category labels (labels file)
● List of image files with corresponding category labels (index
file)
● Convolutional neural network architecture for image
classification
● Training parameters (max error, max epochs, learning rate)
● File name for the trained model
Under the hood: Convolutional Neural Network for Image Recognition
High dimensional data + automated preprocessing and feature extraction
Reference Implementation: Deep Netts
● Pure Java implementation of main Deep Learning algorithms:
convolutional and feed forward neural networks
● Open source (LGPL) and professional edition
● Pro Edition includes Deep Learning IDE
○ Visual ML Tools, Wizards and
● Starting today Pro Edition is available
Under FREE DEVELOPMENT license!
https://www.deepnetts.com/download
Image classification - Convolutional network using Deep Netts API
ConvolutionalNetwork neuralNet = ConvolutionalNetwork.builder()
.addInputLayer(imageWidth, imageHeight, 3)
.addConvolutionalLayer(3, 3, 12)
.addMaxPoolingLayer(2, 2)
.addFullyConnectedLayer(30)
.addFullyConnectedLayer(20)
.addOutputLayer(labelsCount, ActivationType.SOFTMAX)
.hiddenActivationFunction(ActivationType.TANH)
.lossFunction(LossType.CROSS_ENTROPY)
.randomSeed(123)
.build();
jChampions   JSR381 Visual recognition for java
Next Steps for You!
github.com/JavaVisRec/visrec-api/wiki/Getting-Started-Guide
JSR 381
Visual Recognition for Java
Finally,
A Java-Friendly ML API
Please provide feedback
and contribute!
No reason why Java
cannot be used for ML!
Thank You!

More Related Content

jChampions JSR381 Visual recognition for java

  • 1. JSR 381 Visual Recognition for Java Finally, A Java-Friendly ML API Gran Sasso
  • 2. Frank Greco @frankgreco Chair NYJavaSIG - NY Java User Group JC, Cloud/Mobile Architect Zoran Severac @neuroph AI Researcher Univ of Belgrade, Serbia JC, Apache NetBeans PMC NullPointerExceptional
  • 3. Session Topics ● Patterns and Machine Learning (ML) ● Why is ML Different than Conventional Programming ● Java and ML ● VisRec JSR 381 ● VisRec Architecture and Implementation ● Examples
  • 5. Machine Learning - Huge Impact on Everything...
  • 8. “One of the most interesting aspects of the world is that it can be considered to be made up of patterns” Norbert Wiener - 1894-1964 - MIT Cybernetics (1948) - early steps to modern AI This was AI before it was called “AI”
  • 11. Learning a Foreign Language Understand All Rules Observe/Follow Patterns
  • 12. Where Else Does This Apply?
  • 13. Where Else Does This Apply? Any application that has a large number of parameters and lots of data
  • 16. Session Topics ● Patterns and Machine Learning (ML) ● Why is ML Different than Conventional Programming ● Java and ML ● VisRec JSR 381 ● VisRec Architecture and Implementation ● Examples
  • 17. T F T F T F T F FT FT FT FT FT T F
  • 21. ML - Basic Workflow Obtaining, Organizing, Cleaning, Removing Bias, etc. Selecting ML Algorithm, Parameter Experimentation, Analyze Errors Deploy Model with jar/container
  • 22. ML - Basic Workflow Obtaining, Organizing, Cleaning, Removing Bias, etc. Selecting ML Algorithm, Parameter Experimentation, Analyze Errors Deploy Model with jar/container
  • 23. ML - Basic Workflow Obtaining, Organizing, Cleaning, Removing Bias, etc. Selecting ML Algorithm, Parameter Experimentation, Analyze Errors Deploy Model with jar/container
  • 24. Session Topics ● Patterns and Machine Learning (ML) ● Why is ML Different than Conventional Programming ● Java and ML ● VisRec JSR 381 ● VisRec Architecture and Implementation ● Examples
  • 25. You can write your Machine Learning app in any language you want as long as its Python.
  • 26. You can write your Machine Learning app in any language you want as long as its Python. HEY!
  • 28. Java Needs to be a First Class Citizen for ML ● Don’t want another JavaScript “Doomsday” Scenario occurring in our Lifetime ● Python is a very good language. There should be others to express the ML world’s creativity ● Java is a great language with a huge ecosystem with 12M developers ● Existing ML APIs aren’t Java-friendly or AppDev-friendly
  • 29. Everyone we talked was interested to collaborate
  • 30. Session Topics ● Patterns and Machine Learning (ML) ● Why is ML Different than Conventional Programming ● Java and ML ● VisRec JSR 381 ● VisRec Architecture and Implementation ● Examples
  • 31. Don’t boil the ocean… [heat up some coffee first] VisRec - JSR #381 Visual Recognition for Java Spec Leads and Expert Group Zoran Sevarac (ML researcher - Univ of Belgrade) Frank Greco (NYJavaSIG, Consultant) Kevin Berendsen (OpenValue, Senior Software Eng)
  • 32. Other contributors and Advisors ● Frank Liu (Amazon) ● Constantin Drabo ● Amit Nagesh ● Marissa Staller ● Eric Bruno ● Anakar Parida ● Nikita Ivanov (Gridgain) ● James Weaver (IBM) ● Werner Keil ● Jyoti Buddha ● Guillaume Laforge (Google) ● Ed Burns (fmr Oracle) ● Nishant Raut (Mumbai JUG) ● Sandhya Kapoor (fmr IBM)
  • 33. JSR 381 API, Architecture, Implementations, and Examples
  • 34. JSR #381 - Visual Recognition API ● ● ● ● ● ● More readable and easier to use VisRec JSR #381 https://github.com/JavaVisRec/visrec-api/wiki/Getting-Started-Guide
  • 35. Issues with Existing Offerings ● ● ● ●
  • 36. VisRec Design goals and principles ● ● ● ●
  • 37. What Can you Do with It? 1) Classify images and data/objects classification task 2) Estimate numeric value regression task 3) Object Detection classification + regression(position)
  • 38. Generic ML Layer Visual Recognition Image Abstraction VisRec Public API Apps/Libs Visual Recognition Layer JSR381 Service Provider Interface ML Engine 1 Service Provider Impl ML Engine 2 Service Provider Impl JSR 381 Architecture
  • 39. Core Classes & Design Generic ML Layer (common abstractions, interfaces for general ML tasks) Visual Rec Layer (specialization of generic ML tasks for specific objects / domain) Implementation Based on specific ML engine DataSet<E> ImageSet extends DataSet<ExampleImage> Classifier<T, R> BinaryClassifier<T> MutliClassClassifier<T, R> ImageClassifier<IMAGE_CLASS> AbstractImageClassifier<IMAGE_CLASS , MODEL> implements ImageClassifier<IMAGE_CLASS> ImageClassifierNetwork extends AbstractImageClassifier<BufferedImage, ConvolutionalNetwork> Regressor<T, R> SimpleLinearRegression< MODEL_CLASS> implements Regressor<Float, Float>, SimpleLinearRegressionNetwork extends SimpleLinearRegression<FeedForwardN etwork>
  • 40. How to classify image Build Classifier ImageClassifier<BufferedImage> dukeClassifier = NeuralNetImageClassifier.builder() .inputClass(BufferedImage.class) .imageHeight(64) .imageWidth(64) .labelsFile(new File("labels.txt")) .trainingFile(new File("index.txt")) .networkArchitecture(new File("duke_net.json")) .exportModel(Paths.get("duke.dnet")) .maxError(0.05f) .maxEpochs(1000) .learningRate(0.01f) .build() Use Classifier BufferedImage image = ... Map<String, Float> results = classifier.classify(image); Full Example on GitHub
  • 41. Running the Demo Epoch:1, Time:686ms, TrainError:0.68538016, TrainErrorChange:0.68538016, TrainAccuracy: 0.91150445 Epoch:2, Time:505ms, TrainError:0.4474997, TrainErrorChange:-0.23788047, TrainAccuracy: 0.96460176 Epoch:3, Time:506ms, TrainError:0.28403035, TrainErrorChange:-0.16346934, TrainAccuracy: 0.96460176 Epoch:4, Time:479ms, TrainError:0.1824384, TrainErrorChange:-0.101591945, TrainAccuracy: 0.9734513 Epoch:5, Time:486ms, TrainError:0.123548426, TrainErrorChange:-0.058889978, TrainAccuracy: 0.99115044 Epoch:6, Time:493ms, TrainError:0.08493269, TrainErrorChange:-0.038615733, TrainAccuracy: 1.0
  • 42. Minimal Configuration ● Image class ● Image dimensions ● Category labels (labels file) ● List of image files with corresponding category labels (index file) ● Convolutional neural network architecture for image classification ● Training parameters (max error, max epochs, learning rate) ● File name for the trained model
  • 43. Under the hood: Convolutional Neural Network for Image Recognition High dimensional data + automated preprocessing and feature extraction
  • 44. Reference Implementation: Deep Netts ● Pure Java implementation of main Deep Learning algorithms: convolutional and feed forward neural networks ● Open source (LGPL) and professional edition ● Pro Edition includes Deep Learning IDE ○ Visual ML Tools, Wizards and ● Starting today Pro Edition is available Under FREE DEVELOPMENT license! https://www.deepnetts.com/download
  • 45. Image classification - Convolutional network using Deep Netts API ConvolutionalNetwork neuralNet = ConvolutionalNetwork.builder() .addInputLayer(imageWidth, imageHeight, 3) .addConvolutionalLayer(3, 3, 12) .addMaxPoolingLayer(2, 2) .addFullyConnectedLayer(30) .addFullyConnectedLayer(20) .addOutputLayer(labelsCount, ActivationType.SOFTMAX) .hiddenActivationFunction(ActivationType.TANH) .lossFunction(LossType.CROSS_ENTROPY) .randomSeed(123) .build();
  • 47. Next Steps for You! github.com/JavaVisRec/visrec-api/wiki/Getting-Started-Guide
  • 48. JSR 381 Visual Recognition for Java Finally, A Java-Friendly ML API Please provide feedback and contribute! No reason why Java cannot be used for ML!