SlideShare a Scribd company logo
CREATING A CUSTOM MACHINE LEARNING
MODEL FOR YOUR APPLICATIONS
Hello!
I am Isabel Palomar
2
Agenda
● Challenges and Initial ideas
● Main Deep Learning concepts
● Using the model!
○ Android applications
○ In your iOS, web or backend applications
… that’s all
3
��
1.
CHALLENGES AND INITIAL IDEAS
Getting started with Machine Learning and Android
Production-ready for common use cases
5
I want to create a
custom model
HOW?
6
“
77
@jeremyphoward
@math_rachel
I started a Deep Learning
Course last year at the
University of San Francisco.
💃 MY STORY: TAKING MY FIRST DEEP LEARNING CLASS
8
🤯 After the class…..
The key outcome of this lesson is that we'll have trained an
image classifier which can recognize pet breeds at state of
the art accuracy. The key to this success is the use of
transfer learning, which will be a key platform for much of
this course.
We also discuss how to set the most important
hyper-parameter when training neural networks:
the learning rate, using Leslie Smith's fantastic learning rate
finder method. Finally, we'll look at the important but rarely
discussed topic of labeling, and learn about some of the
features that fastai provides for allowing you to easily add
labels to your images. https://course.fast.ai/videos/?lesson=1
challenges….
‐ Many courses, even basic, assume that
you already know the subject.
‐ Reaching the final result without
learning the basics is not good.
9
“When you are starting to learn about
Deep Learning it seems that there
are thousands of concepts,
mathematical functions and
scientific articles that you have to
read.
10
myths
2.
Main DEEP LEARNING CONCEPTS
Let’s understand the general concepts first
MACHINE LEARNING CONCEPTS
Data Task Model
12
Loss Function Learning Algorithm Evaluation
Let’s take a look of the
implementation
We are going to build an app to
classify the artisanal beers of
Cervecería Colima
Place your screenshot here
13
1.- dATA
Data is distinct pieces of information which
acts as a fuel
14
Formats
Data can come in different formats depending on what you
want to solve
15
DATA FOR OUR EXAMPLE
16
How? Where do we get data from?
Data curation is the organization and integration
of data collected from various sources.
17
Techniques
You can use techniques like Questionnaires and surveys,
conducting interviews, using data scraping and data
crawling techniques.
Public datasets
● Google AI
● UCI ML Repository
● Data.gov.in
● Kaggle
Where do we get data from?
Crowdsourcing
Marketplaces
● Amazon Mechanical
Turk
● Dataturks
● Figure-eight
18
BACK TO OUR EXAMPLE...
● Google Images
● https://github.com/hardikvasa/google-images-download
● https://forums.fast.ai/t/tips-for-building-large-image-datasets/26688
19
2.- task
The problem to resolve
20
Examples of tasks
21
TASK FOR OUR EXAMPLE
22
Classify Images of
Artisanal Beers
Image classification
A common use of machine learning is to identify
what an image represents.
The task of predicting what an image
represents is called image classification.
23
3.- model
The mathematical formulation of a task.
24
models
25
There are many models that are created over
the years.
Each model has its own advantages and
disadvantages based on the type of data on
which we are creating a model.
IMAGE CLASSIFICATION MODEL
An image classification model is trained to recognize various
classes of images.
26
When we subsequently
provide a new image as input
to the model, it will output the
probabilities of the image
representing each of the
types it was trained on.
An example output might be as follows:
Beer type Probability
Cayaco 0.02
Colimita 0.96
Piedra Lisa 0.01
Ticus 0.00
Paramo 0.01
27
Based on the output, we
can see that the
classification model has
predicted that the image
has a high probability of
representing a Colimita
Beer.
In this example, we will retrain a
MobileNet. MobileNet is a a small efficient
convolutional neural network.
https://ai.googleblog.com/2017/06/mobilenets-open-source-models-for.html
Model for our example
28
Retraining the mobileNet model
29
We use MobileNet model and retrain it.
python3 -m scripts.retrain
--bottleneck_dir=tf_files/bottlenecks
--model_dir=tf_files/models/"${ARCHITECTURE}"
--summaries_dir=tf_files/training_summaries/"${ARCHITECTURE}"
--output_graph=tf_files/retrained_graph.pb
--output_labels=tf_files/retrained_labels.txt
--architecture="${ARCHITECTURE}"
--image_dir=tf_files/beer_photos
IMAGE_SIZE=224
ARCHITECTURE="mobilenet_0.50_${IMAGE_SIZE}"
tHE RESULT...
USING THE RETRAINED MODEL
3030
Evaluation time (1-image): 0.250s
ticus (score=0.99956)
paramo (score=0.00043)
cayaco (score=0.00000)
piedra lisa (score=0.00000)
colimita (score=0.00000)
python3 -m scripts.label_image
--graph=tf_files/retrained_graph.pb
--image=tf_files/beer_photos/ticus/"3. ticus.jpg"
4.- loss function
How do we know which model is better?
Loss function (also known as the error)
answers this question.
31
Classification losses:
● Mean Square Error/L2 Loss
● Mean Absolute Error/L1 Loss
Regression losses:
● Hinge Loss/Multi-class SVM Loss
● Cross Entropy
● Loss/Negative Log Likelihood
LOSS FUNCTIONS
To know which model
is good for our data,
we compute the loss
function by
comparing the
predicted outputs to
actual output.
32
5.- learning algorithm
The Learning Algorithms also known as
Optimization algorithms helps us to minimize
Error
33
Is something you do everyday...
You are optimizing
variables and basing your
personal decisions all day
long, most of the time
without even recognizing
the process consciously
https://mitsloan.mit.edu/ideas-made-to-matter/how-to-use
-algorithms-to-solve-everyday-problems
34
First Order Optimization
Algorithms 
● Gradient Descent
Types of learning algorithms
Second Order Optimization
Algorithms
● Hessian
https://towardsdatascience.com/types-of-optimization-algorithms-used-in-neural-networks-and-
ways-to-optimize-gradient-95ae5d39529f
35
6.- evaluation
To compute a score for our ML model, we
need to evaluate it.
36
evaluation
There are many performance metrics to achieve this. One
simple such metric is Accuracy.
37
Evaluation/performance metrics
38
● Confusion matrix
● Area Under the ROC curve (AUC — ROC)
● Root Mean Squared Error (RMSE) (used in regression)
DEEP LEARNING CONCEPTS
Data Task Model
39
Loss Function Learning Algorithm Evaluation
3.
USING THE MODEL
How to use our model in my apps
MACHINE LEARNING IN YOUR APPS
● ML Kit For Firebase
● Core ML (Apple)
● TensorFlow Lite
● Cloud-based web services
● Your own service
Place your screenshot here
41
TENSORFLOW LITE
TensorFlow Lite is an open
source deep learning
framework for on-device
inference.
42
USING THE RETRAINED MODEL
4343
Evaluation time (1-image): 0.250s
ticus (score=0.99956)
paramo (score=0.00043)
cayaco (score=0.00000)
piedra lisa (score=0.00000)
colimita (score=0.00000)
python3 -m scripts.label_image
--graph=tf_files/retrained_graph.pb
--image=tf_files/beer_photos/ticus/"3. ticus.jpg"
TENSORFLOW LITE
44
TensorFlow Lite is a set of tools to
help developers run TensorFlow
models on mobile, embedded, and
IoT devices.
● TensorFlow Lite converter
● TensorFlow Lite interpreter
TensorFlow Lite converter
Converts TensorFlow models into
an efficient form for use by the
interpreter
Command line: tflite_convert
Starting from TensorFlow
1.9, the command-line tool
tflite_convert is installed as
part of the Python package.
45
pip install --upgrade "tensorflow==1.9.*"
Using TFLite Converter
46
Output:IMAGE_SIZE=224
tflite_convert 
--graph_def_file=tf_files/retrained_graph.pb 
--output_file=tf_files/optimized_graph.lite 
--input_format=TENSORFLOW_GRAPHDEF 
--output_format=TFLITE 
--input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 
--input_array=input 
--output_array=final_result 
--inference_type=FLOAT 
--input_data_type=FLOAT
47
?
@rigaroo
recap
3.1
Use the model - android
Required files
49
Optimized graph
cp tf_files/optimized_graph.lite android/tflite/app/src/main/assets/graph.lite
cp tf_files/retrained_labels.txt android/tflite/app/src/main/assets/labels.txt
Labels
repositories {
maven {
url 'https://google.bintray.com/tensorflow'
}
}
dependencies {
// ...
compile 'org.tensorflow:tensorflow-lite:+'
}
TensorFlow Lite interpreter
50
android {
aaptOptions {
noCompress "tflite"
noCompress "lite"
}
}
The TensorFlow Lite
interpreter is designed to be
lean and fast. The interpreter
uses a static graph ordering
and a custom (less-dynamic)
memory allocator to ensure
minimal load, initialization, and
execution latency.
dependencies
settings
Load model and create interpreter
class ImageClassifier constructor(private val assetManager: AssetManager) {
init {
interpreter = Interpreter(loadModelFile(assetManager,
MODEL_PATH))
labels = loadLabelList(assetManager)
...
}
}
51
// Name of the model file stored in Assets.
const val MODEL_PATH = "graph.lite";
// Name of the label file stored in Assets.
const val LABEL_PATH = "labels.txt";
cAMERA, Read the labels…..
52
https://developer.android.com/training/camerax
// Convert the image to bytes
convertBitmapToByteBuffer(bitmap)
// An array to hold inference results, to be feed
into Tensorflow Lite as outputs.
val recognitions = ArrayList<Result>()
val recognitionsSize = Math.min(pq.size, MAX_RESULTS)
for (i in 0 until recognitionsSize) recognitions.add(pq.poll())
return@flatMap Single.just(recognitions)
Show the results
53
// Get the results
textToShow = String.format("n%s: %4.2f", label.key,
label.value)
// Label (In this case PARAMO)
label.key
// Value (In this case 1.0)
label.value
ticus (score=0.00000)
paramo (score=1.00000)
cayaco (score=0.00000)
piedra lisa (score=0.00000)
colimita (score=0.00000)
Call to action!
Now you are ready to
start building your first
custom ML model.
54
3.1
Use the model - other applications
iOS, web or backend applications
SOMETHING IS HAPPENING…..
56
The AI industry is
constantly changing
and evolving
Tensorflow lite options - Mobile & iot
TensorFlow Lite provides all the
tools you need to convert and
run TensorFlow models on
mobile, embedded, and IoT
devices.
57
Tensorflow platform
58
TensorFlow is an end-to-end open source
platform for machine learning.
● Web Apps
● Back end - APIs
https://www.tensorflow.org/
59
YOU CAN BUILD GREAT THINGS!
https://ai.google/social-good/
There a lot of
problems to solve!
59
60
SOME EXTRA MOTIVATION
http://blog.indeed.com/2019/06/28/top-10-ai-jobs-salaries-cities/
💸🤑💰💸
💸🤑🤑
61
THANKS!
You can find me at @isabelpalomar
isabelpalomarb@gmail.com

