//This method return the training accuracy for each of the parameters for the model by running the python script : train.py with these paramters private double TrainModelAndReturnAccuracy(double layers, double steps, double learningRate) { var pythones = new PythonExecutionService().GetAccuracy(layers, steps, learningRate); //Call the python function and get the accuracy return(pythones); }
public async Task <HttpResponseMessage> TestUserImage() { Dictionary <string, object> dict = new Dictionary <string, object>(); try { ModelService modelService = new ModelService(); var httpRequest = HttpContext.Current.Request; //Getting the GUID from the request var guid = httpRequest.Params["guid"]; var image = new MLApiImage(); try { if (!modelService.IsValidModelId(Guid.Parse(guid))) { var message = string.Format("The model is not available in the datamodel"); dict.Add("status", "failure"); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.NotFound, dict)); } image.ModelId = Guid.Parse(guid); } catch (Exception ex) { var message = string.Format("The GUID format is incorrect"); dict.Add("status", "failure"); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } foreach (string file in httpRequest.Files) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); var postedFile = httpRequest.Files[file]; if (postedFile != null && postedFile.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 1; //Size = 1 MB IList <string> AllowedFileExtensions = new List <string> { ".jpg", ".png" }; var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); //Checking for the compatible extensions if (!AllowedFileExtensions.Contains(extension)) { var message = string.Format("Please Upload image of type .jpg,.png."); dict.Add("status", "failure"); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } else if (postedFile.ContentLength > MaxContentLength) { var message = string.Format("Please Upload a file of size upto 1 mb."); dict.Add("status", "failure"); dict.Add("error", message); return(Request.CreateResponse(HttpStatusCode.BadRequest, dict)); } else { string pathToCreate = "~/Userimages/"; if (!Directory.Exists(HttpContext.Current.Server.MapPath(pathToCreate))) { //Now you know it is ok, create it Directory.CreateDirectory(HttpContext.Current.Server.MapPath(pathToCreate)); } var filePath = HttpContext.Current.Server.MapPath("~/Userimages/" + postedFile.FileName + extension); postedFile.SaveAs(filePath); image.ImagePath = filePath; } } var result = SaveImage(image); if (result.IsSuccessStatusCode) { var pythones = new PythonExecutionService().GetAccuracyForModel(image.ModelId ?? Guid.Empty); //Call the python function and get the accuracy dict.Clear(); dict.Add("status", "success"); dict.Add("message", new { Accuracy = pythones }); return(Request.CreateResponse(HttpStatusCode.OK, dict));; } else { return(result); } } var res = string.Format("No image found , please upload an image."); dict.Add("status", "failure"); dict.Add("error", res); return(Request.CreateResponse(HttpStatusCode.NotFound, dict)); } catch (Exception ex) { var res = string.Format($"Error Occurred in saving image {ex.Message}"); dict.Add("status", "failure"); dict.Add("error", res); return(Request.CreateResponse(HttpStatusCode.NotFound, dict)); } }