Cloud AutoML Vision: Train your own machine learning model

Cloud AutoML Vision running on Macbook Machine learning (ML) is the sci-fi sounding concept of computers teaching themselves. In ML, you supply some data representing the type of content that you want the machine learning model to process automatically, and then the model teaches itself based on that data. Machine learning may be cutting-edge, but it also has a huge barrier to entry. If you want to use any kind of ML, then you’ll typically need to hire a machine learning expert or a data scientist, and both of these professions are currently in very high demand! Google’s Cloud AutoML Vision is a new machine learning service that aims to bring ML to the masses by making it possible to create a machine learning model, even if you have zero ML experience. Using Cloud AutoML Vision, you can create an image recognition model that’s capable of identifying content and patterns in photographs, and then use this model to process subsequent images automatically. This kind of visual-based ML can be used in lots of different ways. Want to create an app that provides information about a landmark, product or barcode the user is pointing their smartphone at? Or do you want to create a powerful search system that lets users filter thousands of products based on factors such as material, color, or style? Increasingly, machine learning is one of the most effective ways of delivering this kind of functionality. Although it’s still in beta, you can already use Cloud AutoML Vision to build custom machine learning models that identify patterns and content in photos. If you’re eager to discover what all the machine learning buzz is about, then in this article I’ll show you how to build your own image recognition model, and then use it process new photos automatically. Preparing your dataset Cloud AutoML Vision being announced When working with Cloud AutoML, you’ll use labeled photos as your datasets. You can use any photos or labels you like, but to help keep this tutorial straightforward I’ll be creating a simple model that can distinguish between photos of dogs, and photos of cats. Whatever the specifics of your model, the first step is sourcing some appropriate photos! Cloud AutoML Vision requires at least 10 images per label, or 50 for advanced models, for example models where they’ll be multiple labels per image. However, the more data you provide, the higher the model’s chances of correctly identifying subsequent content, so the AutoML Vision docs recommend that you use at least 100 examples per model. You should also provide roughly the same number of examples per label, as an unfair distribution will encourage the model to show bias towards the most “popular” category. For the best results, your training images should represent the variety of images that this model will encounter, for example you may need to include images taken at different angles, at higher and lower resolutions, and with different backgrounds. AutoML Vision accepts images in the following formats: JPEG, PNG, WEBP, GIF, BMP, TIFF, AND ICO, with a maximum file size of 30MB. Since we’re just experimenting with the Cloud AutoML Vision service, chances are you’ll want to create a dataset as quickly and easily as possible. To help keep things simple, I’ll be downloading a bunch of free stock photos of dogs and cats from Pexels, and then storing the cat and dog photos in separate folders, as this will make it easier to upload these photos later on. Note that when building datasets to use in production, you should take into account responsible AI Practices, to help prevent prejudicial treatment. For more information on this topic, check out Google’s Inclusive ML Guide and Responsible AI Practices documents. There’s three ways to upload your data to AutoMl Vision: Upload the images already sorted into folders that correspond to your labels. Import a CSV file that contains the images, plus their associated category labels. You can upload these photos from either your local computer, or from Google Cloud Storage. Upload your images using the Google Cloud AutoML Vision UI, and then apply labels to each image. This is the method I’ll be using in this tutorial. Claim your Google Cloud Platform free trial To use Cloud AutoML Vision, you’ll need a Google Cloud Platform (GCP) account. If you don’t have an account, then you can sign up for a 12 month free trial by heading over to the Try Cloud Platform for free page, and then following the instructions. You will need to enter your debit or credit card details, but according to the Free Tier FAQ, these are just used to verify your identity and you won’t be charged unless you upgrade to a paid account. The other requirement, is that you must enable billing for your AutoML project. If you’ve only just signed up for a free trial, or you don’t have any billing information associated with your GPC account, then: Head over to the GCP Console. Open the navigation menu (the lined icon in the upper-left corner of the screen). Select “Billing.” Open the “My Billing” dropdown menu, followed by “Manage billing accounts.” Select “Create account,” and then follow the onscreen instructions to create a billing profile. Create a new GCP project You’re now ready to create your first Cloud AutoML Vision project: Head over to the Manage resources page. Click “Create project.” Give your project a name, and then click “Create.” If you have multiple billing accounts, then GCP should ask which account you want to associate with this project. If you have a single billing account and you’re the billing administrator, then this account will be linked to your project automatically. Alternatively, you can select a billing account manually: Open the GCP Console’s navigation menu, and then select “Billing.” Select “Link a billing account.” Select “Set account,” and then choose the billing account that you want to associate with this project. Enable the Cloud AutoML and Storage APIs When creating your model, you’ll store all of your training images in a Cloud Storage bucket, so we need to enable the AutoML and Google Cloud Storage APIs: Open the GCP navigation menu and select “APIs & Services > Dashboard.” Click “Enable APIs and Services.” Start typing “Cloud AutoML API,” and then select it when it appears. Choose “Enable.” Navigate back to the “APIs & Services > Dashboard > Enable APIs and Services” screen. Start typing “Google Cloud Storage,” and select it when it appears. Choose “Enable.” Create a Cloud Storage bucket We’ll create our Cloud Storage bucket using Cloud Shell, which is an online, Linux-based virtual machine: Select the “Activate Google Cloud Shell” icon from the header bar (where the cursor is positioned in the following screenshot). Cloud AutoML Vision - activate shell A Cloud Shell session will now open along the bottom of the console. Wait while Google Cloud Shell connects to your project. Copy/paste the following command into Google Cloud Shell: PROJECT=$(gcloud config get-value project) && BUCKET="${PROJECT}-vcm" Press the “Enter” key on your keyboard. Copy/paste the next command into Google Cloud Shell: gsutil mb -p ${PROJECT} -c regional -l us-central1 gs://${BUCKET} Press the “Enter” key. Grant the AutoML Service permission to access your Google Cloud resources, by copy/pasting the following command, and then pressing the “Enter” key: PROJECT=$(gcloud config get-value project) gcloud projects add-iam-policy-binding $PROJECT \ --member="" \ --role="roles/ml.admin" gcloud projects add-iam-policy-binding $PROJECT \ --member="" \ --role="roles/storage.admin" Time to train: Building your dataset With this setup out of the way, we’re now ready to upload our dataset! This involves: Creating an empty dataset. Importing photos into the dataset. Assigning at least one label to each photo. AutoML Vision will completely ignore any photos that don’t have a label. To make the labelling process easier, I’m going to upload and label all my dog photos, before tackling the cat photos: Head over to the AutoML Vision UI (still in beta at the time of writing). Select “New Dataset.” Give your dataset a descriptive name. Click “Select files.” In the subsequent window, select all your dog photos, and then click “Open.” Since our images don’t have more than one label, we can leave “Enable multi-label classification” deselected. Click “Create Dataset.” Once the upload is complete, Cloud AutoML Vision UI will take you to a screen containing all your images, plus a breakdown of any labels you’ve applied to this dataset. Since our dataset currently only contains pictures of dogs, we can label them en masse: In the left-hand menu, select “Add label.” Type “dog,” and then hit the “Enter” key on your keyboard. Click “Select all images.” Open the “Label” dropdown, and choose “dog.” Cloud AutoML Vision UI Now we’ve labelled all our dog photos, it’s time to move onto the cat photos: Select “Add images” from the header bar. Choose “Upload from your computer.” Select all your cat photos, and then click “Open.” In the left-hand menu, select “Add label.” Type “cat” and then press the “Enter” key on your keyboard. Go through and select each cat photo, by hovering over the image and then clicking the little checkmark icon when it appears. Open the “Label” dropdown, and choose “Cat.” Training your machine learning model Now we have our dataset, it’s time to train our model! You receive one compute hour of free training per model for up to 10 models each month, which represents internal compute usage, and therefore may not correlate to an actual hour on the clock. To train your model, simply: Select AutoML Vision UI’s “Train” tab. Click “Start training.” The time it takes Cloud AutoML Vision to train your model will vary depending on the amount of data you’ve provided, although according to the official docs it should take around 10 minutes. Once your model has been trained, Cloud AutoML Vision will deploy it automatically, and send an email notifying you that your model is now ready to use. How accurate is your model? Before putting your model to the test, you may want to make some tweaks, to ensure its predictions are as accurate as possible. Select the “Evaluate” tab, and then select one of your filters from the left-hand menu. At this point, the AutoML Vision UI will display the following information for this label: Score threshold. This is the level of confidence the model must have, in order to assign a label to a new photo. You can use this slider to test the impact different thresholds will have on your dataset, by monitoring the results in the accompanying precision-recall graph. Lower thresholds mean your model will classify more images, but there’s an increased risk of it misidentifying photos. If the threshold is high, then your model will classify fewer images, but it should also misidentify fewer images. Average precision. This is how well your model performs across all score thresholds, with 1.0 being the maximum score. Precision. The higher the precision, the fewer false positives you should encounter, which is where the model applies the wrong label to an image. A high-precision model will label only the most relevant examples. Recall. Out of all the examples that should have been assigned a label, recall tells us how many of them were actually assigned a label. The higher the recall percentage, the fewer false negatives you should encounter, which is where the model fails to label an image. Put your model to the test! Now comes the fun part: checking whether your model can identify whether a photo contains a dog or a cat, by generating a prediction based on data that it hasn’t seen before. Grab a photo that wasn’t included in your original dataset. In the AutoML Vision Console, select the “Predict” tab. Select “Upload images.” Choose the image that you want AutoML Vision to analyze. After a few moments, your model will make its prediction – hopefully, it’s correct! Note that while Cloud AutoML vision is in beta, there may be a warmup delay with your model. If your request returns an error, then wait a few seconds before trying again. Wrapping up In this article, we looked at how you can use Cloud AutoML Vision to train and deploy a custom learning model. Do you think that tools such as AutoML have the potential to get more people using machine learning? Let us know in the comments below!

date: Wed, 22 Aug 2018 21:46:57 +0000