Source: Deep Learning on Medium
In the first part of this story, we discussed the overall architecture and how easy it is to do real-time data ingestion, processing and visualization with the architecture. Followed by the second part, we described big data analytics using Apache Spark, Zeppelin and Hive with FlashBlade. In this final part, we will talk about training and deploying a deep learning model, and use the model to detect dogs!
Train a Deep Learning Model
At the heart of our dog lovers AI, it is a deep learning model called YOLO for dog detection. YOLO (“you only look once”) is a popular model because it achieves high accuracy while also being able to run in real-time.
At a high level, steps to build a deep learning system includes:
- Collect large amount of data
- Label training data set
- Train, validate and tune model
- Deploy model
- Measure model performance, apply feedback and update model
Extract Dog Images from Tweets
We need a huge amount of data for training and testing deep learning model. Here I download dog images from Twitter API using NiFi.
This sub flow evaluates Twitter response, if there is an image in the tweet, NiFi invokes a HTTP request to download the image, and store it on FlashBlade NFS mount and also S3 bucket (for demo purpose).
I connect the Extract Images sub flow to the main flow on NiFi UI. I did it by dragging from the Pull Key Attributes processor to the Extract Images sub flow, then select “matched” relationship on the popup.
NiFi will start extracting images once we connected the flows. We can see images being stored in the FlashBlade NFS volume and S3 bucket. I open the S3 Viewer from Ambari to take a look at the downloaded dog images.
Train a Deep Learning Model
After obtained the data, we label the data and use labeled data to training a deep learning model. During the training process, the YOLO model tries to figure out what does a dog look like, by learning from huge amount of labelled data. We also validate the model and tune its performance (how accurately the model detects objects). This is normally a repeated process. How to label, train and validate a deep learning model is out of the scope of this article.
Training a YOLO model takes a very long time and requires a fairly large dataset of labelled bounding boxes for a large range of target object classes. In my Jupyter notebook, I load an pre-trained YOLO model and print its summary.
from keras.models import load_model, Model
yolo_model = load_model("model_data/yolo.h5")
This model has more than 62 millions parameters and that’s why we need GPU for massively parallel computing and FlashBlade for massively parallel I/O to accelerate the training to improve data scientists’ productivity.
Deploy a Deep Learning Model
We are satisfied with our model performance; we want to deploy it for dog detection. In production, we usually deploy a model as a REST API so that applications can easily access the API to integrate the model to detect objects.
Deploy a Model as REST API
I start a Python server to load the YOLO model and serve it through HTTP.
$ python yolo-server.py -cf ./cfg/yolov3.cfg -df ./cfg/coco.data -wf ./yolov3.weights -ud ./upload -pf true -H localhost
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32 0.299 BFLOPs
1 conv 64 3 x 3 / 2 416 x 416 x 32 -> 208 x 208 x 64 1.595 BFLOPs
103 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128 0.177 BFLOPs
104 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BFLOPs
105 conv 255 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BFLOPs
Loading weights from ./yolov3.weights…./cfg/yolov3.cfg
* Running on http://localhost:8080/ (Press CTRL+C to quit)
The API server will be listening on localhost:8080. We are ready to detect dogs from images. I run a script to send an image to the API server.
$ curl -XPOST -F file=@./hachi-a-dog-s-tale.jpg http://localhost:8080/detect
From the API response, the model tells me there is a dog and where it is (represented by the bounding box). The model is 98% confident of this detection. In the model predicted image on the right, a green box is drawn to surround the dog.
Deploy Model to The Edge
We can also deploy the model to an edge device such as a Raspberry Pi. Normally the edge device has not enough computing power, so we accelerate it with Intel Neural Compute Stick 2 or Google Edge Tensor Processing Unit. With this setup, we will be albe to detect dogs from live video in real-time.
I will have another blog to cover this topic.
So what does this all mean? It means that customers finally have an alternative to their data silos, and all the complexities that comes with managing them. Prior to FlashBlade, customer has to use siloed data systems for each stage in AI pipeline. Directed attached storage (DAS) HDD for data lake. Separated DAS HDD/SSD for streaming analytics. And HPC style storage for deep learning/GPU systems.
With FlashBlade, all of these applications can be consolidated to a single platform. Data can now be unified and shared across the applications that need them for better insight. On top of that, it is simple and elastic, allowing applications to spin up and down any resources as needed.
FlashBlade changes everything for customers.