More Related Content

Similar to Creating a custom ML model for your application - DevFest Lima 2019

"Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St..."Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St...
Stefan Krawczyk
 
Machine Learning for .NET Developers - ADC21
Machine Learning for .NET Developers - ADC21Machine Learning for .NET Developers - ADC21
Machine Learning for .NET Developers - ADC21
Gülden Bilgütay
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
ssuserb4d806
 
Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)
wesley chun
 
MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle
Databricks
 
Easy path to machine learning (Spring 2020)
Easy path to machine learning (Spring 2020)Easy path to machine learning (Spring 2020)
Easy path to machine learning (Spring 2020)
wesley chun
 
Introduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventureIntroduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventure
mylittleadventure
 
Easy path to machine learning
Easy path to machine learningEasy path to machine learning
Easy path to machine learning
wesley chun
 
Google Big Data Expo
Google Big Data ExpoGoogle Big Data Expo
Google Big Data Expo
BigDataExpo
 
Apache Liminal (Incubating)—Orchestrate the Machine Learning Pipeline
Apache Liminal (Incubating)—Orchestrate the Machine Learning PipelineApache Liminal (Incubating)—Orchestrate the Machine Learning Pipeline
Apache Liminal (Incubating)—Orchestrate the Machine Learning Pipeline
Databricks
 
