private bool CheckIfInDb(string single_image_path, out PredictionResult result) { using (var db = new MyResultContext()) { byte[] RawImg = File.ReadAllBytes(single_image_path); byte[] hash = System.Security.Cryptography.MD5.Create().ComputeHash(RawImg); var query = db.Results.Where(p => p.Hash == hash).Select(p => p).ToList(); if (query.Count == 0) { result = null; return(false); } foreach (var single_image in query) { db.Entry(single_image).Reference(p => p.Detail).Load(); if (RawImg.SequenceEqual(single_image.Detail.RawImg)) { single_image.CountReffered++; db.SaveChanges(); result = new PredictionResult(single_image.Path, single_image.Label, single_image.Confidence); return(true); } } } result = null; return(true); }
public PredictionResult WorkSingleImg(string str, string filename) { var bytes = Convert.FromBase64String(str); if (filename.EndsWith("from_browser")) { int count; using (var db = new MyResultContext()) { count = db.Results.ToList().Count; } filename = "C:/server_images/processing" + "current" + count.ToString() + ".jpeg"; using (var imageFile = new FileStream(filename, FileMode.Create)) { imageFile.Write(bytes, 0, bytes.Length); imageFile.Flush(); } } filenames ??= new ConcurrentQueue <string>(); filenames.Enqueue(filename); //out_mutex = new AutoResetEvent(true); //cancel = new ManualResetEvent(false); //worker(); Console.WriteLine("here in predictsingleimg"); string name; filenames.TryDequeue(out name); var current_res = Predict_with_db(ImageToTensor(name), name); return(current_res); }
public List <string> ShowDbStats() { List <string> all_res = new List <string>(); using (var db = new MyResultContext()) { foreach (var single_res in db.Results.ToList()) { all_res.Add(single_res.Label + " " + single_res.Hash + " " + single_res.CountReffered); } }; return(all_res); }
public void ClearDB() { using (var db = new MyResultContext()) { try { db.Database.EnsureDeleted(); db.Database.EnsureCreated(); } catch (Exception) { // dummy } } }
private void AddToDb(PredictionResult pred) { using (var db = new MyResultContext()) { byte[] CurrentRawImg = File.ReadAllBytes(pred.Path); byte[] CurrentHash = System.Security.Cryptography.MD5.Create().ComputeHash(CurrentRawImg); ImgDetail detail_to_db = new ImgDetail { RawImg = CurrentRawImg }; db.ImgDetails.Add(detail_to_db); Result pred_to_db = new Result { Hash = CurrentHash, Path = pred.Path, Label = pred.Label, Confidence = pred.Confidence, CountReffered = 1, Detail = detail_to_db }; db.Results.Add(pred_to_db); db.SaveChanges(); }; }