Git Product home page Git Product logo

msp-emea's Introduction

Rock Paper Scissors Lizard Spock: AI Edition

Microsoft EMEA Summit Workshop

Introduction

Everyone knows the game Rock Paper Scissors, but have you heard of Rock Paper Scissors Lizard Spock? This twist on the game became popular through the show the Big Bang Theory (Youtube clip).

Give the game a try for yourself: https://rockpaperscissorslizardspock.dev/!

Objective

Perhaps you noticed when visiting the above website that it is possible to play this game with your webcam! Wouldn't it be cool if we could build this ourselves?

In this workshop we will be using AI to automatically detect the hand gestures of the game. It is much easier than you think! Afterwards you can claim you used machine learning to train a convolutional neural network (CNN).

Training Data

For every machine learning model we need lots of good data to train the model on. To produce the best results for everyone here I need your help! Please visit this website to submit images: https://mspvision.azurewebsites.net/

What happened under the hood? We won't cover this in this workshop, but since you were curious: The JavaScript app sent images and tags to a serverless app hosted on Azure Functions. From there the images were stored in an Azure BlobStore Container for future processing. Additionally, images were directly uploaded to Azure Custom Vision. More details at https://github.com/leestott/MSP-EMEA/tree/master/rockpaperscissors and https://github.com/leestott/MSP-EMEA/tree/master/rockpaperscissorsapi

Training the Model

We log into the Azure Custom Vision Portal at https://customvision.ai You can see that all the images you submitted have already been tagged with labels. Now we can simply train a machine learning model with One button!

Testing the Model

Using the QuickTest feature we choose the latest training iteration and upload an image. Does the result look good? If not, let's get more images and train again!

Publishing the Model

Now we can publish the model. This allows us to export the model or consume it directly via a Prediction API.

Let's move to prediction in the cloud

Let's use the cloud based prediction API endpoint to determine the hand gesture in an image. Take a look at the simple code to do this: https://github.com/leestott/MSP-EMEA/tree/master/AzureCustomVision-Prediction

To run this app we must set a few environment variables.

# Change these to the value corresponding to your Custom Vision Service instance and project
export Prediction_Endpoint='https://rpscustomvision-prediction.cognitiveservices.azure.com/'
export Prediction_Key='XXXXXXXXXXXXXXXXXXXXXXXXXX'
export Project_Id='2861e073-dbfa-48f9-ae13-9c0e69ff4383' 
export Iteration_Name='v2'

This app is much faster!

Deploying the app to the cloud

Let's make the app available to everyone. Using Azure App Service we can easily publish this app. There are many ways but I prefer the Azure Command-Line Interface (CLI).

# F1 is the free tier!
# Choose a unique name like YOURCOOLNAME for your app, the app will be available at YOURCOOLNAME.azurewebsites.net
az webapp up --sku F1 -n rockpaperscissorslizardspock -l westus2

That command provided a bunch of information. Pay attention to the resource group name - we'll need that! We still need to inject our environment variables with the credentials into the app!

# -g is short hand for the resource group name
# -n is short hand for the name of the resource you are creating or modifying
az webapp config appsettings set -g beverst_rg_Linux_westus2 -n rockpaperscissorslizardspock --settings "Prediction_Key=XXXXXXXXXXXXXXXXXXX" "Prediction_Endpoint=https://rpscustomvision-prediction.cognitiveservices.azure.com/" "Project_Id=2861e073-dbfa-48f9-ae13-9c0e69ff4383" "Iteration_Name=v2"

For good measure let's restart the app.

az webapp restart -g beverst_rg_Linux_westus2 -n rockpaperscissorslizardspock

Now the app is available at https://rockpaperscissorslizardspock.azurewebsites.net

Spock

Live Long and Prosper!

Bonus

Exporting the Model for TensorFlow (Python)

We choose the export option and pick TensorFlow Android (it's confusing, I know!), then pick TensorFlow. Once ready we'll download a zip file containing two important files. Our tags (labels.txt) and our model (model.pb).

Note that there are many more choices for exporting the model.

Making prediction with the exported model in TensorFlow (Python)

This is a great option if you want to include the exported model on a device with no internet connection, or perhaps want to minimize latency but at the cost of increased CPU and Memory requirements.

We'll review this project that has the finished code for serving a TensorFlow based API that makes predictions using our ML model: https://github.com/berndverst/AzureCustomVision-TensorFlowImageClassification

References & Resources

Azure:

Documentation:

Github repos:

msp-emea's People

Contributors

leestott avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.