Lecture-6-7.pptx
Lecture-6-7.pptxLecture-6-7.pptx
Lecture-6-7.pptx
JohnMichaelPadernill
 
An introduction to Machine Learning
An introduction to Machine LearningAn introduction to Machine Learning
An introduction to Machine Learning
Valéry BERNARD
 
On-device ML with TFLite
On-device ML with TFLiteOn-device ML with TFLite
On-device ML with TFLite
Margaret Maynard-Reid
 
Learn data structures algorithms tutorial
Learn data structures algorithms tutorialLearn data structures algorithms tutorial
Learn data structures algorithms tutorial
Ashoka Vanjare
 
Data structures algorithms_tutorial
Data structures algorithms_tutorialData structures algorithms_tutorial
Data structures algorithms_tutorial
Rama Prasath A
 
Using AI to create smart application - DroidCon Tel Aviv
Using AI to create smart application - DroidCon Tel AvivUsing AI to create smart application - DroidCon Tel Aviv
Using AI to create smart application - DroidCon Tel Aviv
Sarit Tamir
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and Engineering
Vijayananda Mohire
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and Engineering
Vijayananda Mohire
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
Chetan Khatri
 
Asgh
AsghAsgh

Similar to Creating a custom ML model for your application - DevFest Lima 2019 (20)

"Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St..."Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St...
 
Machine Learning for .NET Developers - ADC21
Machine Learning for .NET Developers - ADC21Machine Learning for .NET Developers - ADC21
Machine Learning for .NET Developers - ADC21
 
AIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdfAIML4 CNN lab256 1hr (111-1).pdf
AIML4 CNN lab256 1hr (111-1).pdf
 
Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)Easy path to machine learning (Spring 2021)
Easy path to machine learning (Spring 2021)
 
MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle
 
Easy path to machine learning (Spring 2020)
Easy path to machine learning (Spring 2020)Easy path to machine learning (Spring 2020)
Easy path to machine learning (Spring 2020)
 
Introduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventureIntroduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventure
 
Easy path to machine learning
Easy path to machine learningEasy path to machine learning
Easy path to machine learning
 
Google Big Data Expo
Google Big Data ExpoGoogle Big Data Expo
Google Big Data Expo
 
Apache Liminal (Incubating)—Orchestrate the Machine Learning Pipeline
Apache Liminal (Incubating)—Orchestrate the Machine Learning PipelineApache Liminal (Incubating)—Orchestrate the Machine Learning Pipeline
Apache Liminal (Incubating)—Orchestrate the Machine Learning Pipeline
 
Lecture-6-7.pptx
Lecture-6-7.pptxLecture-6-7.pptx
Lecture-6-7.pptx
 
An introduction to Machine Learning
An introduction to Machine LearningAn introduction to Machine Learning
An introduction to Machine Learning
 
On-device ML with TFLite
On-device ML with TFLiteOn-device ML with TFLite
On-device ML with TFLite
 
Learn data structures algorithms tutorial
Learn data structures algorithms tutorialLearn data structures algorithms tutorial
Learn data structures algorithms tutorial
 
Data structures algorithms_tutorial
Data structures algorithms_tutorialData structures algorithms_tutorial
Data structures algorithms_tutorial
 
Using AI to create smart application - DroidCon Tel Aviv
Using AI to create smart application - DroidCon Tel AvivUsing AI to create smart application - DroidCon Tel Aviv
Using AI to create smart application - DroidCon Tel Aviv
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and Engineering
 
Key projects Data Science and Engineering
Key projects Data Science and EngineeringKey projects Data Science and Engineering
Key projects Data Science and Engineering
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
 
Asgh
AsghAsgh
Asgh
 

Recently uploaded

