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

A Gentle Introduction to Deep Learning for Developers at ConFoo Montreal

A Gentle Introduction to Deep Learning for Developers at ConFoo Montreal

While we are a long way out from machines that can perform artificial general intelligence (AGI) tasks, deep learning can be used for many narrow artificial intelligence (AI) tasks including image or audio classification, facial recognition, object recognition, image caption generation, and natural language processing. We will explore how developers can easily integrate open source deep learning models into their applications.

Bradley Holt

March 14, 2019
Tweet

More Decks by Bradley Holt

Other Decks in Programming

Transcript

  1. A Gentle Introduction to Deep Learning for Developers Bradley Holt

    Program Manager, Developer Advocacy Center for Open-Source Data and AI Technologies @BradleyHolt DOC ID / Month XX, 2018 / © 2018 IBM Corporation
  2. Yes

  3. General AI Metal Skull With Terminator Eye by L.C. Nøttaasen,

    on Flickr <https://flic.kr/p/6xh2Dr> (CC BY-SA 2.0).
  4. Broad AI -[ electrIc b88Gal88 ]- by JD Hancock, on

    Flickr <https://flic.kr/p/6x9t1H> (CC BY 2.0).
  5. Narrow AI Danbo on the Lookout by IQRemix, on Flickr

    <https://flic.kr/p/x5oWjP> (CC BY-SA 2.0).
  6. Install magicat $ npm install -g magicat + [email protected] added

    255 packages from 209 contributors in 11.798s
  7. Scan Directory with magicat $ magicat . Scanning directory '/Users/bradleydholt/tfjs-demos/magicat'...

    The image '23895621638_535be71dee_k.jpg' contains the following segments: background, cat. The image '37038669284_899d7784a9_k.jpg' contains the following segments: background, sheep. The image '37489697170_31d05aa027_k.jpg' contains the following segments: background, sheep. The image '37699459356_24fd526a5e_k.jpg' contains the following segments: background, cat. The image '37699976806_5ce694be36_k.jpg' contains the following segments: background, horse.
  8. background, cat background, sheep background, sheep background, cat background, horse

    Animal photos by Susanne Nilsson, on Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0).
  9. Save Image Segment with magicat $ magicat 37699976806_5ce694be36_k.jpg --save horse

    The image '37699976806_5ce694be36_k.jpg' contains the following segments: background, horse. saved 37699976806_5ce694be36_k-horse.png Animal photos by Susanne Nilsson, on Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0).
  10. Demo: Object Identification and Image Segmentation with the Magic Cropping

    Tool https://developer.ibm.com/patterns/max-image-segmenter-magic-cropping-tool-web-app/
  11. Labeled Training Data Backpropagation Animal photos by Susanne Nilsson, on

    Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0). Output Errors Cat ❌ Not Cat ❌ Cat ❌ Cat Cat
  12. Input Neural Network Inferencing Output Cat Animal photos by Susanne

    Nilsson, on Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0).
  13. Neural Network Inferencing Output Not Cat Input Animal photos by

    Susanne Nilsson, on Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0).
  14. Machine Learning Libraries The Leeds Library by Michael D Beckwith,

    on Flickr <https://flic.kr/p/r6ip1G> (CC0 1.0).
  15. Goal & Context • Train a neural network to classify

    images of clothing • Classifications include dress, sneaker, etc. • We will use the Keras high-level API within TensorFlow https://www.tensorflow.org/tutorials/keras/basic_classification
  16. Fashion-MNIST • Training set of 60,000 article of clothing images

    • Test set of 10,000 examples can be used to evaluate image classification accuracy • Each example is a 28x28 grayscale image • Each example has an associated label from 10 classes (T-shirt/top, trouser, pullover, etc.) https://github.com/zalandoresearch/fashion-mnist
  17. Fashion-MNIST Image Labels Label Class 0 T-shirt/top 1 Trouser 2

    Pullover 3 Dress 4 Coat 5 Sandal 6 Shirt 7 Sneaker 8 Bag 9 Ankle boot https://github.com/zalandoresearch/fashion-mnist
  18. Import Libraries In [3]: # TensorFlow and tf.keras import tensorflow

    as tf from tensorflow import keras # Helper libraries import numpy as np import matplotlib.pyplot as plt print(tf.__version__) https://www.tensorflow.org/tutorials/keras/basic_classification
  19. Import Fashion-MNIST Dataset In [4]: fashion_mnist = keras.datasets.fashion_mnist (train_images, train_labels),

    (test_images, test_labels) = fashion_mnist.load_data() In [5]: class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat’, 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] https://www.tensorflow.org/tutorials/keras/basic_classification
  20. Explore the Data In [6]: train_images.shape Out[6]: (60000, 28, 28)

    In [7]: len(train_labels) Out[7]: 60000 In [8]: train_labels Out[8]: array([9, 0, 0, ..., 3, 0, 5], dtype=uint8) In [9]: test_images.shape Out[9]: (10000, 28, 28) In [10]: len(test_labels) Out[10]: 10000 https://www.tensorflow.org/tutorials/keras/basic_classification
  21. Preprocess the Data In [12]: train_images = train_images / 255.0

    test_images = test_images / 255.0 https://www.tensorflow.org/tutorials/keras/basic_classification
  22. Preprocess the Data In [13]: plt.figure(figsize=(10,10)) for i in range(25):

    plt.subplot(5,5,i+1) plt.xticks([]) plt.yticks([]) plt.grid(False) plt.imshow(train_images[i], cmap=plt.cm.binary) plt.xlabel(class_names[train_labels[i]]) plt.show() https://www.tensorflow.org/tutorials/keras/basic_classification
  23. Set Up the Model Layers In [14]: model = keras.Sequential([

    keras.layers.Flatten(input_shape=(28, 28)), keras.layers.Dense(128, activation=tf.nn.relu), keras.layers.Dense(10, activation=tf.nn.softmax) ]) https://www.tensorflow.org/tutorials/keras/basic_classification
  24. Train the Model Epoch 1/5 60000/60000 [==============================] - 4s 61us/step

    - loss: 0.4985 - acc: 0.8261 Epoch 2/5 60000/60000 [==============================] - 3s 54us/step - loss: 0.3747 - acc: 0.8646 Epoch 3/5 60000/60000 [==============================] - 4s 58us/step - loss: 0.3359 - acc: 0.8771 Epoch 4/5 60000/60000 [==============================] - 3s 55us/step - loss: 0.3123 - acc: 0.8846 Epoch 5/5 60000/60000 [==============================] - 4s 59us/step - loss: 0.2945 - acc: 0.8912 https://www.tensorflow.org/tutorials/keras/basic_classification
  25. Evaluate Accuracy In [17]: test_loss, test_acc = model.evaluate(test_images, test_labels) print('Test

    accuracy:', test_acc) https://www.tensorflow.org/tutorials/keras/basic_classification
  26. Make Predictions In [19]: predictions[0] Out[19]: array([9.6376725e-06, 4.5565642e-07, 5.0994299e-06, 4.8001135e-07,

    4.9554501e-06, 2.0314518e-02, 5.0287876e-05, 1.6105843e-01, 2.2055059e-04, 8.1833553e-01], dtype=float32) https://www.tensorflow.org/tutorials/keras/basic_classification
  27. Make Predictions In [20]: np.argmax(predictions[0]) Out[20]: 9 In [21]: test_labels[0]

    Out[21]: 9 https://www.tensorflow.org/tutorials/keras/basic_classification
  28. Applying Deep Learning Data Science Expertise Computing Resources High-Quality Training

    Data Model Deployment Time Model Integration Inferencing Code And more…
  29. Choose deployable model Deep Learning asset on MAX Deploy Swagger

    specification Inference endpoint Metadata endpoint Microservice Input pre-processing, model execution, and output post-processing Deploy model Use model https://developer.ibm.com/exchanges/models/
  30. Operating AI Systems Fabric for Deep Learning (FfDL) Train and

    deploy deep learning models on Kubernetes using TensorFlow, Caffe2, PyTorch, and other frameworks AI Fairness 360 (AIF360) Comprehensive set of fairness metrics for machine learning models, explanations for these metrics, and algorithms to mitigate bias in models Adversarial Robustness Toolbox (ART) Python library for adversarial attacks and defenses for neural networks with multiple framework support
  31. What will you build using deep learning? Dynamic Earth -

    Continental Shelf by NASA Goddard Space Flight Center, on Flickr <https://flic.kr/p/ch8t25> (CC BY 2.0).
  32. Resources: Machine Learning Libraries • TensorFlow https://www.tensorflow.org/ • Train your

    first neural network: basic classification | TensorFlow https://www.tensorflow.org/tutorials/keras/basic_classification • Keras https://keras.io/ • PyTorch https://pytorch.org/ • Caffe2 https://caffe2.ai/
  33. Resources: IBM Developer • IBM Cloud https://ibm.biz/Bd2A5f • Center for

    Open-Source Data & AI Technologies (CODAIT) http://codait.org/ • IBM Developer Model Asset Exchange (MAX) https://developer.ibm.com/exchanges/models/ • Model Asset Exchange (MAX) Code Patterns https://ibm.biz/max-developers • Deploy a deep learning-powered ‘Magic cropping tool’ https://developer.ibm.com/patterns/max-image-segmenter-magic-cropping-tool-web-app/ • !" magicat https://github.com/CODAIT/magicat
  34. Resources: Building and Training AI Models • Project Jupyter https://jupyter.org/

    • IBM Developer Model Asset Exchange (MAX) https://developer.ibm.com/exchanges/models/ • IBM Watson Studio https://www.ibm.com/cloud/watson-studio
  35. Resources: Deploying AI Models • Data Mining Group (PMML &

    PFA) http://dmg.org/ • ONNX https://onnx.ai/ • ONNX.js https://github.com/Microsoft/onnxjs • TensorFlow.js https://js.tensorflow.org/ • TensorFlow Lite https://www.tensorflow.org/lite • Core ML https://developer.apple.com/machine-learning/ • IBM Watson Machine Learning https://www.ibm.com/cloud/machine-learning
  36. Resources: Operating AI Systems • Fabric for Deep Learning (FfDL)

    https://github.com/IBM/FfDL • AI Fairness 360 (AIF360) https://github.com/IBM/AIF360 • Adversarial Robustness Toolbox (ART) https://github.com/IBM/adversarial-robustness-toolbox • IBM Watson OpenScale https://www.ibm.com/cloud/watson-openscale