Everyone is doin’ em these days... Jupyter Notebooks. Between Google Colab, AWS Sagemaker Notebooks and now Microsoft Azure Notebooks, accessing the endearing, data-science-friendly development environment in the cloud has never been easier.
In previous posts, we’ve shown you how to train machine learning models on common cloud platforms and upload them to Skafos for mobile app deployment:
- Training Turi Create models in Google Colab
- Delivering ML to Mobile Apps with Skafos and AWS Sagemaker
In this third post, we will walk you through how to get started in Azure Notebooks and deploy models to the edge with Skafos.
Accessing Azure Notebooks
Microsoft provides a free training environment powered by Jupyter Notebooks/Labs where sharing and collaborating is central to the user experience. Because they’ve made it so easy to share projects with peers, we created a set of projects for you to explore. While this tool is still in “beta” mode, we’re excited about where it will go in the near future!
- First, log in (or create a free account) at https://notebooks.azure.com.
- Then checkout the list of Skafos projects at https://notebooks.azure.com/Skafos.
- You will see three example projects listed: Text Classification, Image Classification, and Object Detection. Some of you will recognize as the same three starter models from the Skafos dashboard and from our other blog posts.
- Click on whichever example you are most interested in. Once selected, hit the “clone” button near the top right. This will make a copy of this project and its resources just for you.
- Select “Free Compute” from the drop down list and then hit “Run on Free Compute” to launch the instance.
Training a Model
Once inside the Jupyter Lab environment, notice that there are three example notebooks you can choose between. If you want to follow along with this post, I will be using the
image-classification-examples project and the
At the time of writing this post Azure Notebooks don’t yet publicly support GPU training because it’s still in beta mode. Additionally, if the instance is slow or if dependencies aren’t properly installed, give it some time and restart the kernel.
Run through all of the cells prior to
Model Export and Skafos Upload, which cover the following:
- Importing the necessary Python libraries.
- Downloading photos of dogs and cats from a public S3 bucket and reading them into a data frame.
- Building an image classifier model using the Turi Create framework. If you are new to machine learning, it is a fantastic place to start!
Delivering your model using Skafos
At the end of all of this, you will have a model artifact that you can convert to Core ML, upload to Skafos, and deploy to an iOS app. Before proceeding, make sure you’ve taken the following steps:
- Sign up for a Skafos account
- On the dashboard, create an Example App. Once created, the integration guide will walk you through downloading our example image classification iOS app.
You now have the ability to tie this all together: a newly trained image classification model from an Azure Notebook and an iOS app that will use it.
Model Export and Upload
Back in the Jupyter Notebook, you need to convert the Turi Create model to CoreML format.
While other types of models can be used, CoreML is a solid starting point because Apple has made it SO easy to integrate them in your Xcode environment.
Next, import the Skafos Python SDK. With your API token, get a summary of all of the Skafos Apps and Models for which you have access. This will help you find where this model version needs to be uploaded.
You can find your existing API tokens, generate new ones, and revoke old ones on your account settings page. The summary JSON response will look something like:
Now that you have a token and summary of models, replace the org/app/model names below with your own. Check out this guide on best practices for setting up your dev environment when using the Python SDK.
Finally, navigate to your Skafos dashboard and verify that your new model is there!
Deploy this model (or any model) to your app by clicking the Deploy button. You will be presented with two environment groups: Dev or Prod. In your iOS app, the keys you set in the
AppDelegate.swift file dictate the environment from which models will be downloaded.
That’s it! You can do this as many times as you need to iterate on your model. You can upload to Skafos, deploy to Dev or Prod as needed, or roll back to older model versions if there’s an issue. No need to re-release through the App Store to get out model updates to your user base. Period.
Intrigued? Want to try this out? Here are some resources:
- A video tutorial on our YouTube Channel that walks you through a text classification example that has many steps similar to what we just did.
- Skafos documentation, including a list of FAQs, that provides more information about both functional architectures and tactical steps you can take to get ML into your apps.
- Our Slack channel. We love to chat with and help our users solve their problems. Come say hi and let us know what you are up to.
We’re excited to see what you build!