An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
DharmaBanothu
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
EMERSON EDUARDO RODRIGUES
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Dr.Costas Sachpazis
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
OKORIE1
 
comptia-security-sy0-701-exam-objectives-(5-0).pdf
comptia-security-sy0-701-exam-objectives-(5-0).pdfcomptia-security-sy0-701-exam-objectives-(5-0).pdf
comptia-security-sy0-701-exam-objectives-(5-0).pdf
foxlyon
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
ShurooqTaib
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
felixwold
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
pvpriya2
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
paraasingh12 #V08
 
SMT process how to making and defects finding
SMT process how to making and defects findingSMT process how to making and defects finding
SMT process how to making and defects finding
rameshqapcba
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
LokerXu2
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
PriyankaKilaniya
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 

Recently uploaded (20)

An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
 
comptia-security-sy0-701-exam-objectives-(5-0).pdf
comptia-security-sy0-701-exam-objectives-(5-0).pdfcomptia-security-sy0-701-exam-objectives-(5-0).pdf
comptia-security-sy0-701-exam-objectives-(5-0).pdf
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
 
SMT process how to making and defects finding
SMT process how to making and defects findingSMT process how to making and defects finding
SMT process how to making and defects finding
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 

Creating a custom ML model for your application - DevFest Lima 2019

  • 1. CREATING A CUSTOM MACHINE LEARNING MODEL FOR YOUR APPLICATIONS
  • 2. Hello! I am Isabel Palomar 2
  • 3. Agenda ● Challenges and Initial ideas ● Main Deep Learning concepts ● Using the model! ○ Android applications ○ In your iOS, web or backend applications … that’s all 3 ��
  • 4. 1. CHALLENGES AND INITIAL IDEAS Getting started with Machine Learning and Android
  • 6. I want to create a custom model HOW? 6
  • 7. “ 77 @jeremyphoward @math_rachel I started a Deep Learning Course last year at the University of San Francisco. 💃 MY STORY: TAKING MY FIRST DEEP LEARNING CLASS
  • 8. 8 🤯 After the class….. The key outcome of this lesson is that we'll have trained an image classifier which can recognize pet breeds at state of the art accuracy. The key to this success is the use of transfer learning, which will be a key platform for much of this course. We also discuss how to set the most important hyper-parameter when training neural networks: the learning rate, using Leslie Smith's fantastic learning rate finder method. Finally, we'll look at the important but rarely discussed topic of labeling, and learn about some of the features that fastai provides for allowing you to easily add labels to your images. https://course.fast.ai/videos/?lesson=1
  • 9. challenges…. ‐ Many courses, even basic, assume that you already know the subject. ‐ Reaching the final result without learning the basics is not good. 9
  • 10. “When you are starting to learn about Deep Learning it seems that there are thousands of concepts, mathematical functions and scientific articles that you have to read. 10 myths
  • 11. 2. Main DEEP LEARNING CONCEPTS Let’s understand the general concepts first
  • 12. MACHINE LEARNING CONCEPTS Data Task Model 12 Loss Function Learning Algorithm Evaluation
  • 13. Let’s take a look of the implementation We are going to build an app to classify the artisanal beers of Cervecería Colima Place your screenshot here 13
  • 14. 1.- dATA Data is distinct pieces of information which acts as a fuel 14
  • 15. Formats Data can come in different formats depending on what you want to solve 15
  • 16. DATA FOR OUR EXAMPLE 16
  • 17. How? Where do we get data from? Data curation is the organization and integration of data collected from various sources. 17 Techniques You can use techniques like Questionnaires and surveys, conducting interviews, using data scraping and data crawling techniques.
  • 18. Public datasets ● Google AI ● UCI ML Repository ● Data.gov.in ● Kaggle Where do we get data from? Crowdsourcing Marketplaces ● Amazon Mechanical Turk ● Dataturks ● Figure-eight 18
  • 19. BACK TO OUR EXAMPLE... ● Google Images ● https://github.com/hardikvasa/google-images-download ● https://forums.fast.ai/t/tips-for-building-large-image-datasets/26688 19
  • 20. 2.- task The problem to resolve 20
  • 22. TASK FOR OUR EXAMPLE 22 Classify Images of Artisanal Beers
  • 23. Image classification A common use of machine learning is to identify what an image represents. The task of predicting what an image represents is called image classification. 23
  • 24. 3.- model The mathematical formulation of a task. 24
  • 25. models 25 There are many models that are created over the years. Each model has its own advantages and disadvantages based on the type of data on which we are creating a model.
  • 26. IMAGE CLASSIFICATION MODEL An image classification model is trained to recognize various classes of images. 26 When we subsequently provide a new image as input to the model, it will output the probabilities of the image representing each of the types it was trained on.
  • 27. An example output might be as follows: Beer type Probability Cayaco 0.02 Colimita 0.96 Piedra Lisa 0.01 Ticus 0.00 Paramo 0.01 27 Based on the output, we can see that the classification model has predicted that the image has a high probability of representing a Colimita Beer.
  • 28. In this example, we will retrain a MobileNet. MobileNet is a a small efficient convolutional neural network. https://ai.googleblog.com/2017/06/mobilenets-open-source-models-for.html Model for our example 28
  • 29. Retraining the mobileNet model 29 We use MobileNet model and retrain it. python3 -m scripts.retrain --bottleneck_dir=tf_files/bottlenecks --model_dir=tf_files/models/"${ARCHITECTURE}" --summaries_dir=tf_files/training_summaries/"${ARCHITECTURE}" --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --architecture="${ARCHITECTURE}" --image_dir=tf_files/beer_photos IMAGE_SIZE=224 ARCHITECTURE="mobilenet_0.50_${IMAGE_SIZE}" tHE RESULT...
  • 30. USING THE RETRAINED MODEL 3030 Evaluation time (1-image): 0.250s ticus (score=0.99956) paramo (score=0.00043) cayaco (score=0.00000) piedra lisa (score=0.00000) colimita (score=0.00000) python3 -m scripts.label_image --graph=tf_files/retrained_graph.pb --image=tf_files/beer_photos/ticus/"3. ticus.jpg"
  • 31. 4.- loss function How do we know which model is better? Loss function (also known as the error) answers this question. 31
  • 32. Classification losses: ● Mean Square Error/L2 Loss ● Mean Absolute Error/L1 Loss Regression losses: ● Hinge Loss/Multi-class SVM Loss ● Cross Entropy ● Loss/Negative Log Likelihood LOSS FUNCTIONS To know which model is good for our data, we compute the loss function by comparing the predicted outputs to actual output. 32
  • 33. 5.- learning algorithm The Learning Algorithms also known as Optimization algorithms helps us to minimize Error 33
  • 34. Is something you do everyday... You are optimizing variables and basing your personal decisions all day long, most of the time without even recognizing the process consciously https://mitsloan.mit.edu/ideas-made-to-matter/how-to-use -algorithms-to-solve-everyday-problems 34
  • 35. First Order Optimization Algorithms  ● Gradient Descent Types of learning algorithms Second Order Optimization Algorithms ● Hessian https://towardsdatascience.com/types-of-optimization-algorithms-used-in-neural-networks-and- ways-to-optimize-gradient-95ae5d39529f 35
  • 36. 6.- evaluation To compute a score for our ML model, we need to evaluate it. 36
  • 37. evaluation There are many performance metrics to achieve this. One simple such metric is Accuracy. 37
  • 38. Evaluation/performance metrics 38 ● Confusion matrix ● Area Under the ROC curve (AUC — ROC) ● Root Mean Squared Error (RMSE) (used in regression)
  • 39. DEEP LEARNING CONCEPTS Data Task Model 39 Loss Function Learning Algorithm Evaluation
  • 40. 3. USING THE MODEL How to use our model in my apps
  • 41. MACHINE LEARNING IN YOUR APPS ● ML Kit For Firebase ● Core ML (Apple) ● TensorFlow Lite ● Cloud-based web services ● Your own service Place your screenshot here 41
  • 42. TENSORFLOW LITE TensorFlow Lite is an open source deep learning framework for on-device inference. 42
  • 43. USING THE RETRAINED MODEL 4343 Evaluation time (1-image): 0.250s ticus (score=0.99956) paramo (score=0.00043) cayaco (score=0.00000) piedra lisa (score=0.00000) colimita (score=0.00000) python3 -m scripts.label_image --graph=tf_files/retrained_graph.pb --image=tf_files/beer_photos/ticus/"3. ticus.jpg"
  • 44. TENSORFLOW LITE 44 TensorFlow Lite is a set of tools to help developers run TensorFlow models on mobile, embedded, and IoT devices. ● TensorFlow Lite converter ● TensorFlow Lite interpreter TensorFlow Lite converter Converts TensorFlow models into an efficient form for use by the interpreter
  • 45. Command line: tflite_convert Starting from TensorFlow 1.9, the command-line tool tflite_convert is installed as part of the Python package. 45 pip install --upgrade "tensorflow==1.9.*"
  • 46. Using TFLite Converter 46 Output:IMAGE_SIZE=224 tflite_convert --graph_def_file=tf_files/retrained_graph.pb --output_file=tf_files/optimized_graph.lite --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 --input_array=input --output_array=final_result --inference_type=FLOAT --input_data_type=FLOAT
  • 48. 3.1 Use the model - android
  • 49. Required files 49 Optimized graph cp tf_files/optimized_graph.lite android/tflite/app/src/main/assets/graph.lite cp tf_files/retrained_labels.txt android/tflite/app/src/main/assets/labels.txt Labels
  • 50. repositories { maven { url 'https://google.bintray.com/tensorflow' } } dependencies { // ... compile 'org.tensorflow:tensorflow-lite:+' } TensorFlow Lite interpreter 50 android { aaptOptions { noCompress "tflite" noCompress "lite" } } The TensorFlow Lite interpreter is designed to be lean and fast. The interpreter uses a static graph ordering and a custom (less-dynamic) memory allocator to ensure minimal load, initialization, and execution latency. dependencies settings
  • 51. Load model and create interpreter class ImageClassifier constructor(private val assetManager: AssetManager) { init { interpreter = Interpreter(loadModelFile(assetManager, MODEL_PATH)) labels = loadLabelList(assetManager) ... } } 51 // Name of the model file stored in Assets. const val MODEL_PATH = "graph.lite"; // Name of the label file stored in Assets. const val LABEL_PATH = "labels.txt";
  • 52. cAMERA, Read the labels….. 52 https://developer.android.com/training/camerax // Convert the image to bytes convertBitmapToByteBuffer(bitmap) // An array to hold inference results, to be feed into Tensorflow Lite as outputs. val recognitions = ArrayList<Result>() val recognitionsSize = Math.min(pq.size, MAX_RESULTS) for (i in 0 until recognitionsSize) recognitions.add(pq.poll()) return@flatMap Single.just(recognitions)
  • 53. Show the results 53 // Get the results textToShow = String.format("n%s: %4.2f", label.key, label.value) // Label (In this case PARAMO) label.key // Value (In this case 1.0) label.value ticus (score=0.00000) paramo (score=1.00000) cayaco (score=0.00000) piedra lisa (score=0.00000) colimita (score=0.00000)
  • 54. Call to action! Now you are ready to start building your first custom ML model. 54
  • 55. 3.1 Use the model - other applications iOS, web or backend applications
  • 56. SOMETHING IS HAPPENING….. 56 The AI industry is constantly changing and evolving
  • 57. Tensorflow lite options - Mobile & iot TensorFlow Lite provides all the tools you need to convert and run TensorFlow models on mobile, embedded, and IoT devices. 57
  • 58. Tensorflow platform 58 TensorFlow is an end-to-end open source platform for machine learning. ● Web Apps ● Back end - APIs https://www.tensorflow.org/
  • 59. 59 YOU CAN BUILD GREAT THINGS! https://ai.google/social-good/ There a lot of problems to solve! 59
  • 61. 61 THANKS! You can find me at @isabelpalomar isabelpalomarb@gmail.com