Trigger automation for dataset creation and training the model

The process of dataset is kicked off when a user creates a dataset custom object record. We will use trigger to call the scheduled job to the created dataset. To train the model, we will use the chaining series of scheduled Apex jobs. The following table lists the apex scheduled jobs and the working code link to the relevant git repository:

Apex class Name Description Github link to entire code
EinsteinVisionCreateDatasetScheduler This creates the dataset by uploading using the public URL. https://github.com/PacktPublishing/Learning-Salesforce-Einstein/blob/master/Chapter6/SalesforceEinsteinVision/src/classes/EinsteinVisionCreateDatasetScheduler.cls
EinsteinVisionGetStatusScheduler This job monitors the status of the dataset creation. It chains itself until the status of the data creation job is a either success or a failure. https://github.com/PacktPublishing/Learning-Salesforce-Einstein/blob/master/Chapter6/SalesforceEinsteinVision/src/classes/EinsteinVisionGetStatusScheduler.cls
EinsteinVisionTrainDatasetScheduler This kicks off the job to train the dataset and schedules the apex job to monitor the status of the training job. https://github.com/PacktPublishing/Learning-Salesforce-Einstein/blob/master/Chapter6/SalesforceEinsteinVision/src/classes/EinsteinVisionTrainDatasetScheduler.cls
EinsteinVisionGetTrainingStatusScheduler This monitors the status of the model training and stops once the status of success is reached. https://github.com/PacktPublishing/Learning-Salesforce-Einstein/blob/master/Chapter6/SalesforceEinsteinVision/src/classes/EinsteinVisionGetTrainingStatusScheduler.cls

The trigger code that automatically starts a scheduler is as follows:

    trigger TriggerOnEinsteinVisionDataset on 
Einstein_Vision_Dataset__c (after insert) {
//Not bulkified purposefully so that we only
trigger for individual records inserted via UI
//Use extreme caution if you plan to further bulkify this method
if(trigger.new[0].Status__c == 'STARTED'){
//Schedule the process of creating and training dataset
System.schedule('DatasetCreateJob', '0 '+
DateTime.now().addMinutes(2).minute()+' */1 ? * *', new
EinsteinVisionCreateDatasetScheduler(trigger.new[0].Id));
}
}


Note that trigger is not bulkified, and assuming that the user adds the records one by one, there is a single admin with a privilege to create the dataset record. You can use the permission sets to control the application access, tab access, and objects' CRUD (Create, Read, Update, and Delete) access.

The following flowchart shows the sequence of jobs:

As an administrator, once a dataset record is created, it will take some time to get modelId and the training status. Currently, jobs are scheduled to run every two minutes. The following screenshot shows the administrator screen once a model is completely trained and ready to use the model to ask for predictions:

Note that ModelId is shown in the preceding screenshot. As an administrator, you will need the ModelId for the smart image recognition lightning component that we are building in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset