$30 off During Our Annual Pro Sale. View Details »

JGS594 Lecture 08

JGS594 Lecture 08

Software Engineering for Machine Learning
Image Recognition I
(202202)

Javier Gonzalez-Sanchez
PRO

February 03, 2022
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    SER 594
    Software Engineering for
    Machine Learning
    Lecture 08: Image Recognition with DL4J
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu | javiergs.com
    PERALTA 230U
    Office Hours: By appointment

    View Slide

  2. jgs
    Previously …

    View Slide

  3. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 3
    jgs
    Guidelines
    1. Get data
    2. Create a Model
    3. Train the Model (i.e., calculate the W, Bias, and so on)
    4. Test the Model (accuracy, recall, precision, F1-score, confusion matrix)
    5. Deploy the model

    View Slide

  4. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 4
    jgs
    ND4J Input

    View Slide

  5. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 5
    jgs
    DL4J | Our Model

    View Slide

  6. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 6
    jgs
    DL4J | Training

    View Slide

  7. jgs
    Image Recognition
    Neural Networks

    View Slide

  8. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 8
    jgs
    Definition
    Using neural networks for image classification is a very straightforward
    process.
    1. We need a dataset with multiple images that we can use to train our
    neural network. We will use as inputs every single pixel in every image.
    2. We expect to get as output a category that we are looking forward to
    recognizing.

    View Slide

  9. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 9
    jgs
    Problem
    Recognize handwriting numbers 0 to 9.
    Steps:
    1. Load the dataset
    2. Create, train, and evaluate a model
    3. Save the model
    4. Put our model in an application

    View Slide

  10. jgs
    Input

    View Slide

  11. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 11
    jgs
    Publicly Available Datasets
    § MNIST dataset. 70, 000 samples of handwritten digits written by high
    school students and employees of the United States Census Bureau
    § Iris dataset. which contains three classes of 50 instances each, where each
    class refers to a type of iris plant;
    § TinyImageNet (a subset of ImageNet) dataset. An image dataset organized
    according to the WordNet hierarchy (~1000 per noun);
    § CIFAR-10 dataset. A a dataset consists of 60,000 32x32 color images in 10
    classes, with 6,000 images per class;
    § Labeled Faces in the Wild, a database of face photographs; and,
    § Curve Fragment Ground-Truth Dataset, which is used for evaluating edge
    detection or boundary detection methods.

    View Slide

  12. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 12
    jgs
    Publicly Available Datasets
    § UC Irvine Machine Learning Repository
    https://archive-beta.ics.uci.edu
    ~596 Datasets

    View Slide

  13. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 13
    jgs
    CIFAR-10 dataset | Samples

    View Slide

  14. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 14
    jgs
    MNIST dataset
    § Each number is stored as an anti-aliased image in black and white and is
    normalized to fit into a 28x28 pixel bounding box

    View Slide

  15. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 15
    jgs
    Note
    According to the MNIST website,
    1. a one-layer neural network (trained with this dataset) could achieve an
    error rate of 12% (pretty bad) –– 0.12
    2. a deep convolutional neural network could achieve an error rate below
    0.25% –– 0.0025
    Remember: Go for a value < 0.05

    View Slide

  16. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 16
    jgs
    Load Data
    (28 x 28) x 70,000

    View Slide

  17. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 17
    jgs
    Load Data
    § DeepLearning4j comes with out-of-the-box dataset iterators for standard
    datasets, including one for the MNIST dataset.
    § The class MnistDataSetIterator allows us to load these standard datasets.
    § The constructor for MnistDataSetIterator receives three parameters:
    1. The batch size, i.e., the number of training samples to work through
    before comparing to the expected output and calculate the error.
    2. The total number of samples in the dataset.
    3. A flag to indicate whether the dataset should be binarized (images
    considered in black & white without shades of gray) or not.

    View Slide

  18. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 18
    jgs
    Code

    View Slide

  19. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 19
    jgs
    Iterator

    View Slide

  20. jgs
    Model
    Case 1

    View Slide

  21. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 21
    jgs
    First Attempt
    § Single hidden layer neural network.
    § Each pixel in the images became an input 28 x 28 = 784 inputs.
    § Each of the digits that we want to predict became an output; therefore, we
    have ten neurons in the output layer.
    § What about the hidden layer?
    Use the sum of input and output neurons, not a rule, but a starting point.
    794 neurons in the hidden layer.

    View Slide

  22. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 22
    jgs
    Model 1

    View Slide

  23. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 23
    jgs
    Training

    View Slide

  24. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 24
    jgs
    Evaluation
    (Number of classes)

    View Slide

  25. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 25
    jgs
    Evaluation
    (Number of classes)

    View Slide

  26. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 26
    jgs
    Results

    View Slide

  27. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 27
    jgs
    Results
    Is this
    Good enough?

    View Slide

  28. jgs
    🙁
    To be continued …

    View Slide

  29. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 29
    jgs
    Questions

    View Slide

  30. Javier Gonzalez-Sanchez | SER 594 | Spring 2022 | 30
    jgs
    Reference
    § Deeplearning4j Suite Overview
    https://deeplearning4j.konduit.ai
    § Source Code

    View Slide

  31. jgs
    SER 594 Software Engineering for Machine Learning
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Spring 2022
    Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University.
    They cannot be distributed or used for another purpose.

    View Slide