public List <RecognitionContract> Post([FromBody] Dictionary <string, string> imgs) { List <RecognitionContract> predictionResults = new List <RecognitionContract>(); imgs.Values.ToArray(); model.MakePrediction(imgs); lock (model.recognitionLibraryContext) { foreach (var i in imgs) { RecognitionInfo temp = new RecognitionInfo(i.Key, "", 0); temp.Image = Convert.FromBase64String(i.Value); var res = model.recognitionLibraryContext.FindOne(temp); if (res == null) { Trace.WriteLine("Post null"); } else { byte[] tmp1 = res.ImageDetails.Image; var converted = Convert.ToBase64String(tmp1); predictionResults.Add(new RecognitionContract(i.Key, res.Label.ToString(), res.Confidence, converted)); } Trace.WriteLine("Post " + i.Key + " " + res.Label + res.Confidence); } } return(predictionResults); }
static void Main(string[] args) { //Console.WriteLine("If you want to stop recognition press ESС"); string img = Console.ReadLine(); string curDir = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.Parent.Parent.FullName; NNModel Mnist = new NNModel(Path.Combine(curDir, "mnist-8.onnx"), Path.Combine(curDir, "classlabel.txt")); Mnist.MessageToUser += PrintMessageToUser; Mnist.OutputResult += PrintResult; var t = Task.Run(() => { return(Mnist.MakePrediction()); }).Result; }
public List <RecognitionInfo> Post([FromBody] string dir) { List <RecognitionInfo> predictionResults = new List <RecognitionInfo>(); model.MakePrediction(dir); lock (model.recognitionLibraryContext) { foreach (var path in Directory.GetFiles(dir).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".bmp") || s.EndsWith(".gif"))) { RecognitionInfo temp = new RecognitionInfo(path, "", 0); var res = model.recognitionLibraryContext.FindOne(temp); predictionResults.Add(new RecognitionInfo(path, res.Label.ToString(), res.Confidence)); } } return(predictionResults); }