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.

8896271ee9d6f46d4b1783c9566cb645?s=128

Bradley Holt

March 14, 2019
Tweet

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. Is AI overhyped?

  3. Yes

  4. Thank you for coming to my talk

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

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

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

    <https://flic.kr/p/x5oWjP> (CC BY-SA 2.0).
  8. Deep Learning http://codait.org/

  9. Demo: Object Identification and Image Segmentation with magicat https://github.com/CODAIT/magicat

  10. https://github.com/CODAIT/magicat

  11. Install magicat $ npm install -g magicat + magicat@1.4.9 added

    255 packages from 209 contributors in 11.798s
  12. 23895621638_535be71dee_k.jpg 37038669284_899d7784a9_k.jpg 37489697170_31d05aa027_k.jpg 37699459356_24fd526a5e_k.jpg 37699976806_5ce694be36_k.jpg Animal photos by Susanne Nilsson,

    on Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0).
  13. 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.
  14. 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).
  15. 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).
  16. Demo: Object Identification and Image Segmentation with the Magic Cropping

    Tool https://developer.ibm.com/patterns/max-image-segmenter-magic-cropping-tool-web-app/
  17. https://developer.ibm.com/patterns/max-image-segmenter-magic-cropping-tool-web-app/

  18. None
  19. None
  20. Deep Learning Use Cases https://ibm.biz/max-developers

  21. Software Programming Untitled by Marcin Wichary, on Flickr <https://flic.kr/p/68Lhc9> (CC

    BY 2.0).
  22. 0101100100101100000110101101 0101001001100000110101101011 0110010010101010011101001011 0101010011100101010101010000 1010101011100000011010101010 1001000110000011010011010101 0010001011010101011101000101 Software Program Business

    Logic
  23. 0101100100101100000110101101 0101001001100000110101101011 0110010010101010011101001011 0101010011100101010101010000 1010101011100000011010101010 1001000110000011010011010101 0010001011010101011101000101 Software Program Input

    Program Execution Output
  24. Deep Learning

  25. Input Layer Hidden Layers Output Layer

  26. 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
  27. Input Neural Network Inferencing Output Cat Animal photos by Susanne

    Nilsson, on Flickr <https://www.flickr.com/photos/infomastern/> (CC BY-SA 2.0).
  28. 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).
  29. Machine Learning Libraries The Leeds Library by Michael D Beckwith,

    on Flickr <https://flic.kr/p/r6ip1G> (CC0 1.0).
  30. None
  31. None
  32. Demo: Basic Classification https://www.tensorflow.org/tutorials/keras/basic_classification

  33. 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
  34. 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
  35. Fashion-MNIST Images https://github.com/zalandoresearch/fashion-mnist

  36. 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
  37. https://jupyter.org/

  38. 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
  39. 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
  40. 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
  41. Preprocess the Data In [11]: plt.figure() plt.imshow(train_images[0]) plt.colorbar() plt.grid(False) plt.show()

    https://www.tensorflow.org/tutorials/keras/basic_classification
  42. 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
  43. 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
  44. https://www.tensorflow.org/tutorials/keras/basic_classification

  45. 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
  46. Compile the Model In [15]: model.compile(optimizer='adam’, loss='sparse_categorical_crossentropy’, metrics=['accuracy']) https://www.tensorflow.org/tutorials/keras/basic_classification

  47. Train the Model In [16]: model.fit(train_images, train_labels, epochs=5) https://www.tensorflow.org/tutorials/keras/basic_classification

  48. 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
  49. 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
  50. Evaluate Accuracy 10000/10000 [==============================] - 0s 26us/stepTest accuracy: 0.8748 https://www.tensorflow.org/tutorials/keras/basic_classification

  51. Make Predictions In [18]: predictions = model.predict(test_images) https://www.tensorflow.org/tutorials/keras/basic_classification

  52. 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
  53. 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
  54. https://www.tensorflow.org/tutorials/keras/basic_classification

  55. Applying Deep Learning Data Science Expertise Computing Resources High-Quality Training

    Data Model Deployment Time Model Integration Inferencing Code And more…
  56. Model Asset Exchange (MAX) Classify Generate Recognize https://developer.ibm.com/exchanges/models/

  57. 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/
  58. AI Lifecycle Deploy Operate Build & Train

  59. Building and Training AI Models Model Asset Exchange (MAX)

  60. None
  61. Deploying AI Models ONNX.js Model Asset Exchange (MAX)

  62. None
  63. 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
  64. None
  65. 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).
  66. 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/
  67. 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
  68. 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
  69. 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
  70. 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
  71. Thank you codait.org twitter.com/codait_datalab medium.com/ibm-watson-data-lab github.com/codait developer.ibm.com

  72. None