Percept and AWS? A match made in heaven ;)

Deploy your own Cutting Edge Image Classification onto AWS

Harsh Sikka
ModelDepot
Published in
6 min readJun 12, 2018

--

Machine Learning forms the backbone of many interesting and powerful features in an amazing array of technology, and part of our mission over at ModelDepot is to help anybody leverage cutting edge ML with just a few lines of code.

Here, we’ll be deploying Percept, a state of the art Image Classification model that’s packaged into a handy docker container you can deploy on any infrastructure. The Percept container is located on Docker hub, and has the registry id modeldepot/percept. Hold onto that, because it’s going to come in handy when we deploy our task!

Deploying to AWS

Creating a Task

The first step necessary in order to deploy our model is the creation of a task that defines it. A task definition functions almost like a blueprint for our model deployment. In specifying a task definition, we inform ECS as to which Docker image to use for its containers, how many containers are going to be used in the task, and the specific resources that are to be allocated to each of those containers.

To set up a task, navigate over to your ECS console. On the left side you’ll see a menu that has Clusters, Task Definitions, and Repositories. Go ahead and click Task Definitions, we’ll come back to Clusters later. Now, you’re on the Task Definition Management page! Click on the big blue Create New Task Definition button, and lets start setting up our task.

First, we have to select our lunch type compatibility. You should see the following screen:

Go ahead and select EC2, because it allows us to manage our own infrastructure using AWS EC2, and it keeps costs low!

Now, after clicking next step, we get to the Configuration screen! Give your task a cool name, and keep the Task Role and Network Mode at their default values. Your form should look like this so far:

As you move downward, you can leave the Task Execution and Task Size sections on their defaults. Now, when you reach Container Definitions, click the Add Container button.

A popup out menu should jump out of the right side. Go ahead and give your container a name, and supply that registry id, modeldepot/percept, to the Image section. Map your port from 8000 to 8000, since that’s how our Percept Docker Container is configured, and set the protocol to tcp. Your screen should look something like this:

Awesome, lets scroll down and set up our HealthChecks and Environment. In the HealthChecks section, add the following command:

CMD-SHELL curl -f http://localhost:8000/ || exit 1

Set Interval, Timeout, Start Period, and Retries to 30,30,10, and 5 respectively.

In Environment, set an environmental variable MD_KEY. MD_KEY should be set to whatever key you were given when you registered for Percept.

Your HealthCheck and Environment screens should look as follows:

Great, we’re almost done with our task definition! Lets move over to Storage and Logging, and just check the box next to Auto-configure Cloudwatch Logs. Leave everything else as is, and hit the blue Add button!

Back on your task definition configuration screen, you should now see the following Container Definition:

Awesome, we’re just about done! Go head and click the Create button. If you see a green box on the next page that says Created Task Definition Successfully, you’re all set! Now lets set up a cluster to run our task on!

Configuring a Cluster:

Onto the home stretch! Now, we just have to configure the cluster that our ModelDepot tasks are going to run on. A cluster is really just a set of EC2 instances.

We’ll have to configure the name of the cluster, as well as the EC2 instance type. Keep the number of instances to 1 as well, so that we launch just a single instance for our cluster to sit on.

On the left side, click the Clusters tab. On the Clusters page, go ahead and click create Cluster.

Select EC2 Linux + Networking as our cluster template, and lets get this party started!

On the following screen, set a cluster name for your new cluster.

NOTE: If you’re really just playing around with deploying your cluster, you may want to opt for Spot pricing, where you can automatically bid for whatever the spare EC2 compute capacity is.

When selecting your instance type, go for at least c5.4xlarge, as it gives you more than enough resources to run your Percept container. ML can be resource intensive! The minimum requirements are 1gb of ram and 2 CPUs, if you’d like to look into your possible configuration options. Pick just 1 instance and leave everything else as is. On the bottom, configure your Security Group inbound rules to have a port range of 8000. Create a new instance IAM role if you don’t already have one.

Your screen should be looking similar to this:

Give your Cluster some time to spin up! After a few minutes, it should have 3/3 complete and 3 green boxes.

Final Step: Setup ECS Instances

Onto the last step of setup! We just have to set up some ECS instances for our cluster to run on, and configure scaling. Navigate to the same Clusters page that you went to create a new cluster initially. You should now see your new Cluster! Move into it and click the ECS instances tab. Go ahead and click the Scale ECS Instances button.

Now, wait for your instance to spin up. You can check its status by navigating to the EC2 console.

Run your Percept Task

Once everything is ready, navigate back to your cluster, click on tasks, and hit run new task! You should be presented with a form where you should specify EC2 as the launch type. Also select the task definition and cluster you just set up!

Your screen should look something like this:

Check out your newly deployed ModelDepot Image Classifier!

Once running, if you navigate back to the tasks section of your cluster, you should see a new task running. Awesome! Click into it and expand the percept task definition by clicking the little arrow next to it.

Grab the External Link, and navigate to it using your web browser! Congratulations, you’ve just seen your newly deployed Percept container. What you’re looking at is the deployed documentation and API explorer, which lets you sample and play with the REST api end points that Percept comes with out of the box. If you’re interested in learning how to train your own custom classes on Percept, head over here!

Interested in trying ModelDepot Percept? Get started for free here! If you have any questions, don’t hesitate to reach us via the in-site chat on the bottom right or via email at hi@modeldepot.io.

--

--

Harsh Sikka
ModelDepot

Grad Student at Harvard and Georgia Tech. Artificial Intelligence, Theoretical Neuroscience, Synthetic Biology, and generally cool stuff.