/// <summary> /// Used to update the retrained model. It first checks to ensure that the job completed successfuly. /// </summary> /// <param name="jobId"></param> /// <returns></returns> public async Task <Boolean> UpdateModel(string jobId) { BatchScoreStatus status; bool isUdpated = false; try { using (HttpClient client = new HttpClient()) { // Check the job string jobLocation = _mlretrainmodelurl + "/" + jobId + "?api-version=2.0"; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _mlretrainerkey); HttpResponseMessage response = await client.GetAsync(jobLocation); if (!response.IsSuccessStatusCode) { return(false); } status = await response.Content.ReadAsAsync <BatchScoreStatus>(); } AzureBlobDataReference res = status.Results["output2"]; isUdpated = await UpdateRetrainedModel(res.BaseLocation, res.RelativeLocation, res.SasBlobToken, _storageConnectionString); //isUdpated = await UpdateRetrainedModel2(res.BaseLocation, res.RelativeLocation, res.SasBlobToken, _storageConnectionString); return(isUdpated); } catch { return(false); } }
/// <summary> /// Used to setup the job retraining. You nust receive the jobID from this call and submit to the start method. This method only gets retraining /// ready but it MUST be started with the returned jobID after the sucessful completion of this call /// This will submit the default SQL Query pulled from the ML Storage container and use it unless it was nodified with other LIB calls /// </summary> /// <returns>This is a jobID used to then start the retraining job</returns> public async Task <string> QueueRetrainingAsync(TRAINING_DATA_SOURCE source, Dictionary <string, string> globalOptions) { string jobId = null; _currentModelTraining = retrainerPrefix + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss"); BatchExecutionRequest request = null; AzureBlobDataReference adr = null; if (source == TRAINING_DATA_SOURCE.DATA_UPLOAD && _trainingBlob == null) { throw new Exception("Training set not uploaded referenced"); } else if (source == TRAINING_DATA_SOURCE.DATA_UPLOAD && _trainingBlob != null) { adr = new AzureBlobDataReference() { ConnectionString = _storageConnectionString, RelativeLocation = _trainingBlob.Uri.LocalPath }; } //Now do outputs var outputs = new Dictionary <string, AzureBlobDataReference>() { { "output2", new AzureBlobDataReference() { ConnectionString = _storageConnectionString, RelativeLocation = string.Format("/{0}/{1}.ilearner", _mlstoragecontainer, _currentModelTraining) } }, { "output1", new AzureBlobDataReference() { ConnectionString = _storageConnectionString, RelativeLocation = string.Format("/{0}/{1}.csv", _mlstoragecontainer, _currentModelTraining) } }, }; //Now setup request object request = new BatchExecutionRequest() { Outputs = outputs }; if (globalOptions != null) { request.GlobalParameters = globalOptions; } else { request.GlobalParameters = new Dictionary <string, string>(); } if (adr != null) { request.Input = adr; } using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _mlretrainerkey); // WARNING: The 'await' statement below can result in a deadlock if you are calling this code from the UI thread of an ASP.Net application. // One way to address this would be to call ConfigureAwait(false) so that the execution does not attempt to resume on the original context. // For instance, replace code such as: // result = await DoSomeTask() // with the following: // result = await DoSomeTask().ConfigureAwait(false) // submit the job string uploadJobURL = _mlretrainmodelurl + "?api-version=2.0"; HttpResponseMessage response = await client.PostAsJsonAsync(uploadJobURL, request); if (!response.IsSuccessStatusCode) { return(null); } jobId = await response.Content.ReadAsAsync <string>(); //Used to reference the job for start and monitoring of completion } return(jobId); }