Building Your First Neural Network On The Cloud

Donal Byrne
Coinmonks
Published in
8 min readJul 9, 2018

--

In this article I am going to walk you through how to easily build an image classifier that can distinguish between 10 different pieces of clothing from the Fashion MNIST dataset. Not only that, but this will all be done by utilising the power of cloud computing. This article will go through all the steps to set up your own project on the cloud. If you want to skip straight to a fully working project, click on the link below and you will find the project already set up and ready to go!

Intro

Over the last few years we have seen an abundance of exciting use cases for neural networks ranging from generating content, talking to life like chat bots and beating the top human players at various games. This is an amazing time to be part of the rapidly growing world of AI. However unless you have access to your own high powered rig it can take a rediculously long time to train a network to acceptable standards. This can take anywhere between several hours to several days. Even with high spec hardware, the more impressive tasks can still take a long time.

If you are just starting out in the field its unlikely that you will want to invest in building your own custom machine with the necessary hardware. Luckily we don’t have to. The cloud provides the perfect ecosystem for AI to thrive in, allowing us to easily harness the necessary resources we need to get up and running quickly and efficiently. By the end of this article you should feel comfortable in running your own machine learning projects on the cloud!

What Platform To use?

Right now there are several options to chose from when it comes to picking a cloud provider. The 3 big names in cloud computing at the moment is of course Google, Amazon and Microsoft. Each of these provide powerful cloud platforms and infrastructures that can cater to all of your cloud needs. That sounds great, but they also come with a large learning curve (Some more than others). There is a lot of information to take in and if you are just starting out or need to quickly prototype an idea, its kind of overkill. Personally, I use a 4th Option called FloydHub for my own personal projects. FloydHub is a quick and simple cloud platform that lets you get up and running in no time. FloydHub is refered to as the Heroku of deep learning, and thats a great way of describing it. It essentially takes out all of the hassle of getting set up in the cloud and for this project that is what we are going to use.

Getting Setup

Ok so first things first, head over to FloydHub and create a free account. Once you are logged in, click on the projects tab and create a new project. You can also choose to use a FloydHub template which provides you with a starter template for various AI use cases such as Image classification and sentiment analysis. Once you create your project you need to create a workspace. This is where we will be working on our project. Click create workspace.

You will then be prompted to select how you want to initialise your project. You can either start it from scratch or import code from an existing GitHub repository. For now choose start from scratch

Next you need to select your environment and machine type. You can choose various types of environments that range from different versions of python, tensorflow and pytorch. For now choose tensorflow 1.7 for python 3. The machine type determines the specs of the hardware you will be using. The basic free account provides a standard single CPU which will suit our purposes. You can also purchase power ups that provides you with higher spec GPU’s and CPU’s. Power ups lets you purchase dedicated deep learning machines for an allocated number of hours based the package that best suits your needs.

Once you have finished picking your specs you will see a new workspace in your project. Click on it to be taken to where we will work on our code.

Navigating the Workspace

The workspace provides several UI features to help with your cloud development. On the top we can see the information about the workspace we are running. This includes the environment type, the machine type being used, the amount of time it has been running for, wether or not it is currently running and options to restart the workspace or shut it down entirely. Make sure you don’t leave your workspaces running idle! This will waste your CPU/GPU time and you wont be able to get it back.

To the left we have our folder directory with all our resources and files. The top bar of this section has options for creating and uploading new files/folders.

On the right we see a tab that lets us add a dataset to our workspace. We’ll talk more about this later.

Firstly, click the plus icon in the files directory on the left. This will give you the option to make a new python3 notebook. Name it what ever you like and we are almost ready to start coding.

Adding The Dataset

Before we can get our hands dirty we need to add a dataset to work with. You can download the Fashion MNIST dataset from Kaggle. Once you have the dataset on your local machine you can connect it to your FloydHub workspace. To do this we need to navigate back to the project page.

Go to Datasets, then click on New Dataset. Like with creating a new project, fill in the details. In this example I called my dataset fashion-mnist. Next we need to use some command line instructions. If you aren’t familiar with the command line I strongly suggest learning some of the common instructions such as cd and ls. It might seem a bit confusing at first but trust me, once you get the hang of it the command line makes things so much faster.

First we need to install the FloydHub CLI, this lets us use FloydHub commands in the terminal. Run the following:

$ pip3 install -U floydhub-cli

Once that’s done, log in to FloydHub with:

$ floyd loginLogin with your FloydHub username and password to run jobs.Username [alice]: alicePassword:Login Successful as alice

Enter your username and password and you will be good to go.

Next, navigate to the folder where you are storing your dataset. For example, I just downloaded the Fashion MNIST dataset, so my data will be in my downloads folder. To connect it, run the following commands in terminal

$ cd Downloads/fashionmnist$ floyd data init fashion-mnist$ floyd data upload

Our dataset is now connected to our FloydHub account. The last step is to add the new dataset to our project.

Navigate back to the workspace page. You can quickly do this from the main dashboard by clicking workspaces and finding your appropriate workspace. If you have stopped your workspace in the mean time, click resume to get it back up and running.

On the right hand side, under “Add Datasets” search for the dataset we just uploaded, fashion-mnist. As you can see from below, when you have selected your dataset, FloydHub shows you the url for where the data is stored in your workspace so you can easily access it.

We are now ready to begin coding!

Building the Project

On to the fun stuff. We are going to make a simple image classifier with keras. For those unfamiliar with keras it is a great library that provides a simple API that lets you quickly build neural networks. I am not going to go into detail on the specifics of the code as it will be covered in a later article, this is just to give you an example of building a project in FloydHub.

Import Libraries

Data Prep

Hyperparameters

Building The Network

Compilation & Training

Testing The Accuracy Of Our Model

Running The Project

Ok lets run our finished model and see how it performs.

After 10 epochs of training (~10 minutes) our model got a 91% accuracy on the test set! Thats pretty good, but we can do better. Try and play with the given code and see if you can increase the models accuracy. Change the hyperparameters, add more epochs or a lower learning rate. Take a look at the keras documentation and see if you can add some extra layers to our model to improve its accuracy. In the future I will be doing an article covering convolutional neural networks in detail. The full code and notebook can be found on my github

Its worth pointing out that if you were to run this with a GPU machine, instead of the basic CPU, it would run significantly faster. Running our projects on a GPU machine allows us to training for longer epochs, use more complex models and achieve better results.

Conclusion

Congratulations, you have successfully built your first neural network in the cloud!

In this article we learned:

  1. The power of utilising cloud computing for our ML projects
  2. How to set up your own project and add a custom dataset on FloydHub
  3. A quick run through of building an image classifier with keras on the cloud

I hope that you found this article usefull. If you have any questions, comments or feedback leave them below.

--

--

Donal Byrne
Coinmonks

Senior Research Engineer @InstaDeep, specialising in training large scale reinforcement learning agents. Currently hoping that the machines remember me fondly.