Moving to AWS
Support the site!
You can also support LearningTensorFlow.com by becoming a patron at Patreon. If we have saved you trawling through heavy documentation, or given you a pointer on where to go next, help us to create new lessons and keep the site running.
In a lot of cases running code can be quite time consuming, especially if you are doing machine learning or anything to do with neural networks. Unless you have spent a large amount of money on your machine, going to a cloud based service might be the best way to go.
In this tutorial we are going to take some Tensorflow code and move it to a Amazon web service, (AWS) Elastic Compute Cloud instance (EC2).
Amazon Web Services (AWS) is a secure cloud services platform, which offers compute power, database storage, content delivery and other functionality to help businesses scale and grow. Additionally, Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers.
The advantage to this is, Amazon have a huge selection of cloud based servers with a lot of power behind them. This will allow you to run your code over the web in half the time you would be able to run it from your local machine. It also means that if it is a massive file that is going to take 5 - 8 hours to run, you can run it on the EC2 instance and leave it in the background without using your whole computers resources.
For prices visit this link
Creating an EC2 instances
To start with, go to the AWS console at:
Log in with your Amazon account. If you don’t have one, you will be prompted to create one, which you will need to do in order to continue.
Next, go to the EC2 service console at: https://console.aws.amazon.com/ec2/v2/home?region=us-east-1.
Click on Launch Instance and choose your local region(i.e sydney, N california) as your location in the drop-down menu at the top-right.
Next go to community AMIs and search Ubuntu x64 AMI with TensorFlow (GPU), this is ready to run code via the GPU but it is also more then enough to run your basic or big Tensorflow scripts on it, and the great part is Tensorflow is already installed.
You’ll be prompted with some information on how to connect to your instance. If you haven’t used AWS before, you will probably need to create a new key pair to securely connect to your instance. In this case, give your key pair a name, download the pemfile, and store it in a safe place—if lost, you will not be able to connect to your instance again!
Click on Connect for information on using the pem file to connect to your instance. The most likely scenario is that you will use ssh with the following command:
ssh -i <certificante_name>.pem ubuntu@<server_ip_address>
Moving your code to AWS EC2
We will use this following example to move on to our EC2 instance, which is from our convergence lesson
There are many ways to get this file onto your EC2 instance, but one of the easiest is to just copy-and-paste the contents.
To start with, highlight all of the above code by pressing ctrl + A and then copy all of the code with ctrl + C
On the Amazon Virtual Machine, move to the home directory and open nano with a new filename, which we will call basic.py for this example: (The following are terminal commands)
$ nano <nameofscript>.py
The nano program will open, which is a command-line text editor.
With this program open, paste the contents of your clipboard into this file. On some systems, you may need to use a file option of the ssh program, rather than pressing Ctrl+ V to paste. In nano, press Ctrl+ O to save the file on the disk, which we called basic.py and then Ctrl+ X to exit the program.
Once you have exited nano, type in python basic.py and you’re done!
You should now see the result of the code pop up in the terminal, as you could most likely see this could be a much better way of doing large data programs.
Facenet is a Face recognition programing which utilizes Tensorflow, it offers pre-trained models for you to download and run to see how it works.
1) go to this link and download a pre-trained face recognition model
2) Using the above tutorial, Upload the code to the EC2 instances and get it running
We have an increasing set of lessons that we hope guides you through learning this powerful library. Follow these links to keep going to our next lesson.
You can also use the nav menu at the top of the page to go directly to a specific lesson.
Coming soon (although not written by us):