public List <BoundingBox> DetectObjectsUsingModel(ImageInputData imageInputData) { var labels = customVisionPredictionEngine?.Predict(imageInputData).PredictedLabels ?? tinyYoloPredictionEngine?.Predict(imageInputData).PredictedLabels; var boundingBoxes = outputParser.ParseOutputs(labels); var filteredBoxes = outputParser.FilterBoundingBoxes(boundingBoxes, 5, 0.5f); return(filteredBoxes); }
private List <BoundingBox> DetectObjectsUsingModel(ImageInputData imageInputData) { var labels = fasterRCNNPredictionEngine?.Predict(imageInputData).PredictedLabels ?? fasterRCNNPredictionEngine?.Predict(imageInputData).PredictedLabels; var boundingBoxes = outputParser.ParseOutputs(labels); var filteredBoxes = outputParser.FilterBoundingBoxes(boundingBoxes, 5, 0.5f); return(filteredBoxes); }
public string Predict(InputData input) { var result = prediction.Predict(input); var maxScore = result.Score.Max(); Console.WriteLine(result.ToString()); Console.WriteLine(maxScore); if (maxScore > 0.7) { return("Predicted : " + labels[Array.IndexOf(result.Score, maxScore)] + Environment.NewLine + "Confidence : " + maxScore.ToString()); } else { return(null); } }
public string GetIntention() { Comment comment = new Comment() { ID = "0", Contents = RawContents }; var prediction = _intentionPredEngine.Predict(comment); if (prediction.Intention.Contains("-")) { return("que va a ocurrir"); } else { return("que ya ocurrió"); } }
public async Task <bool> DetectAsync(string fileName) { try { var imgPath = Path.Combine(_environment.ContentRootPath, "image", fileName); var imageToPredict = new ImageData(System.IO.File.ReadAllBytes(imgPath), "", imgPath); var prediction = await Task.Run(() => mlEngine.Predict(imageToPredict)); return(prediction.PredictedLabel == "3310"); } catch (Exception ex) { throw; } }
public static void ClassifySingleImage(MLContext mlContext, IDataView data, ITransformer trainedModel) { PredictionEngine <ModelInput, ModelOutput> predictionEngine = mlContext.Model.CreatePredictionEngine <ModelInput, ModelOutput>(trainedModel); ModelInput image = mlContext.Data.CreateEnumerable <ModelInput>(data, reuseRowObject: true).First(); ModelOutput prediction = predictionEngine.Predict(image); //prediction = predictionEngine.Predict(new ModelInput() //{ // Image = File.ReadAllBytes("<your image path>"), // LabelAsKey = 1000, // ImagePath = "<your image path", // Label = "Image name" //}); Console.WriteLine("Classifying single image"); OutputPrediction(prediction); }
public string GetIrony() { Comment comment = new Comment() { ID = "0", Contents = RawContents }; var prediction = _ironyPredEngine.Predict(comment); if (prediction.Irony.Contains("-")) { return("literal"); } else { return("irónico"); } }
public static string Predict(GitHubIssue issue, ILogger logger, double threshold) { if (predEngine == null) { MLContext mlContext = new MLContext(); ITransformer mlModel = mlContext.Model.Load(ModelPath, out DataViewSchema inputSchema); predEngine = mlContext.Model.CreatePredictionEngine <GitHubIssue, GitHubIssuePrediction>(mlModel); } GitHubIssuePrediction prediction = predEngine.Predict(issue); float[] probabilities = prediction.Score; float maxProbability = probabilities.Max(); logger.LogInformation($"# {maxProbability.ToString()} {prediction.Area} for #{issue.Number} {issue.Title}"); return(maxProbability > threshold ? prediction.Area : null); }
static void Main(string[] args) { MLContext mlContext = new MLContext(); // Load model ITransformer mlModel = mlContext.Model.Load(ModelPath, out _); PredictionEngine <ModelInput, ModelOutput> predEngine = mlContext.Model.CreatePredictionEngine <ModelInput, ModelOutput>(mlModel); ModelInput modelInput = new ModelInput { SentimentText = "HIGHLIGHTS VIDEO ON YOUTUBE" }; ModelOutput modelOutput = predEngine.Predict(modelInput); Console.WriteLine(modelOutput.Prediction); }
private static void UseModelWithSingleItem(MLContext mlContext, ITransformer model) { PredictionEngine <SentimentData, SentimentPrediction> predictionFunction = model.CreatePredictionEngine <SentimentData, SentimentPrediction>(mlContext); // The Predict() function makes a prediction on a single row of data. var res = predictionFunction.Predict(new SentimentData() { SentimentText = "This was a very bad steak" }); Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ==============="); Console.WriteLine($"Prediction {res.Prediction}"); Console.WriteLine("=============== End of Predictions ==============="); Console.WriteLine(); }
public static IEstimator<ITransformer> BuildAndTrainModel(IDataView trainingDataView, IEstimator<ITransformer> pipeline) { var trainingPipline = pipeline.Append(_mLContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features")) .Append(_mLContext.Transforms.Conversion.MapKeyToValue("PredictedLabel")); _trainedmodel = trainingPipline.Fit(trainingDataView); _predEngine = _mLContext.Model.CreatePredictionEngine<Sentiment_Analysis, Sentiments>(_trainedmodel); Sentiment_Analysis se = new Sentiment_Analysis() { Phrase = //"This terms candidates are very normal" "This website sucks" }; var prediction = _predEngine.Predict(se); Console.WriteLine($"single line prediction { prediction.Sentiment}"); return trainingPipline; }
private static void UseModelWithSingleItem(MLContext mlContext, ITransformer model, string sentimentText) { PredictionEngine <SentimentData, SentimentPrediction> predictionFunction = model.CreatePredictionEngine <SentimentData, SentimentPrediction>(mlContext); SentimentData sampleStatement = new SentimentData { SentimentText = sentimentText }; var resultprediction = predictionFunction.Predict(sampleStatement); Console.WriteLine(); Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ==============="); Console.WriteLine($"Sentiment: {sampleStatement.SentimentText} | Prediction: {(Convert.ToBoolean(resultprediction.Prediction) ? "Positive" : "Negative")} | Probability: {resultprediction.Probability} "); Console.WriteLine("=============== End of Predictions ==============="); Console.WriteLine(); }
public Action Decide(RangeBarModel bar, double inventoryAbsolute) { if (bar.TimestampDiffMs < (1000 * 60 * 1)) { // to fast bar, not executable return(Action.Nothing); } var convertedBar = new RangeBar(); convertedBar.VolumeRate = ComputeRate(bar.BuyVolume, bar.SellVolume); convertedBar.CountRate = ComputeRate(bar.BuyCount, bar.SellCount); convertedBar.ChangeRate = ComputeRate(bar.PriceChangedUpCount, bar.PriceChangedDownCount); convertedBar.InsertedRate = ComputeRate(bar.ObInsertedCountBid, bar.ObInsertedCountAsk); convertedBar.UpdatedRate = ComputeRate(bar.ObUpdatedCountBid, bar.ObUpdatedCountAsk); convertedBar.DeletedRate = ComputeRate(bar.ObDeletedCountBid, bar.ObDeletedCountAsk); if (_prevBar != null) { convertedBar.MidPrev = (float)_prevBar.CurrentPrice; convertedBar.MidChangePrev = (float)(bar.CurrentPrice - _prevBar.CurrentPrice); } var prediction = _predictionEngine.Predict(convertedBar); //if (Math.Abs(prediction.Score) < 0.5) // return Action.Nothing; _prevBar = bar; if (!string.IsNullOrWhiteSpace(prediction.Prediction)) { if (prediction.Prediction == "1") { return(Action.Sell); } return(Action.Buy); } if (prediction.Direction) { return(Action.Buy); } return(Action.Sell); }
static void Main(string[] args) { IEnumerable <Sentimento> sentimentDatas = new List <Sentimento> { new Sentimento { SePositivo = true, Comentario = "muito bom" }, new Sentimento { SePositivo = true, Comentario = "gostei disso" }, new Sentimento { SePositivo = true, Comentario = "gostei do que vocês fizeram" }, new Sentimento { SePositivo = true, Comentario = "bom trabalho" }, new Sentimento { SePositivo = false, Comentario = "não gostei" }, new Sentimento { SePositivo = false, Comentario = "muito ruim" } }; MLContext mlContext = new MLContext(seed: 0); IDataView dataView = mlContext.Data.LoadFromEnumerable(sentimentDatas); TrainTestData splitDataView = mlContext.Data.TrainTestSplit(dataView, testFraction: 0.2); var estimator = mlContext.Transforms.Text.FeaturizeText (outputColumnName: "Features", inputColumnName: nameof(Sentimento.Comentario)) .Append(mlContext.BinaryClassification.Trainers.SdcaLogisticRegression (labelColumnName: "Label", featureColumnName: "Features")); var model = estimator.Fit(splitDataView.TrainSet); PredictionEngine <Sentimento, PredicacaoDeSentimento> predictionFunction = mlContext.Model.CreatePredictionEngine <Sentimento, PredicacaoDeSentimento>(model); Sentimento sampleStatement = new Sentimento { Comentario = "tá bom" }; var resultPrediction = predictionFunction.Predict(sampleStatement); Console.WriteLine(resultPrediction.Predicao); Console.ReadKey(); }
public static IEstimator <ITransformer> BuildAndTrainModel(IDataView trainingDataView, IEstimator <ITransformer> pipeline) { var trainingPipeline = pipeline.Append(_mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features")) .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel")); _trainedModel = trainingPipeline.Fit(trainingDataView); _predEngine = _mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(_trainedModel); GitHubIssue issue = new GitHubIssue() { Title = "WebSockets communication is slow in my machine", Description = "The WebSckets ommunication used under the covers by SignalR looks like is going slow in my development machine.." }; var prediction = _predEngine.Predict(issue); Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ==============="); return(trainingPipeline); }
private static void UseModelWithSingleItem(MLContext mlContext, ITransformer model) { PredictionEngine <SpamData, SpamPrediction> predictionFunction = model.CreatePredictionEngine <SpamData, SpamPrediction>(mlContext); SpamData sampleStatement = new SpamData() { SpamText = "hahahahaha 08702840625.COMUK. dfdf-fdfdf dfdfdfdfdfdfdf" }; var resultprediction = predictionFunction.Predict(sampleStatement); Console.WriteLine(); Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ==============="); Console.WriteLine(); Console.WriteLine($"Spam: {sampleStatement.SpamText} | Prediction: {(Convert.ToBoolean(resultprediction.Prediction) ? "Spam" : "Ham")} | Probability: {resultprediction.Probability} "); Console.WriteLine("=============== End of Predictions ==============="); Console.WriteLine(); }
public void Prediction() { // check if a given user likes 'GoldenEye' Console.WriteLine("Calculating the score for user 6 liking the movie 'GoldenEye'..."); PredictionEngine = _mlContext.Model .CreatePredictionEngine <Like, PostRatingPrediction>(Model); var prediction = PredictionEngine.Predict( new Like { UserId = 1, PostId = 1 // GoldenEye } ); Console.WriteLine($" Score: {prediction.Score}"); }
public static void TestSinglePrediction(MLContext mlContext) { SentimentIssue sampleStatement = new SentimentIssue { Text = "This is a very rude movie" }; ITransformer trainedModel = mlContext.Model.Load(ModelPath, out DataViewSchema modelInputSchema); // Create prediction engine related to the loaded trained model PredictionEngine <SentimentIssue, SentimentPrediction> predictionEngine = mlContext.Model.CreatePredictionEngine <SentimentIssue, SentimentPrediction>(trainedModel); //Score SentimentPrediction resultPrediction = predictionEngine.Predict(sampleStatement); Console.WriteLine($"=============== Single Prediction ==============="); Console.WriteLine($"Text: {sampleStatement.Text} | Prediction: {(Convert.ToBoolean(resultPrediction.Prediction) ? "Toxic" : "Non Toxic")} sentiment | Probability of being toxic: {resultPrediction.Probability} "); Console.WriteLine($"=================================================="); }
public static void UseModelWithSingleItem2(MLContext mlContext, ITransformer model, string text) { PredictionEngine <SentimentData, SentimentPrediction> predictionFunction = mlContext.Model.CreatePredictionEngine <SentimentData, SentimentPrediction>(model); SentimentData sentiment = new SentimentData { SentimentText = text, }; var resultPrediction = predictionFunction.Predict(sentiment); Console.WriteLine(); Console.WriteLine($"Sentiment: {resultPrediction.SentimentText} | Prediction: {(Convert.ToBoolean(resultPrediction.Prediction) ? "Positive" : "Negative")} | Probability: {resultPrediction.Probability} "); Console.WriteLine("=============== End of Predictions ==============="); Console.WriteLine(); }
private static List <SentimentModel> UseModelWithSingleItem(MLContext mlContext, ITransformer model, List <SentimentData> dataModelList) { var sentimentDataResult = new List <SentimentModel>(); PredictionEngine <SentimentData, SentimentPrediction> predictionFunction = mlContext.Model.CreatePredictionEngine <SentimentData, SentimentPrediction>(model); foreach (var dataModel in dataModelList) { var resultPrediction = predictionFunction.Predict(dataModel); var tempSentimentModel = new SentimentModel { Text = resultPrediction.SentimentText, Location = resultPrediction.Location, SentimentValue = resultPrediction.Probability }; sentimentDataResult.Add(tempSentimentModel); } return(sentimentDataResult); }
public static string PredictGrade( string inspectionType, string violationCodes, int criticalFlag, int inspectionScore) { ModelInput input = new ModelInput { InspectionType = inspectionType, Codes = violationCodes, CriticalFlag = (float)criticalFlag, InspectionScore = (float)inspectionScore }; ModelOutput prediction = _predictionEngine.Predict(input); return(prediction.PredictedLabel); }
private static void PredictIssue() { ITransformer loadedModel; using (var stream = new FileStream(_modelPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { loadedModel = _mlContext.Model.Load(stream); } GitHubIssue singleIssue = new GitHubIssue() { Title = "Entity Framework crashes", Description = "When connecting to the database, EF is crashing" }; _predEngine = loadedModel.CreatePredictionEngine <GitHubIssue, IssuePrediction>(_mlContext); var prediction = _predEngine.Predict(singleIssue); Console.WriteLine($"=============== Single Prediction - Result: {prediction.Area} ==============="); }
private EstimatorChain <KeyToValueMappingTransformer> BuildAndTrainModel(IDataView trainingDataView, EstimatorChain <ITransformer> pipeline) { var trainer = new SdcaMultiClassTrainer(_mlContext, DefaultColumnNames.Label, DefaultColumnNames.Features); var trainingPipeline = pipeline.Append(trainer) .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel")); _trainedModel = trainingPipeline.Fit(trainingDataView); _predEngine = _trainedModel.CreatePredictionEngine <ConformChecker, CheckerPrediction>(_mlContext); var conf = new ConformChecker { Name = "Электронный аукцион" }; var prediction = _predEngine.Predict(conf); SaveModelAsFile(_mlContext, _trainedModel); return(trainingPipeline); }
public ActionResult <string> Get(string id) { var _mlContext = new MLContext(seed: 0); ITransformer _trainedModel = _mlContext.Model.Load("model.zip", out DataViewSchema inputSchema); PredictionEngine <ConversationInput, SentenceClassifiedOutput> _predEngine = _mlContext.Model.CreatePredictionEngine <ConversationInput, SentenceClassifiedOutput>(_trainedModel); ConversationInput issue = new ConversationInput() { Description = id }; var prediction = _predEngine.Predict(issue); if (prediction.Area.Contains("Question")) { return("true"); } return("false"); }
private static void UseModelWithSingleItemMulti(MLContext mlContext, ITransformer model) { PredictionEngine <SentimentData, SentimentPredictionMulti> predictionFunction = mlContext.Model.CreatePredictionEngine <SentimentData, SentimentPredictionMulti>(model); SentimentData sampleStatement = new SentimentData { SentimentText = "This show is great" }; var resultPrediction = predictionFunction.Predict(sampleStatement); Console.WriteLine(); Console.WriteLine("=============== Prediction Test of model with a single sample and test dataset ==============="); Console.WriteLine(); Console.WriteLine($"Sentiment: {resultPrediction.SentimentText} | Prediction: {(Convert.ToBoolean(resultPrediction.Prediction) ? "Positive" : "Negative")} "); Console.WriteLine("=============== End of Predictions ==============="); Console.WriteLine(); }
public FfmRecommendationPrediction Predict(FfmRecommendationData recommendationData) { if (_predictionEngine == null) { return(null); } // Single prediction var recommendationPrediction = _predictionEngine.Predict(recommendationData); if (!recommendationPrediction.PredictedLabel) { // Reverse probability if not recommended. recommendationPrediction.Probability = recommendationPrediction.Probability * -1; } return(recommendationPrediction); }
// =========================================================================================================== public IList <ActualVsPredicted> AssessModel(bool useTestingData) { var response = new List <ActualVsPredicted>(); if (ErrorHasOccured) { return(response); } if (useTestingData) { if (_testingDataView == null) { return(response); } } else { if (_trainingDataView == null) { return(response); } } PredictionEngine <ModelInput, ModelOutput> predictionEngine = _mlContext.Model.CreatePredictionEngine <ModelInput, ModelOutput>(_mlModel); IEnumerable <ModelInput> samplesForPrediction = (useTestingData) ? _mlContext.Data.CreateEnumerable <ModelInput>(_testingDataView, false) : _mlContext.Data.CreateEnumerable <ModelInput>(_trainingDataView, false); foreach (var singleRow in samplesForPrediction) { ModelOutput predictionResult = predictionEngine.Predict(singleRow); response.Add(new ActualVsPredicted { ActualValue = singleRow.SalePrice, PredictedValue = predictionResult.Score }); } return(response); }
public static Bitmap Restore(this Bitmap lowQuality, Bitmap original = null) { var dataArray = lowQuality.To2DDataArray(); var width = lowQuality.Width; var height = lowQuality.Height; var predictedBitmap = new Bitmap(width, height); var mlContext = new MLContext(); DataViewSchema predictionPipelineSchema; ITransformer predictionPipeline = mlContext.Model.Load("./mymodel.zip", out predictionPipelineSchema); PredictionEngine <Data, OutputData> predictionEngine = mlContext.Model.CreatePredictionEngine <Data, OutputData>(predictionPipeline); Debug.WriteLine("Predicting and constructing bitmap..."); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var data = dataArray[x, y]; var output = predictionEngine.Predict(dataArray[x, y]); /* * if (original == null) * { * Debug.WriteLine("value: " + data.value + " -> " + " output: " + output.outputValue); * } * else * { * Debug.WriteLine("value: " + data.value + " -> " + " output: " + output.outputValue + ". original: " + original.GetPixel(x, y).ToArgb()); + } */ predictedBitmap.SetPixel(x, y, Color.FromArgb((int)output.outputValue)); } } Debug.WriteLine("completed"); return(predictedBitmap); // PredictionEngine<Data, OutputData> predictionEngine = mlContext.Model.CreatePredictionEngine<Data, OutputData>(predictionPipeline); // var output = predictionEngine.Predict(new Data { low = new float[] { 0.1f, 0.1f }, original = new float[] { 2f, 2f } }); // Console.WriteLine("prediction: " + output.predicted + " with score: " + output.score); }
public static void UseModelWithSingleItem(MLContext mlContext, ITransformer model) { PredictionEngine <SentimentData, SentimentPrediction> predictionFunction = mlContext.Model.CreatePredictionEngine <SentimentData, SentimentPrediction>(model); SentimentData sampleStatement = new SentimentData { SentimentText = "This is a very bad steak" }; var resultPrediction = predictionFunction.Predict(sampleStatement); Console.WriteLine(); Console.WriteLine("========== Prediction test of model with a single sample and test dataset =========="); Console.WriteLine(); Console.WriteLine($"Sentiment: {resultPrediction.SentimentText} | " + $"Prediction: {(Convert.ToBoolean(resultPrediction.Prediction) ? "Positive" : "Negative")} | " + $"Probability: {resultPrediction.Probability}"); Console.WriteLine("========== End of predictions =========="); Console.WriteLine(); }
public static void PredictConformity() { ITransformer loadedModel; using (var stream = new FileStream(_modelPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { loadedModel = _mlContext.Model.Load(stream); } СonformChecker singleConf = new СonformChecker() { Name = "котировка" }; _predEngine = loadedModel.CreatePredictionEngine <СonformChecker, CheckerPrediction>(_mlContext); var prediction = _predEngine.Predict(singleConf); Console.WriteLine($"=============== Single Prediction - Result: {prediction.Con} ==============="); }