SlideShare a Scribd company logo
1 of 41
Download to read offline
From Zero To
Deep Learning
With Scala
Fabio Tiriticco
@ticofab
ScalaLove - Harmony
18th April 2020
@ticofab
ticofab.io
An AI expert
Who I am NOT
@ticofab
ticofab.ioWho I am
• Scala / Akka enthusiast

• Community manager
The Planes Idea
@ticofab
ticofab.ioThe Surroundings Of My Office
Original
airport area
Second
strip built
Brigde over
highway
@ticofab
ticofab.ioView From My Office
@ticofab
ticofab.ioThe Planes Idea
Camera Module
Raspberry PI
@ticofab
ticofab.ioRaspberry PI setup
AI Overview
@ticofab
ticofab.ioAI, Machine Learning & Deep Learning
Artificial
Intelligence (AI)
Machine
Learning (ML)
Deep Learning
(DL)
@ticofab
ticofab.ioThe Pyramid Of Wisdom
KNOWLEDGE
INFORMATION
RAW DATA
Typical application
of ML / AI
WISDOM
🏆
@ticofab
ticofab.ioTwo Common Uses for ML / AI
Regression
“How much?” “What kind?”
Classification
@ticofab
ticofab.ioOur Case: Classification Between Two Classes
PLANE NO PLANE
@ticofab
ticofab.ioHow To Build Our AI? (A revelation)
AI is still at the stage
of trial & error.
We only know that for
some problems, certain
architectures work
better than others.
@ticofab
ticofab.ioProblems Matched By Architectures
TYPE OF DEEP NETWORK TYPICAL USE CASES
Unsupervised Pretrained Networks
Reproduce existing models

(sound, video, handwriting…)
Convolutional Neural Networks

CNN
Image recognition 

(faces, animals, street signs..)
Recurrent Neural Networks

RNN
Processes where inputs form sequences in time

(speech synthesis, translation…)
…. …
The Basics Of Neural Networks
@ticofab
ticofab.ioThe Artificial Neuron
f(w1, w2, .. wn)
w1
w2
wn
…
a(res)res
WEIGHTED
INPUTS
TRANSFER
FUNCTION ACTIVATION
FUNCTION
NET INPUT
@ticofab
ticofab.io
T
P
G
Multilayer Neural Network
INPUT
VALUES
INPUT
LAYER
HIDDEN
LAYER 1
HIDDEN
LAYER 2
OUTPUT
LAYER
OUTPUT
VALUES
A
B
C
2
5
7
1
Convolutional Neural Networks
(CNN)
@ticofab
ticofab.ioThe Power Of CNNs
Automatic feature
extraction
Able to identify a
complex combination
of features
@ticofab
ticofab.ioHow Does A Convolutional Layer Work?
Learns filters that, applied to the
training images, see the rabbit features
The network learns the “rabbitness” of
the rabbit - what makes it unique! 🐰
TRAIN WITH 1000s OF IMAGES
@ticofab
ticofab.ioA Typical CNN Architecture (LeNet)
Convolutional
Layer
Convolutional
Layer
Subsampling
Layer
Subsampling
Layer
Dense
Layer
(500 fully connected neurons)
Output
Layer
Input
Layer
Scala & Deeplearning4J
@ticofab
ticofab.ioTraining Images - Crop And Resize To 171 x 25 Pixels
NO PLANEPLANE
Split the image dataset in two:
TRAINING SET 80%

