Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Whirlwind Tour of Machine Learning with TensorFlow

A Whirlwind Tour of Machine Learning with TensorFlow

International Women's Day 2020, Jakarta

Galuh Sahid

May 17, 2020
Tweet

More Decks by Galuh Sahid

Other Decks in Technology

Transcript

  1. Galuh Sahid
    @galuhsahid
    A Whirlwind Tour of
    Machine Learning with
    TensorFlow

    View Slide

  2. Image slides
    Hi! I’m Galuh.
    • Data Scientist at Gojek
    • Google Dev Expert in Machine Learning
    • Co-host podcast Kartini Teknologi
    (kartiniteknologi.id)

    View Slide

  3. Resources
    First photo credit: Photo by BENCE BOROS on Unsplash

    View Slide

  4. It’s an exciting time to learn about
    machine learning!

    View Slide

  5. TensorFlow

    View Slide

  6. TensorFlow is an end-to-end open source platform for machine
    learning.
    TensorFlow.org

    View Slide

  7. How is machine learning different
    from traditional programming?

    View Slide

  8. Traditional
    Programming
    Rules
    Data
    Answers

    View Slide

  9. if pixel[5][7] is black and pixel [5][6]
    is black and pixel [5][8] is black and …:
    if pixel[6][7] is black and pixel[6][7]
    is black and …:
    return “panda”



    else:
    return “cat”
    Photo credit: Photo by Damian Patkowski on Unsplash

    View Slide

  10. if pixel[5][7] is black and pixel [5][6]
    is black and pixel [5][7] is black and …:
    if pixel[6][7] is black and pixel[6][7]
    is black and …:
    return “panda”



    else:
    return “not cat”
    Photo credit: Photo by Dušan Smetana on Unsplash

    View Slide

  11. Machine
    Learning
    Answers
    Data
    Rules

    View Slide

  12. Answers
    Data
    Photo credit: Max Baskakov and Zane Lee on Unsplash
    Panda
    Panda
    Cat
    Cat

    View Slide

  13. Photo credit: Cyrus Chew on Unsplash
    ?
    Cat
    ?

    View Slide

  14. The machine learning project
    journey

    View Slide

  15. Adapted from Introduction to ML Problem Framing
    Define a
    machine
    learning
    problem
    Construct &
    transform your
    dataset
    Train a model
    Use the model
    to make
    predictions

    View Slide

  16. Define a
    machine
    learning
    problem
    Construct &
    transform your
    dataset
    Train a model
    Use the model
    to make
    predictions
    Adapted from Introduction to ML Problem Framing

    View Slide

  17. Define a machine learning problem

    View Slide

  18. Define your ML problem
    Type of problem Description Example
    Classification Pick one of N labels Cat, dog, horse, or bear
    Regression Predict numerical values House price
    Clustering Group similar examples
    News articles grouped into
    categories (unsupervised)
    Ranking Identify position on a scale Search result ranking
    Adapted from Introduction to ML Problem Framing

    View Slide

  19. Define your ML problem
    Type of problem Description Example
    Classification Pick one of N labels Cat, dog, horse, or bear
    Regression Predict numerical values House price
    Clustering Group similar examples
    News articles grouped into
    categories (unsupervised)
    Ranking Identify position on a scale Search result ranking
    Adapted from Introduction to ML Problem Framing
    Example: “our problem is best framed as a classification problem, which predicts
    whether a picture will be in one of the four classes: cat, dog, horse, or bear.”

    View Slide

  20. Define a
    machine
    learning
    problem
    Build your
    dataset
    Train a model
    Use the model
    to make
    predictions
    Adapted from Introduction to ML Problem Framing

    View Slide

  21. Build your dataset

    View Slide

  22. Data Type: Tabular House
    Price
    Year
    Built
    Lot Area

    View Slide

  23. Data Type: Pictures

    View Slide

  24. Data Type: Text

    View Slide

  25. Social media
    tf.data: Input
    Makes it easy for you to process:
    - text data
    - CSV data
    - image data
    and more

    View Slide

  26. tf.data: Transformation example
    def preprocess(image, label):
    image = tf.image.random_flip_left_right(image)
    image = tf.image.random_brightness(image,
    max_delta=0.2)
    image = tf.clip_by_value(image, 0.0, 1.0)
    return image, label
    Image augmentation

    View Slide

  27. tf.data: Transformation example
    def preprocess(image, label):
    image = tf.image.random_flip_left_right(image)
    image = tf.image.random_brightness(image,
    max_delta=0.2)
    image = tf.clip_by_value(image, 0.0, 1.0)
    return image, label
    Image augmentation

    View Slide

  28. tf.data: Transformation example
    def preprocess(image, label):
    image = tf.image.random_flip_left_right(image)
    image = tf.image.random_brightness(image,
    max_delta=0.2)
    image = tf.clip_by_value(image, 0.0, 1.0)
    return image, label
    Image augmentation
    1+1 =
    2+2 =
    3+3 =

    View Slide

  29. tf.data: Transformation example
    def preprocess(image, label):
    image = tf.image.random_flip_left_right(image)
    image = tf.image.random_brightness(image,
    max_delta=0.2)
    image = tf.clip_by_value(image, 0.0, 1.0)
    return image, label
    Image augmentation
    1+1 =
    2+2 =
    3+3 =
    1+1*2 =
    2+2*2 =
    3+3*2 =

    View Slide

  30. tf.data: TensorFlow Datasets
    and many more

    View Slide

  31. MNIST Dataset
    tf.data: TensorFlow Datasets

    View Slide

  32. tf.data: TensorFlow Datasets
    import tensorflow.compat.v2 as tf
    import tensorflow_datasets as tfds
    # Construct a tf.data.Dataset
    ds = tfds.load('mnist', split='train', shuffle_files=True)

    View Slide

  33. Define a
    machine
    learning
    problem
    Construct &
    transform your
    dataset
    Train a model
    Use the model
    to make
    predictions
    Adapted from Introduction to ML Problem Framing

    View Slide

  34. Training a model

    View Slide

  35. What is a “model”?
    - A model maps examples to predicted labels
    - It is defined by weights that are learned during the training process
    - Once trained, you can use it to make predictions about data that it
    has never seen before
    Model
    Data Predictions

    View Slide

  36. A very simplified example
    Iteration 1: 2*number of floors + 3*area size = predicted house price
    Model
    Data Predictions
    House #1:
    predicted: 200 million
    actual: 500 million
    difference: 300 million

    View Slide

  37. A very simplified example
    Iteration 1: 2*number of floors + 3*area size = predicted house price
    Model
    Data Predictions
    Iteration 2: 4*number of floors + 6*area size = predicted house price
    House #1:
    predicted: 400 million
    actual: 500 million
    difference: 100 million

    View Slide

  38. Neural network Layer
    Node

    View Slide

  39. Example of neural network in TensorFlow
    model = tf.keras.models.Sequential(
    [ tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(512, activation=‘relu’),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=‘softmax’)
    ])

    View Slide

  40. ?
    Panda
    Cat
    Accuracy: 80%
    Our model does not get smart right away
    Photo: Manja Vitolic on Unsplash | Icon: Flaticon

    View Slide

  41. ?
    Panda
    Panda
    Accuracy: 95%
    Our model does not get smart right away
    Photo: Nicholas Doherty on Unsplash | Icon: Flaticon

    View Slide

  42. Adapted from Machine Learning Crash Course
    High Loss Low Loss
    - Arrows represent loss
    - Blue lines represent predictions
    How does a model get better? Loss

    View Slide

  43. Neural network in TensorFlow
    model = tf.keras.models.Sequential(
    [ tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(512, activation=‘relu’),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=‘softmax’)
    ])
    model.compile(loss = ‘sparse_categorical_crossentropy’,
    metrics = ‘accuracy’)

    View Slide

  44. How do we know that our model is good enough?
    Metric
    - Evaluation metrics:
    • Accuracy
    • Mean Absolute Error
    • Root Mean Squared Error
    • … and more
    Actual Spam Actual Not Spam
    Predicted Spam 15 10
    Predicted Not
    Spam
    5 30
    Accuracy:
    (Correctly classified spam emails + correctly classified not spam
    emails)/total emails = (15 + 30)/(15+10+5+30) = 75%

    View Slide

  45. Let the training process begin!
    model = tf.keras.models.Sequential(
    [ tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(512, activation=‘relu’),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=‘softmax’)
    ])
    model.compile(loss = ‘sparse_categorical_crossentropy’,
    metrics = ‘accuracy’)
    model.fit(x_train, y_train, epochs=5)
    model.evaluate(x_test, y_test)

    View Slide

  46. Define a
    machine
    learning
    problem
    Construct &
    transform your
    dataset
    Train a model
    Use the model
    to make
    predictions
    Adapted from Introduction to ML Problem Framing

    View Slide

  47. Use the model to make predictions

    View Slide

  48. Making predictions
    1. Use models that you built by yourself
    2. Use existing models
    3. Retrain existing models

    View Slide

  49. Use existing models: TensorFlow Hub
    TensorFlow Hub

    View Slide

  50. Retrain existing models: Teachable Machine
    Teachable Machine

    View Slide

  51. Retrain existing models: Teachable Machine
    Teachable Machine

    View Slide

  52. Retrain existing models: Teachable Machine
    Teachable Machine

    View Slide

  53. Deployment: TensorFlow Serving
    TensorFlow Serving

    View Slide

  54. Deployment: TensorFlow.js
    TensorFlow.js

    View Slide

  55. Deployment: TensorFlow.js
    How Modiface utilized TensorFlow.js in production for AR makeup try on in the browser

    View Slide

  56. Deployment: TensorFlow Lite
    TensorFlow Lite

    View Slide

  57. Next Steps

    View Slide

  58. Define a
    machine
    learning
    problem
    Construct &
    transform your
    dataset
    Train a model
    Use the model
    to make
    predictions
    Adapted from Introduction to ML Problem Framing

    View Slide

  59. Learning Resources
    •Deep Learning with Python (book) by François Chollet
    •Machine Learning Glossary
    •Machine Learning Crash Course
    •TensorFlow Tutorials
    •Teachable Machine Tutorials (1, 2, 3)
    •But what is a neural network? (video)

    View Slide

  60. Learning Resources
    https://main-suit.glitch.me

    View Slide

  61. Learning Resources
    https://main-suit.glitch.me

    View Slide

  62. Thank You!

    View Slide