Einstein Vision: How to Build AI-Powered Apps, Fast

Have you ever wondered how to use Salesforce Einstein to derive meaningful insights from your unstructured data, such as images and text data? Explore this example to learn how to integrate Einstein Platform Services into your CRM workflows to build AI-powered apps, fast.  

We at Altimetrik have built a hypothetical app called, Who am I?, using Einstein Platform Services. Who am I? uses Einstein Vision’s image recognition technology, specifically Einstein Image Classification, to recognize and discern content based on images across several industries within the Fortune 500. Let’s get started to see how it works on a simple example!

Gather Training Data

To get started with Einstein Image Classification, you’ll first need to create a training dataset with defined labels. Each folder will contain sample images that correspond to your training labels. Once you’ve gathered your training data, you can save then save it as a .zip file and  upload it to Dropbox before making an API call to the Einstein Vision API (cURL command).

Folder structure of a sample dataset

 

<div class=”cliformat”>

curl -X POST -H “Authorization: Bearer <TOKEN>” -H “Cache-Control: no-cache” -H “Content-Type: multipart/form-data” -F “type=image” -F “path=https://www.dropbox.com/s/abcdxyz/ImageRecognizerDataSet.zip?dl=1″ https://api.einstein.ai/v2/vision/datasets/upload/sync

</div>

The above command will return the newly created Dataset ID and Label IDs along with the Label Name and number of examples that correspond to each training label. The type parameter in the cURL command determines the model type and are as follows:

  • image
  • image-detection (available in Einstein Vision API version 2.0 and later)
  • image-multi-label (available in Einstein Vision API version 2.0 and later)

Train your Model

As mentioned, training your dataset requires making a simple API call. You can use the cURL command below (where “<DATASET_ID>” is the ID returned from the dataset creation):

<div class=”cliformat”>

curl -X POST -H “Authorization: Bearer <TOKEN>” -H “Cache-Control: no-cache” -H “Content-Type: multipart/form-data” -F “name=Image Recognizer Model” -F “datasetId=<DATASET_ID>” https://api.einstein.ai/v2/vision/train

</div>

1  {
2     “datasetID” : 1015839
3     “datasetVersionID” : 10263,
4     “name” : “Image Recognizer Model”,
5     “status” : “SUCCEEDED”,
6     “progress” : 1, 
7     “createdAT” : “2017-10-13T15 : 37 :17.000+0000”,
8     “updatedAT” : “2017-10-13T15 : 39 :06.000+0000”,
9     “learningRate” :0.001,
10    “epochs” : 3, 
11    “object” : “training”,
12    “modelID” : “3JAN7PUM5BZPA6t3DRDSDMMHJQ”,
13    “trainParams” :null, 
14    “trainStats” : {
15        “labels” :9, 
16        “example” :263,
17        “totalTime” : “00:01:43:224”,
18        “transforms” : {
19            “toFlip” : true,
20            “toRotate” : false,
21            “cropLocation” : “random”
22        } ,
23        “trainingTime” : “00:01:32:460”,
24        “earlyStopping” : false,
25        “lastEpochDone” : 3,
26        “modelSaveTime” :“00:00:02:925”,
27        “testSplitSize” : 32,
28        “trainSplitSize” : 231,
29        “datasetLoadTime” : “00:00:10:764”,
30        “preProcessStats” : null,
31        “postProcessStats” : null
32    } ,
33    “modelType” : “image”
34  }
Sample response of training status

Start Classifying Images

You can use the command below with the Model ID and image location to classify new images.

<div class=”cliformat”>

curl -X POST -H “Authorization: Bearer <TOKEN>” -H “Cache-Control: no-cache” -H “Content-Type: multipart/form-data” -F “sampleLocation=https://en.wikipedia.org/wiki/Maple#/media/File:Acer_pseudoplatanus_002.jpg” -F “modelId=<YOUR_MODEL_ID>” https://api.einstein.ai/v2/vision/predict

</div>

This command returns a prediction i.e. the probability that the new image falls within one of your defined labels.

And, because Who am I? is a mobile app, it’s optimized to make predictions from mobile images. The following is a sample callout for using data from mobile devices, as we know many customers, like us, prefer to build mobile first apps.

<div class=”cliformat”>

curl -X POST -H “Authorization: Bearer <TOKEN>” -H “Cache-Control: no-cache” -H “Content-Type: multipart/form-data” -F “sampleBase64Content=/9j/4AAQSkZ…” -F “modelId=YCQ4ZACEPJFGXZNRA6ERF3GL5E” https://api.einstein.ai/v2/vision/predict

</div>

Building AI-Powered Apps     

Now that you’ve trained your model, it’s time to see Einstein Image Classification in action.

  • Using your mobile phone, capture any image such as a picture of a leaf in this example:

  • Einstein Image Classification will then return the prediction with a probability range as seen in the image.
  • Looks like our app identified a mulberry leaf with 90% confidence!

After getting a basic app working, the next step is to embed Einstein Image Classification into your application workflows to create AI-powered apps for your business. If you want to learn more about how to integrate intelligence into your applications, make sure to attend the following sessions:

  • Test Automation and Continuous Integration in SDLC Using Salesforce DX, by Oscar Quintela, 1:00 PM to 1:40 PM at Moscone West 2009
  • Codeless Advanced Lightning Components, by Fernanda Vecino and Rodrigo Juliani, 3:00 PM to 3:40 PM at Moscone West 2009
  • Smart Lookups with Machine Learning, by Juan Bessonart and Diego Latierro, 2:15 PM to 2:35 PM at Moscone West, Developer Theater

 

 

Published
October 30, 2017
Topics:

Leave your comments...

Einstein Vision: How to Build AI-Powered Apps, Fast