TEST SET 20%
@ticofab
ticofab.ioSome settings
171 px
25 px
/// information about the image
val inputHeight = 25 /// pixels
val inputWidth = 171 /// pixels
val depth = 3 /// Number of input channels (RGB)
/// number of possible outcomes (PLANE or NO PLANE)
val numClasses = 2
@ticofab
ticofab.ioOur Network In Scala Layer By Layer
new NeuralNetConfiguration.Builder().layer(0, new ConvolutionLayer.Builder(5, 5)

.nIn(depth)

.stride(1, 1)

.nOut(20)

.build)
.layer(1, new SubsamplingLayer.Builder()

.kernelSize(2, 2)

.stride(2, 2)

.build)
.layer(2, new ConvolutionLayer.Builder(5, 5)

.stride(1, 1)

.nOut(50)

.build)
.layer(3, new SubsamplingLayer.Builder()

.kernelSize(2, 2)

.stride(2, 2)

.build)
.layer(4, new DenseLayer.Builder()

.nOut(500)

.build)
.layer(5, new OutputLayer.Builder()

.nOut(numClasses)

.build)
.setInputType(InputType.convolutional(

(inputHeight, inputWidth, depth))

.build
new NeuralNetConfiguration.Builder()
.layer(0, new ConvolutionLayer.Builder(5, 5)

.nIn(depth)

.stride(1, 1)

.nOut(20)

.build)
.setInputType(InputType.convolutional(

inputHeight, inputWidth, depth))

.build
.layer(1, new SubsamplingLayer.Builder()

.kernelSize(2, 2)

.stride(2, 2)

.build)
.layer(2, new ConvolutionLayer.Builder(5, 5)

.stride(1, 1)

.nOut(50)

.build)
.layer(3, new SubsamplingLayer.Builder()

.kernelSize(2, 2)

.stride(2, 2)

.build)
.layer(4, new DenseLayer.Builder()

.nOut(500)

.build)
.layer(5, new OutputLayer.Builder()

.nOut(numClasses)

.build)
PSEUDO
CODEConvolutional
Layer
Convolutional
Layer
Subsampling
Layer
Subsampling
Layer
Dense
Layer
(500 fully connected neurons)
Output
Layer
Input
Layer
@ticofab
ticofab.ioTrain And Evaluate Our Network
• Read images

• Split them in two datasets - train + test

• Decide the stopping criteria for training
val tc = new MaxTimeIterationTerminationCondition(6 MINUTES)
val conf = new EarlyStoppingConfiguration.Builder[MultiLayerNetwork]()
.iterationTerminationConditions(tc)
.modelSaver(saver)
.build
• Train and save the model
val bestModel = new EarlyStoppingTrainer(CONF + MODEL + FILES)
.fit.getBestModel
PSEUDO
CODE
@ticofab
ticofab.ioLogs of a training run
The Pipeline
@ticofab
ticofab.ioAI is only a small bit of AI projects
Planes Detection Flow
Tick
every
hour
Pick
earliest
plane pic
Pick
random
quote
Tweet
Move to
TWEETED
folder
New
picture
detected
Trim
picture
Crop
image
121x75
Move to
PLANE
folder
Detect
Plane Plane
detected
Nothing
detected
Move to
NO PLANE
folder
Manually
check
pics
Train new
model
Replace
old model
Read log
files
Check
against
detection
Evaluate
metrics
Save to
CSV
Twitter Flow
Train & Performance
Evaluation Flow
Take pic
every
minute
Results
@ticofab
ticofab.io@PlanesOnBridge
1100 tweets
11 followers
@ticofab
ticofab.ioConfusion Matrix
True Positive (TP)
There was a plane
and the model saw it
🧐
False Positive (FP)
The model saw a plane
but there wasn’t any 

🤥
False Negative (FN)
There was a plane but
the model didn’t see it

🥴
True Negative (TN)
There was no plane and
the model didn’t see one

😅
@ticofab
ticofab.ioModel Performance
@ticofab
ticofab.ioModel Performance
Recall = TP / TP + FN
How well the model
avoids false negatives
Precision = TP / TP + FP
How well the model avoids
false positives
When my model sees a
plane, it’s probably there.

Unfortunately, it misses
quite a few planes.
@ticofab
ticofab.ioWhen does it go wrong?
@ticofab
ticofab.ioAI Bias. So Many Blue Planes!
Next Steps For You
@ticofab
ticofab.ioNext Steps
• Find a fun use-case and a dataset

https:///github.com/ticofab/deep-learning-with-scala
• Learn a few more details about AI and CNNs

• Create and train your network with Deeplearning4j !

• https:///gitter.im/Machine-Learning-in-Scala/community
@ticofab
ticofab.ioReferences
• DeepLearning4j - https:///deeplearning4j.org/
• https:///github.com/ticofab/deep-learning-with-scala
Deep Learning: A Practitioner’s Approach
Josh Patterson & Adam Gibson
Thanks and
stay safe!
Fabio Tiriticco
@ticofab
ScalaLove - Harmony
18th April 2020

More Related Content

Similar to From Zero To Deep Learning With Scala

odtslide-180529073940.pptx
odtslide-180529073940.pptxodtslide-180529073940.pptx
odtslide-180529073940.pptx
ahmedchammam
 
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text DataSemi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Tech Triveni
 

Similar to From Zero To Deep Learning With Scala (20)

Planespotting - From Zero To Deep Learning
Planespotting - From Zero To Deep Learning Planespotting - From Zero To Deep Learning
Planespotting - From Zero To Deep Learning
 
深度學習在AOI的應用
深度學習在AOI的應用深度學習在AOI的應用
深度學習在AOI的應用
 
Flutter + tensor flow lite = awesome sauce
Flutter + tensor flow lite = awesome sauceFlutter + tensor flow lite = awesome sauce
Flutter + tensor flow lite = awesome sauce
 
Object Detection with Tensorflow
Object Detection with TensorflowObject Detection with Tensorflow
Object Detection with Tensorflow
 
EKON 24 ML_community_edition
EKON 24 ML_community_editionEKON 24 ML_community_edition
EKON 24 ML_community_edition
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 
End-to-end Big Data Projects with Python - StampedeCon Big Data Conference 2017
End-to-end Big Data Projects with Python - StampedeCon Big Data Conference 2017End-to-end Big Data Projects with Python - StampedeCon Big Data Conference 2017
End-to-end Big Data Projects with Python - StampedeCon Big Data Conference 2017
 
Ai use cases
Ai use casesAi use cases
Ai use cases
 
Deep AutoViML For Tensorflow Models and MLOps Workflows
Deep AutoViML For Tensorflow Models and MLOps WorkflowsDeep AutoViML For Tensorflow Models and MLOps Workflows
Deep AutoViML For Tensorflow Models and MLOps Workflows
 
2019 05 11 Chicago Codecamp - Deep Learning for everyone? Challenge Accepted!
2019 05 11 Chicago Codecamp - Deep Learning for everyone? Challenge Accepted!2019 05 11 Chicago Codecamp - Deep Learning for everyone? Challenge Accepted!
2019 05 11 Chicago Codecamp - Deep Learning for everyone? Challenge Accepted!
 
odtslide-180529073940.pptx
odtslide-180529073940.pptxodtslide-180529073940.pptx
odtslide-180529073940.pptx
 
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.jsTensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
 
Defend against adversarial AI using Adversarial Robustness Toolbox
Defend against adversarial AI using Adversarial Robustness Toolbox Defend against adversarial AI using Adversarial Robustness Toolbox
Defend against adversarial AI using Adversarial Robustness Toolbox
 
Elasticwulf Pycon Talk
Elasticwulf Pycon TalkElasticwulf Pycon Talk
Elasticwulf Pycon Talk
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
 
用 Python 玩 LHC 公開數據
用 Python 玩 LHC 公開數據用 Python 玩 LHC 公開數據
用 Python 玩 LHC 公開數據
 
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text DataSemi-Supervised Insight Generation from Petabyte Scale Text Data
Semi-Supervised Insight Generation from Petabyte Scale Text Data
 
Object Detection with Transformers
Object Detection with TransformersObject Detection with Transformers
Object Detection with Transformers
 
Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...
Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...
Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...
 
Transfer learning, active learning using tensorflow object detection api
Transfer learning, active learning  using tensorflow object detection apiTransfer learning, active learning  using tensorflow object detection api
Transfer learning, active learning using tensorflow object detection api
 

More from Fabio Tiriticco

More from Fabio Tiriticco (12)

Intro slides - Global Reactive Meetup - Move over JDBC!
Intro slides - Global Reactive Meetup - Move over JDBC!Intro slides - Global Reactive Meetup - Move over JDBC!
Intro slides - Global Reactive Meetup - Move over JDBC!
 
Reactive Amsterdam - Maxim Burgerhout - Quarkus Intro
Reactive Amsterdam - Maxim Burgerhout - Quarkus IntroReactive Amsterdam - Maxim Burgerhout - Quarkus Intro
Reactive Amsterdam - Maxim Burgerhout - Quarkus Intro
 
Ten Frustrations From The Community Trenches (And How To Deal With Them)
Ten Frustrations From The Community Trenches (And How To Deal With Them)Ten Frustrations From The Community Trenches (And How To Deal With Them)
Ten Frustrations From The Community Trenches (And How To Deal With Them)
 
We all need friends and Akka just found Kubernetes
We all need friends and Akka just found KubernetesWe all need friends and Akka just found Kubernetes
We all need friends and Akka just found Kubernetes
 
Cloud native akka and kubernetes holy grail to elasticity
Cloud native akka and kubernetes   holy grail to elasticityCloud native akka and kubernetes   holy grail to elasticity
Cloud native akka and kubernetes holy grail to elasticity
 
Reactive Summit 2017 Highlights!
Reactive Summit 2017 Highlights!Reactive Summit 2017 Highlights!
Reactive Summit 2017 Highlights!
 
Reactive Programming or Reactive Systems? (spoiler: both)
Reactive Programming or Reactive Systems? (spoiler: both)Reactive Programming or Reactive Systems? (spoiler: both)
Reactive Programming or Reactive Systems? (spoiler: both)
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor Programming
 
Akka Streams at Weeronline
Akka Streams at WeeronlineAkka Streams at Weeronline
Akka Streams at Weeronline
 
Reactive in Android and Beyond Rx
Reactive in Android and Beyond RxReactive in Android and Beyond Rx
Reactive in Android and Beyond Rx
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyond
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

From Zero To Deep Learning With Scala