Azure GPUs, Jupyter and Machine Learning

I’m a big advocate of the cloud and it’s ability to provide just enough resources ad hoc. You can use whatever you want, and pay for it just when using it. In machine learning there are services such as Google’s ML Engine or Azure’s upcoming Batch AI but during development, data preprocessing etc sometimes you want immediate iterative processes. In these cases, you can’t go past a Jupyter notebook and in this case, running that on a VM. In this post, I’ll outline how I’ve setup such an environment in Azure, focusing on ability to build it up and tear it down via the CLI and using a cheaper VM during development and an easy jumpt to then being able to run it on a GPU machine once things are running smoothly. ...

4 min · Damien Pontifex

Convert and using the MNIST dataset as TFRecords

TFRecords are TensorFlow’s native binary data format and is the recommended way to store your data for streaming data. Using the TFRecordReader is also a very convenient way to subsequently get these records into your model. The data We will use the well known MNIST dataset for handwritten digit recognition as a sample. This is easily retrieved from tensorflow via: from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets( "/tmp/tensorflow/mnist/input_data", reshape=False ) We then have mnist.validation, mnist.train and mnist.test data sets. ...

3 min · Damien Pontifex

Getting started with TensorFlow in Google ML Engine

In 2017, there seems no doubt that if you aren’t running your ML training on a GPU you just aren’t doing things right ?. At home, my only computer is my MacBook Pro which is great to develop on, but would take an extremely long time to train something such as an image classification task. Saying this, I’d love to have a GPU machine at home, but I also love the opportunity to use this hardware in the cloud without having to power it, upgrade it and generally take care of something you actually own. Thus I am lead to investigate using Google’s ML Engine to train my models. ...

4 min · Damien Pontifex

Image classification using TensorFlow estimators and TensorFlow Hub for transfer learning

This notebook is available as a codelab TensorFlow Hub was announced at TensorFlow Dev Summit 2018 and promises to reduce the effort required to use existing machine learning models and weights in your own custom model. From the overview page TensorFlow Hub is a library to foster the publication, discovery, and consumption of reusable parts of machine learning models. A module is a self-contained piece of a TensorFlow graph, along with its weights and assets, that can be reused across different tasks in a process known as transfer learning. ...

5 min · Damien Pontifex

Images with directories as labels for Tensorflow data

A common format for storing images and labels is a tree directory structure with the data directory containing a set of directories named by their label and each containing samples for said label. Often transfer learning that is used for image classification may provide data in this structure. Update May 2018: If you would like an approach that doesn’t prepare into TFRecords, utilising tf.data and reading directly from disk, I have done this in when making the input function for my Dogs vs Cats transfer learning classifier. ...

3 min · Damien Pontifex

Inspecting TFRecord files and debugging TensorFlow data input

TFrecord files are TensorFlow’s suggested data format, although they are very difficult to inspect given their binary nature. Inspecting the contents of existing record files and ensuring the data in your input pipeline is as you expect is a good technique to have. Inspecting TFRecord values The first trick is reading in the tfrecord files and inspecting their values in python. As you’d expect, the TensorFlow API allows this (although a little hidden down). The small code snippet below highlights using the tf.python_io.tf_record_iterator to inspect ’examples’ in your record file. Replace the ’label’ or ’text_label’ as appropriate for your features, but it shows you can dot access into the property values ...

2 min · Damien Pontifex

Machine Learning in Azure - Linear Regression

I recently completed Stanford Machine Learning on Coursera taught by Andrew Ng. It is a fantastic course for anyone interested, plus it’s free! The course uses MATLAB or Octave for the programming assignments. With the release of Azure Machine Learning, this seemed like a good exercise to reimplement these assignments on Azure ML to learn the tool. Creating an Azure ML Workspace To get started, you will need an Azure subscription. From the Azure Management Portal click ‘+ NEW’ from the lower left and create a workspace, and link to or create an associated storage account for use with the data. ...

4 min · Damien Pontifex

MNIST with Tensorflow Experiments and Estimators

An MNIST classifier is the go-to introduction for machine learning. Tensorflow is no different, and evolves to the Deep MNIST for Experts to include convolution, max pooling, dense layers and dropout: a good overview of ML layers for image problems. The downside of this is it doesn’t make use of Tensorflow’s new tf.estimator high level APIs. These provide all sorts of benefits for free than the usual sess.run TensorFlow tutorials you see online. The tf.estimator Quickstart gives a good reason to use it: ...

6 min · Damien Pontifex

My first Azure Batch AI Job

Azure Batch AI provides us the PaaS opportunity to use GPU resources in the cloud. The basis is to use virtual machines in a managed cluster (i.e. you don’t have to maintain them) and run jobs as you see fit. For my use case, the opportunity of low-priority VMs to reduce the cost of using GPU machines is also particularly promising. What I’ll run through is running our first job on Azure Batch AI. For setup, we’ll use the Azure CLI as I find it easier and quicker than using the UI portal. Saying that, everything can be achieved by point and click at portal.azure.com Assuming you already have the CLI installed and you are already logged in with it. ...

5 min · Damien Pontifex

Saving money on GPUs in Azure

Azure provides low priority VMs that we can use to save some money when utilising GPUs for machine learning. All the major cloud providers offer spare compute for a discount: Google cloud has Preemptible VMs, AWS has spot instances and Azure has low priority VMs. On Azure these low priority VMs can only be provisioned in Azure Batch or virtual machine scale sets and we can use the latter for hosting a jupyter environment. The low priority pricing is 23c/hour vs the normal $1.147/hour…a nice saving ...

3 min · Damien Pontifex