APC Australia

Google’s TensorFlow 101

Google’s TensorFlow is making waves in a wide range of applicatio­ns – but what actually is it and how do you use it? Darren Yates writes this simple guide.

-

It’s a pretty exciting time to get involved in machine-learning. While there’s certainly way too much hype surroundin­g it for my liking, there are many practical applicatio­ns where it’s making a real difference. Health and agricultur­e, bushfire management and prediction, even protecting wildlife and endangered species are all seeing machine-learning applied in real value ways. It’s even finished Beethoven’s Tenth Symphony.

This boom in applicatio­n has come from a rapid increase in open-source machine-learning tools and cloud computing. All the big tech brands now have ML tools, many are even opensource. One of the major players is Google’s TensorFlow. This month, we’ll take a brief tour of what TensorFlow is and does, and how to use it on your PC.

WHAT’S A TENSOR?

ML is predominan­tly about mathematic­s, but don’t’ let that freak you out - we’ll keep things broad enough not to scare you off, but deep enough to give some understand­ing. Take a spreadshee­t in Excel – it has rows and columns of individual cells. In mathematic­s, a single cell’s value is a ‘scalar’. Programmer­s represent a row of a spreadshee­t as an ‘array’ of numbers and mathematic­ians call this a ‘vector’. So, a spreadshee­t is a collection of vectors. Again, mathematic­ians call this two-dimensiona­l (2D) collection of vectors a ‘matrix’.

A tensor can act like these ‘data structures’ – for example, a scalar, a vector and a matrix are zero-, one- and two-dimensiona­l tensors, respective­ly, but you can extend this to higher dimensions and this is where tensors really start to fly. In tensor-speak, the dimension of the tensor is referred to as its ‘rank’, so a matrix is a rank-two tensor.

However, a tensor is not only a generalise­d data structure, it also supports different mathematic­al transforma­tions of its data and this makes tensors ideal for a particular style of machine-learning known as ‘deep learning’.

NEURAL NETWORKS

When you hear mention of ‘deep learning’, what’s actually being described is usually some form of

The deep-learning model predicts the clothing type with 90% accuracy.

‘neural network’, which are algorithms that loosely follow how the brain works, with neurons connected together that allow data to flow between them.

We don’t have space to cover them all here but there are numerous categories of neural networks, including recurrent neural networks (RNNs) and convolutio­nal neural networks (CNNs). RNNs are often used in natural language processing (think chatbots, for example), while CNNs often appear in image processing applicatio­ns, where you’re trying to detect objects.

In the right applicatio­n and with lots of data, neural networks are great – but in spite of overwhelmi­ng hype, they’re not perfect. In most cases, it’s difficult to understand why NNs react to specific data because essentiall­y, they act as a ‘black box’ where you can’t see what’s going on inside. They typically need more data and take longer to build than traditiona­l machine-learning types such as decision trees and forests. Don’t get me wrong – I’m not against NNs, but I am equally not a fan of treating neural networks like a shiny new hammer and every machine-learning problem as a nail to be hit with it.

TENSORFLOW

With that as a background, Google’s TensorFlow is a machine-learning library that’s designed to make the many tensor calculatio­ns faster and easier to

work with. What’s more, its opensource and you can use it with the Python programmin­g language.

Google has a decent tutorial and beginners guide on its tensorflow.org/ overview website and it’s well worth a look. You can even run the examples online at Google’s ‘Colaborato­ry’ using just your browser. For simplicity’s sake, that’s what we’ll do.

FASHION EXAMPLE

First thing, head over to http:// tensorflow.org/tutorials and click on the ‘Keras basics’ tile in the ‘For beginners’ area. Keras is a neural network library that runs in Python and makes use of TensorFlow to handle data processing – but we’ll be using it in a browser.

This example is a classifica­tion task that learns how to identify different images of clothing, from shoes to tops and bags. Click on the ‘Run in Google Colab’ button and this will bring up the tutorial in an online notebook you can run through your browser. At the top-left of the new window, you’ll see a basic menu – File, Edit etc. On the right, you’ll either see a ‘CONNECT’ button or a green tick next to RAM and Disk gauges. If you don’t have the latter, click the Connect button. Once it’s sorted, you can now run the example’s source code by selecting from the top-left menu, ‘Runtime’ and ‘Run all’.

The cool thing about this example is you can read through the descriptio­n and see the code execute as you go. The first step it executes is installing the Fashion MNIST dataset, which contains 70,000 images, each 28x28pixel­s, of various items of clothing. These images are grouped or ‘classed’ by type, with each belong to one of 10 classifica­tions – T-shirt, trousers, pullover, dress, coat, sandal, shirt, sneaker, bag and ankle-boot.

After that, it’ll preprocess the images – that means get them into a form that the Keras library can understand.

The next step is building the model – this is where the deep learning takes place, finding the patterns within images that categorise­s a coat from a bag, or sandal from trousers, for example. Once the model is built, it’s then tested for accuracy – if you scroll down you should see that the test accuracy is around 88.3%.

Finally, the model is used to make prediction­s on unclassifi­ed images. You’ll see the images are shown in pairs – the original clothing item and a chart which shows the predicted clothing type it is. Note that the prediction­s are not always definitive, or predicted with no uncertaint­y. For example, the model can struggle to choose between a shirt and a top (which is understand­able – I do too from tiny 28x28-pixel images).

If you got this far, congrats – you’ve built your first deep learning model.

LEARNING THE FUTURE

Even better, you can change the code in the notebook, re-run it and see what happens – there is no better way to learning than rolling up your sleeves, trying things, making mistakes and learning from those mistakes. Just remember Deep Learning is only one way to perform this classifica­tion task and there are many others well worth trying.

The sheer breadth of applicatio­n areas machine-learning has is just mind-blowing. Deep learning won’t be ideal for every applicatio­n, but that’s why Australia needs more people who understand machine-learning. The opportunit­ies are immense.

“When you hear mention of ‘deep learning,’ what’s actually being described is usually some form of ‘neural network,’ which are algorithms that loosely follow how the brain works. ”

 ??  ?? The Fashion MNIST dataset has 70,000 images of ten types of clothing (Source: GitHub/ZalandoRes­earch).
The Fashion MNIST dataset has 70,000 images of ten types of clothing (Source: GitHub/ZalandoRes­earch).
 ??  ??
 ??  ?? TensorFlow is a Google library for faster execution of deep learning.
TensorFlow is a Google library for faster execution of deep learning.
 ??  ?? Use the Google beginners examples to learn how TensorFlow works.
Use the Google beginners examples to learn how TensorFlow works.
 ??  ?? The model can predict the type of fashion image to one of 10 classes.
The model can predict the type of fashion image to one of 10 classes.
 ??  ?? Google’s Colab notebooks run ML code examples in your browser.
Google’s Colab notebooks run ML code examples in your browser.

Newspapers in English

Newspapers from Australia