14. @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.
15. @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…)
…. …
21. @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
24. @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%
25. @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
26. @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
27. @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
30. @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
33. @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
😅
35. @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.
39. @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
40. @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