MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DatasetFactory.cs
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Drawing;
5using System.IO;
6using System.Linq;
7using System.Text;
8using System.Threading;
9using System.Threading.Tasks;
10using MyCaffe.basecode;
12
13namespace MyCaffe.db.image
14{
18 public class DatasetFactory : IDisposable
19 {
23 protected Database m_db = new Database();
31 protected int? m_nOriginalSourceID = null;
35 protected bool m_bLoadDataCriteria = false;
39 protected bool m_bLoadDebugData = false;
43 protected ConnectInfo m_ciOpen = null;
44
45 ImageCache m_imageCache = null;
46 ParamCache m_paramCache = null;
47
48
53 {
54 m_db = new Database();
55 }
56
62 public DatasetFactory(bool bLoadDataCriteria, bool bLoadDebugData)
63 {
64 m_bLoadDataCriteria = bLoadDataCriteria;
65 m_bLoadDebugData = bLoadDebugData;
66 m_db = new Database();
67 }
68
74 {
77 }
78
83 public DatasetFactory(int nSrcId)
84 {
85 Open(nSrcId);
86 }
87
91 public void Dispose()
92 {
93 }
94
99 {
100 get { return m_db; }
101 }
102
106 public int LastIndex
107 {
108 get { return m_db.LastIndex; }
109 }
110
116 public void SetLoadingParameters(bool bLoadDataCriteria, bool bLoadDebugData)
117 {
118 m_bLoadDataCriteria = bLoadDataCriteria;
119 m_bLoadDebugData = bLoadDebugData;
120 }
121
126 {
127 get { return m_bLoadDataCriteria; }
128 }
129
133 public bool LoadDebugData
134 {
135 get { return m_bLoadDebugData; }
136 }
137
145 public bool ChangeRawImageSourceID(int nID, int nNewSrcID, bool bSave = true)
146 {
147 return m_db.ChangeRawImageSourceID(nID, nNewSrcID, bSave);
148 }
149
153 public void SaveChanges()
154 {
156 }
157
164 public void Open(SourceDescriptor src, int nCacheMax = 500, ConnectInfo ci = null)
165 {
166 m_openSource = src;
167 Open(src.ID, nCacheMax, Database.FORCE_LOAD.NONE, null, ci);
168 }
169
178 public void Open(int nSrcId, int nCacheMax = 500, Database.FORCE_LOAD nForceLoad = Database.FORCE_LOAD.NONE, Log log = null, ConnectInfo ci = null)
179 {
180 if (m_openSource != null)
181 {
182 if (m_openSource.ID != nSrcId)
183 {
184 if (log != null)
185 log.WriteLine("WARNING: Closing currently open source ID of " + m_openSource.ID.ToString() + " and opening new Source ID of " + nSrcId.ToString() + ".");
186 Close();
187 }
188 }
189
190 m_ciOpen = ci;
191 m_openSource = LoadSource(nSrcId, ci);
192 m_db.Open(nSrcId, nForceLoad, ci);
193
194 m_imageCache = new ImageCache(nCacheMax);
195 m_paramCache = new ParamCache(nCacheMax);
196 }
197
201 public void Close()
202 {
203 m_openSource = null;
204 m_ciOpen = null;
205 m_db.Close();
206 }
207
211 public void Refresh()
212 {
213 m_db.Refresh();
214 }
215
220 {
221 get { return m_openSource; }
222 }
223
224
225 //---------------------------------------------------------------------
226 // Raw Images
227 //---------------------------------------------------------------------
228 #region RawImages
229
239 public void PutRawImageParameterCache(int nImageID, string strParam, string strVal, double? dfVal, byte[] rgData, bool bOnlyAddNew)
240 {
241 if (m_paramCache.Add(new ParameterData(strParam, strVal, dfVal, rgData, nImageID, bOnlyAddNew, m_openSource.ID)))
242 ClearParamCache(true);
243 }
244
249 public void ClearParamCache(bool bSave)
250 {
251 if (m_paramCache.Count == 0)
252 return;
253
254 if (bSave)
255 m_db.PutRawImageParameters(m_paramCache.Parameters);
256
257 m_paramCache.Clear();
258 }
259
269 public void PutRawImageCache(int nIdx, SimpleDatum sd, int nBackgroundWritingThreadCount = 0, string strDescription = null, bool bActive = true, params ParameterData[] rgParams)
270 {
271 RawImage img = m_db.CreateRawImage(nIdx, sd, nBackgroundWritingThreadCount, strDescription, m_nOriginalSourceID, bActive);
272 if (m_imageCache.Add(img, sd, rgParams))
273 ClearImageCache(true);
274 }
275
280 public void ClearImageCache(bool bSave)
281 {
282 if (m_imageCache == null || m_imageCache.Count == 0)
283 return;
284
285 if (bSave)
286 {
288 m_db.PutRawImages(m_imageCache.Images, m_imageCache.Parameters, m_ciOpen);
289 }
290
291 m_imageCache.Clear();
292 }
293
301 public int PutRawImage(int nIdx, SimpleDatum sd, string strDescription = null)
302 {
303 return m_db.PutRawImage(nIdx, sd, strDescription);
304 }
305
316 public int SetRawImageParameter(int nRawImageID, string strName, string strValue, double? dfVal = null, byte[] rgData = null, bool bOnlyAddNew = false)
317 {
318 return m_db.SetRawImageParameter(nRawImageID, strName, strValue, dfVal, rgData, true, bOnlyAddNew);
319 }
320
331 public int SetRawImageParameter(int nSrcID, int nRawImageID, string strName, string strValue, double? dfVal = null, byte[] rgData = null)
332 {
333 return m_db.SetRawImageParameter(nSrcID, nRawImageID, strName, strValue, dfVal, rgData);
334 }
335
345 public int SetRawImageParameterAt(DateTime dt, string strName, string strValue, double? dfVal = null, byte[] rgData = null)
346 {
347 return m_db.SetRawImageParameterAt(dt, strName, strValue, dfVal, rgData);
348 }
349
356 public List<RawImageParameter> QueryRawImageParameters(int nSrcId, string strName)
357 {
358 return m_db.QueryRawImageParameters(nSrcId, strName);
359 }
360
366 public List<RawImageParameter> QueryRawImageParameters(int nImageID)
367 {
368 return m_db.QueryRawImageParameters(nImageID);
369 }
370
375 public RawImageMean GetRawImageMean()
376 {
377 return m_db.GetRawImageMean();
378 }
379
388 public List<RawImage> GetRawImagesAt(int nImageIdx, int nImageCount, int nSrcId = 0, string strDescription = null)
389 {
390 return m_db.GetRawImagesAt(nImageIdx, nImageCount, nSrcId, strDescription);
391 }
392
401 public List<RawImage> GetRawImagesAt(List<int> rgImageIdx, ManualResetEvent evtCancel, int nSrcId = 0, string strDescription = null)
402 {
403 List<RawImage> rgImg = new List<RawImage>();
404
405 while (rgImageIdx.Count > 0)
406 {
407 List<int> rgIdx = new List<int>();
408
409 for (int i=0; i<rgImageIdx.Count && i < 100; i++)
410 {
411 rgIdx.Add(rgImageIdx[i]);
412 }
413
414 List<RawImage> rgImg1 = m_db.GetRawImagesAt(rgIdx, nSrcId, strDescription);
415 rgImg.AddRange(rgImg1);
416
417 for (int i = 0; i < rgIdx.Count; i++)
418 {
419 rgImageIdx.RemoveAt(0);
420 }
421
422 if (evtCancel.WaitOne(0))
423 return null;
424 }
425
426 return rgImg;
427 }
428
437 public List<RawImage> GetRawImagesAtID(List<int> rgImageId, ManualResetEvent evtCancel, int nSrcId = 0, string strDescription = null)
438 {
439 List<RawImage> rgImg = new List<RawImage>();
440
441 while (rgImageId.Count > 0)
442 {
443 List<int> rgIdx = new List<int>();
444
445 for (int i = 0; i < rgImageId.Count && i < 100; i++)
446 {
447 rgIdx.Add(rgImageId[i]);
448 }
449
450 List<RawImage> rgImg1 = m_db.GetRawImagesAtID(rgIdx, nSrcId, strDescription);
451 rgImg.AddRange(rgImg1);
452
453 for (int i = 0; i < rgIdx.Count; i++)
454 {
455 rgImageId.RemoveAt(0);
456 }
457
458 if (evtCancel.WaitOne(0))
459 return null;
460 }
461
462 return rgImg;
463 }
464
473 public List<RawImage> GetRawImagesAt(List<DbItem> rgImgItems, ManualResetEvent evtCancel, int nSrcId = 0, string strDescription = null)
474 {
475 List<RawImage> rgImg = new List<RawImage>();
476
477 while (rgImgItems.Count > 0)
478 {
479 List<int> rgID = new List<int>();
480
481 for (int i = 0; i < rgImgItems.Count && i < 100; i++)
482 {
483 rgID.Add(rgImgItems[i].ID);
484 }
485
486 List<RawImage> rgImg1 = m_db.GetRawImagesAtID(rgID, nSrcId, strDescription);
487 rgImg.AddRange(rgImg1);
488
489 for (int i = 0; i < rgID.Count; i++)
490 {
491 rgImgItems.RemoveAt(0);
492 }
493
494 if (evtCancel.WaitOne(0))
495 return null;
496 }
497
498 return rgImg;
499 }
500
509 public List<SimpleDatum> GetImagesAt(List<int> rgImageIdx, ManualResetEvent evtCancel, int nSrcId = 0, string strDescription = null)
510 {
511 List<RawImage> rgImg = GetRawImagesAt(rgImageIdx, evtCancel, nSrcId, strDescription);
512 if (rgImg == null)
513 return null;
514
515 List<SimpleDatum> rgSd = new List<SimpleDatum>();
516
517 foreach (RawImage img in rgImg)
518 {
519 rgSd.Add(LoadDatum(img));
520 }
521
522 return rgSd;
523 }
524
533 public List<SimpleDatum> GetImagesAt(List<DbItem> rgImageItems, ManualResetEvent evtCancel, int nSrcId = 0, string strDescription = null)
534 {
535 List<RawImage> rgImg = GetRawImagesAt(rgImageItems, evtCancel, nSrcId, strDescription);
536 if (rgImg == null)
537 return null;
538
539 List<SimpleDatum> rgSd = new List<SimpleDatum>();
540
541 foreach (RawImage img in rgImg)
542 {
543 rgSd.Add(LoadDatum(img));
544 }
545
546 return rgSd;
547 }
548
556 public List<SimpleDatum> GetImagesAtID(List<int> rgImageId, int nSrcId = 0, string strDescription = null)
557 {
558 List<RawImage> rgImg = m_db.GetRawImagesAtID(rgImageId, nSrcId, strDescription);
559 if (rgImg == null)
560 return null;
561
562 List<SimpleDatum> rgSd = new List<SimpleDatum>();
563
564 foreach (RawImage img in rgImg)
565 {
566 rgSd.Add(LoadDatum(img));
567 }
568
569 return rgSd;
570 }
571
584 public List<RawImage> QueryRawImages(int nSrcId, bool? bActive = null, bool bLoadCriteria = false, bool bLoadDebug = false, Log log = null, CancelEvent evtCancel = null, int nBoostVal = 0, bool bExactBoostVal = false)
585 {
586 List<RawImage> rgImg = m_db.QueryRawImages(nSrcId, bActive, nBoostVal, bExactBoostVal);
587
588 if (!bLoadCriteria && !bLoadDebug)
589 return rgImg;
590
591 Stopwatch sw = new Stopwatch();
592 sw.Start();
593
594 for (int i = 0; i < rgImg.Count; i++)
595 {
596 int? nFmt;
597
598 if (bLoadCriteria)
599 rgImg[i].DataCriteria = m_db.GetRawImageDataCriteria(rgImg[i], out nFmt);
600
601 if (bLoadDebug)
602 rgImg[i].DebugData = m_db.GetRawImageDebugData(rgImg[i], out nFmt);
603
604 if (evtCancel != null && evtCancel.WaitOne(0))
605 return null;
606
607 if (log != null)
608 {
609 if (sw.Elapsed.TotalMilliseconds > 1000)
610 {
611 log.Progress = (double)i / (double)rgImg.Count;
612 log.WriteLine("loading " + i.ToString("N0") + " of " + rgImg.Count.ToString("N0") + "...");
613 sw.Restart();
614 }
615 }
616 }
617
618 return rgImg;
619 }
620
627 public void LoadRawImageData(RawImage img, bool bLoadCriteria, bool bLoadDebug)
628 {
629 int? nFmt;
630
631 if (bLoadCriteria)
632 img.DataCriteria = m_db.GetRawImageDataCriteria(img, out nFmt);
633
634 if (bLoadDebug)
635 img.DebugData = m_db.GetRawImageDebugData(img, out nFmt);
636 }
637
645 public int PutRawImageMean(SimpleDatum sd, bool bUpdate, ConnectInfo ci = null)
646 {
647 return m_db.PutRawImageMean(sd, bUpdate, 0, ci);
648 }
649
657 public bool SaveImageMean(SimpleDatum sd, bool bUpdate, int nSrcId = 0)
658 {
659 if (m_db.PutRawImageMean(sd, bUpdate, nSrcId) != 0)
660 return true;
661
662 return false;
663 }
664
670 public SimpleDatum QueryImageMean(int nSrcId = 0)
671 {
672 RawImageMean img = m_db.GetRawImageMean(nSrcId);
673 return LoadDatum(img);
674 }
675
682 public bool CopyImageMean(string strSrcSrc, string strDstSrc)
683 {
684 int nSrcIdSrc = GetSourceID(strSrcSrc);
685 int nDstIdSrc = GetSourceID(strDstSrc);
686 return m_db.CopyImageMean(nSrcIdSrc, nDstIdSrc);
687 }
688
693 public int GetImageCount()
694 {
695 return m_db.GetImageCount();
696 }
697
708 public List<int> QueryRawImageIDs(int nSrcId = 0, int nMax = int.MaxValue, int nLabel = -1, int nBoost = -1, bool bBoostIsExact = false, bool bAnnotatedOnly = false)
709 {
710 return m_db.QueryAllRawImageIDs(nSrcId, nMax, nLabel, nBoost, bBoostIsExact, bAnnotatedOnly);
711 }
712
718 public int GetRawImageMeanID(int nSrcId = 0)
719 {
720 RawImageMean img = m_db.GetRawImageMean(nSrcId);
721 return (img == null) ? 0 : img.ID;
722 }
723
730 public int GetRawImageID(DateTime dt, int nSrcId = 0)
731 {
732 return m_db.GetRawImageID(dt, nSrcId);
733 }
734
740 public RawImage GetRawImageFromID(int nImageID)
741 {
742 return m_db.GetRawImage(nImageID);
743 }
744
749 public void DeleteRawImageResults(int nSrcId = 0)
750 {
752 }
753
765 public int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List<Result> rgResults, bool bInvert, List<Tuple<DateTime, int>> rgExtra = null)
766 {
767 return m_db.PutRawImageResults(nSrcId, nIdx, nLabel, dt, rgResults, bInvert, rgExtra);
768 }
769
780 public int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List<Tuple<SimpleDatum, List<Result>>> rgrgResults, List<Tuple<DateTime, int>> rgExtra = null)
781 {
782 return m_db.PutRawImageResults(nSrcId, nIdx, nLabel, dt, rgrgResults, rgExtra);
783 }
784
791 public List<Tuple<SimpleDatum, List<Result>>> GetRawImageResultBatch(int nBatchCount, byte[] rgResults)
792 {
793 return m_db.GetRawImageResultBatch(nBatchCount, rgResults);
794 }
795
805 public int AddRawImageGroup(Image img, int nIdx, DateTime dtStart, DateTime dtEnd, List<double> rgProperties)
806 {
807 return m_db.AddRawImageGroup(img, nIdx, dtStart, dtEnd, rgProperties);
808 }
809
817 public int FindRawImageGroupID(int nIdx, DateTime dtStart, DateTime dtEnd)
818 {
819 return m_db.FindRawImageGroupID(nIdx, dtStart, dtEnd);
820 }
821
827 public List<string> GetRawImageDistinctParameterDescriptions(int nSrcId)
828 {
830 }
831
838 public byte[] GetRawImageParameterData(int nRawImageID, string strParam)
839 {
840 return m_db.GetRawImageParameterData(nRawImageID, strParam);
841 }
842
850 public int GetRawImageParameterCount(string strParam, int nSrcId = 0, string strType = "TEXT")
851 {
852 return m_db.GetRawImageParameterCount(strParam, nSrcId, strType);
853 }
854
862 public bool GetRawImageParameterExist(string strName, int nSrcId = 0, string strType = "TEXT")
863 {
864 return m_db.GetRawImageParameterExist(strName, nSrcId, strType);
865 }
866
875 public bool UpdateActiveLabel(int nImageID, int nNewActiveLabel, bool bActivate = true, bool bSaveChanges = true)
876 {
877 return m_db.UpdateActiveLabel(nImageID, nNewActiveLabel, bActivate, bSaveChanges);
878 }
879
885 public void UpdateActiveLabelDirect(int nID, int nLabel)
886 {
887 m_db.UpdateActiveLabelDirect(nID, nLabel);
888 }
889
895 public void UpdateAllActiveLabelsDirect(int nLabel, int? nOriginalLabel = null)
896 {
897 m_db.UpdateAllActiveLabels(m_openSource.ID, nLabel, nOriginalLabel);
898 }
899
905 public void DisableLabel(int nLabel, bool bOriginalLabel = false)
906 {
907 m_db.DisableLabel(m_openSource.ID, nLabel, bOriginalLabel);
908 }
909
913 public void DisableAllLabels()
914 {
916 }
917
924 public int DisableAllNonMatchingImages(int nWidth, int nHeight)
925 {
926 return m_db.DisableAllNonMatchingImages(m_openSource.ID, nWidth, nHeight);
927 }
928
933 {
935 }
936
942 public void UpdateActiveLabelByID(int nID, int nNewActiveLabel)
943 {
944 m_db.UpdateActiveLabelByID(nID, nNewActiveLabel);
945 }
946
952 public void UpdateActiveLabelByIndex(int nIdx, int nNewActiveLabel)
953 {
954 m_db.UpdateActiveLabelByIndex(m_openSource.ID, nIdx, nNewActiveLabel);
955 }
956
962 public void ActivateRawImageByIndex(int nIdx, bool bActive)
963 {
965 }
966
972 public void UpdateRawImageSourceID(int nImageID, int nSrcID)
973 {
974 m_db.UpdateRawImageSourceID(nImageID, nSrcID);
975 }
976
984 public bool ActivateRawImage(int nImageID, bool bActive, bool bSave = true)
985 {
986 return m_db.ActivateRawImage(nImageID, bActive, bSave);
987 }
988
995 public void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, params int[] rgSrcId)
996 {
997 m_db.ActivateAllRawImages(bActive, bAnnotatedOnly, rgSrcId);
998 }
999
1010 public void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, int? nTgtLabel, bool bTargetLabelExact, int? nTgtBoost, bool bTargetBoostExact, params int[] rgSrcId)
1011 {
1012 m_db.ActivateAllRawImages(bActive, bAnnotatedOnly, nTgtLabel, bTargetLabelExact, nTgtBoost, bTargetBoostExact, rgSrcId);
1013 }
1014
1026 public void FixupRawImageCopy(int nImageID, int nSecondarySrcId)
1027 {
1028 m_db.FixupRawImageCopy(nImageID, nSecondarySrcId);
1029 }
1030
1037 public byte[] GetRawImageDataCriteria(byte[] rgData, int nOriginalSourceID)
1038 {
1039 return m_db.GetRawImageDataCriteria(rgData, nOriginalSourceID);
1040 }
1041
1048 public byte[] GetRawImageDataCriteria(int nImgID, int nOriginalSourceID)
1049 {
1050 return m_db.GetRawImageDataCriteria(nImgID, nOriginalSourceID);
1051 }
1052
1053
1060 public byte[] GetRawImageDebugData(byte[] rgData, int nOriginalSourceID)
1061 {
1062 return m_db.GetRawImageDebugData(rgData, nOriginalSourceID);
1063 }
1064
1071 public byte[] GetRawImageDebugData(int nImgID, int nOriginalSourceID)
1072 {
1073 return m_db.GetRawImageDebugData(nImgID, nOriginalSourceID);
1074 }
1075
1083 public void UpdateDatasetImageAnnotations(int nSrcId, int nImageId, AnnotationGroupCollection annotations, bool bSetLabelOnly)
1084 {
1085 m_db.UpdateDatasetImageAnnotations(nSrcId, nImageId, annotations, bSetLabelOnly);
1086 }
1087
1088 #endregion
1089
1090
1091 //---------------------------------------------------------------------
1092 // Labels
1093 //---------------------------------------------------------------------
1094 #region Labels
1095
1102 public List<LabelBoostDescriptor> GetLabelBoosts(int nProjectId, int nSrcId = 0)
1103 {
1104 List<LabelBoost> rgBoosts = m_db.GetLabelBoosts(nProjectId, true, nSrcId);
1105 List<LabelBoostDescriptor> rgDesc = new List<LabelBoostDescriptor>();
1106
1107 foreach (LabelBoost b in rgBoosts)
1108 {
1109 rgDesc.Add(new LabelBoostDescriptor(b.ActiveLabel.GetValueOrDefault(), (double)b.Boost.GetValueOrDefault(1)));
1110 }
1111
1112 return rgDesc;
1113 }
1114
1120 public void SetLabelMapping(LabelMapping map, int nSrcId = 0)
1121 {
1122 m_db.SetLabelMapping(map, nSrcId);
1123 }
1124
1131 public void UpdateLabelMapping(int nNewLabel, List<int> rgOriginalLabels, int nSrcId = 0)
1132 {
1133 m_db.UpdateLabelMapping(nNewLabel, rgOriginalLabels, nSrcId);
1134 }
1135
1141 public void ResetLabels(int nProjectId = 0, int nSrcId = 0)
1142 {
1143 m_db.ResetLabels(nProjectId, nSrcId);
1144 }
1145
1151 public void DeleteLabelBoosts(int nProjectId, int nSrcId = 0)
1152 {
1153 m_db.DeleteLabelBoosts(nProjectId, nSrcId);
1154 }
1155
1163 public void AddLabelBoost(int nProjectId, int nLabel, double dfBoost, int nSrcId = 0)
1164 {
1165 m_db.AddLabelBoost(nProjectId, nLabel, dfBoost, nSrcId);
1166 }
1167
1175 public string GetLabelBoostsAsText(int nProjectId, int nSrcId = 0, bool bSort = true)
1176 {
1177 return m_db.GetLabelBoostsAsText(nProjectId, nSrcId, bSort);
1178 }
1179
1185 public Dictionary<int, int> LoadLabelCounts(int nSrcId = 0)
1186 {
1187 Dictionary<int, int> rgCounts = new Dictionary<int, int>();
1188 m_db.LoadLabelCounts(rgCounts, nSrcId);
1189 return rgCounts;
1190 }
1191
1196 public void UpdateLabelCounts(Dictionary<int, int> rgCounts)
1197 {
1198 m_db.UpdateLabelCounts(rgCounts);
1199 }
1200
1206 public void UpdateLabelCounts(int nSrcId = 0, int nProjectId = 0)
1207 {
1208 m_db.UpdateLabelCounts(nSrcId, nProjectId);
1209 }
1210
1216 public string GetLabelCountsAsText(int nSrcId)
1217 {
1218 return m_db.GetLabelCountsAsText(nSrcId);
1219 }
1220
1227 public void UpdateLabelName(int nLabel, string strName, int nSrcId = 0)
1228 {
1229 m_db.UpdateLabelName(nLabel, strName, nSrcId);
1230 }
1231
1238 public string GetLabelName(int nLabel, int nSrcId = 0)
1239 {
1240 return m_db.GetLabelName(nLabel, nSrcId);
1241 }
1242
1251 public int AddLabel(int nLabel, string strName, int nSrcId = 0, ConnectInfo ci = null)
1252 {
1253 return m_db.AddLabel(nLabel, strName, nSrcId, ci);
1254 }
1255
1260 public void DeleteLabels(int nSrcId = 0)
1261 {
1262 m_db.DeleteLabels(nSrcId);
1263 }
1264
1271 public void ActivateLabels(List<int> rgLabels, bool bActive, params int[] rgSrcId)
1272 {
1273 m_db.ActivateLabels(rgLabels, bActive, rgSrcId);
1274 }
1275
1286 public void UpdateLabelBoost(int? nTgtLbl, bool bTgtLblExact, int? nTgtBst, bool bTgtBstExact, int? nNewLbl, int? nNewBst, params int[] rgSrcId)
1287 {
1288 m_db.UpdateLabelBoost(nTgtLbl, bTgtLblExact, nTgtBst, bTgtBstExact, nNewLbl, nNewBst, rgSrcId);
1289 }
1290
1297 public List<Label> QueryLabels(int nSrcId = 0, ConnectInfo ci = null)
1298 {
1299 return m_db.GetLabels(false, false, nSrcId, ci);
1300 }
1301
1302 #endregion
1303
1304
1305 //---------------------------------------------------------------------
1306 // Sources
1307 //---------------------------------------------------------------------
1308 #region Sources
1309
1315 public int GetSourceID(string strName)
1316 {
1317 return m_db.GetSourceID(strName);
1318 }
1319
1325 public string GetSourceName(int nId)
1326 {
1327 return m_db.GetSourceName(nId);
1328 }
1329
1337 public int AddSource(SourceDescriptor src, ConnectInfo ci = null, bool? bSaveImagesToFileOverride = null)
1338 {
1339 bool bSaveImagesToFile = bSaveImagesToFileOverride.GetValueOrDefault(src.SaveImagesToFile);
1340 src.ID = m_db.AddSource(src.Name, src.Channels, src.Width, src.Height, src.IsRealData, src.CopyOfSourceID, bSaveImagesToFile, ci);
1341 return src.ID;
1342 }
1343
1357 public int AddSource(string strName, int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nCopyOfSourceID = 0, bool bSaveImagesToFile = true, ConnectInfo ci = null)
1358 {
1359 return m_db.AddSource(strName, nChannels, nWidth, nHeight, bDataIsReal, nCopyOfSourceID, bSaveImagesToFile, ci);
1360 }
1361
1366 public void DeleteSources(params string[] rgstrSrc)
1367 {
1368 m_db.DeleteSources(rgstrSrc);
1369 }
1370
1375 public void DeleteSourceData(int nSrcId = 0)
1376 {
1377 m_db.DeleteSourceData(nSrcId);
1378 }
1379
1387 public int GetBoostCount(int nSrcId = 0, string strFilterVal = null, int? nBoostVal = null)
1388 {
1389 return m_db.GetBoostCount(nSrcId, strFilterVal, nBoostVal);
1390 }
1391
1399 public int ActivateFiltered(int nSrcId = 0, string strFilterVal = null, int? nBoostVal = null)
1400 {
1401 return m_db.ActivateFiltered(nSrcId, strFilterVal, nBoostVal);
1402 }
1403
1412 public bool ReindexRawImages(Log log, CancelEvent evtCancel, int nSrcId = 0, bool bCreateImageMean = false)
1413 {
1414 List<RawImage> rgImg = m_db.ReindexRawImages(log, evtCancel, nSrcId);
1415 if (rgImg == null)
1416 return false;
1417
1418 if (bCreateImageMean)
1419 {
1420 bool bOpened = false;
1421 if (m_openSource == null)
1422 {
1423 Open(nSrcId);
1424 bOpened = true;
1425 }
1426
1427 List<SimpleDatum> rgSd = new List<SimpleDatum>();
1428 foreach (RawImage img in rgImg)
1429 {
1430 rgSd.Add(LoadDatum(img));
1431 }
1432
1433 SimpleDatum sdMean = SimpleDatum.CalculateMean(log, rgSd.ToArray(), evtCancel.Handles);
1434 if (sdMean == null)
1435 return false;
1436
1437 bool bRes = SaveImageMean(sdMean, true, nSrcId);
1438 if (bOpened)
1439 Close();
1440
1441 return bRes;
1442 }
1443
1444 return true;
1445 }
1446
1455 public void UpdateSource(int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nSrcId = 0)
1456 {
1457 m_db.UpdateSource(nChannels, nWidth, nHeight, bDataIsReal, nSrcId);
1458 }
1459
1464 {
1468 }
1469
1476 public void SetSourceParameter(string strParam, string strValue, int nSrcId = 0)
1477 {
1478 m_db.SetSourceParameter(strParam, strValue, nSrcId);
1479 }
1480
1487 public string GetSourceParameter(string strParam, int nSrcId = 0)
1488 {
1489 return m_db.GetSourceParameter(strParam, nSrcId);
1490 }
1491
1499 public int GetSourceParameter(string strParam, int nDefault, int nSrcId = 0)
1500 {
1501 return m_db.GetSourceParameter(strParam, nDefault, nSrcId);
1502 }
1503
1511 public bool GetSourceParameter(string strParam, bool bDefault, int nSrcId = 0)
1512 {
1513 return m_db.GetSourceParameter(strParam, bDefault, nSrcId);
1514 }
1515
1523 public double GetSourceParameter(string strParam, double dfDefault, int nSrcId = 0)
1524 {
1525 return m_db.GetSourceParameter(strParam, dfDefault, nSrcId);
1526 }
1527
1534 public DateTime GetFirstTimeStamp(int nSrcId = 0, string strDesc = null)
1535 {
1536 return m_db.GetFirstTimeStamp(nSrcId, strDesc);
1537 }
1538
1545 public DateTime GetLastTimeStamp(int nSrcId = 0, string strDesc = null)
1546 {
1547 return m_db.GetLastTimeStamp(nSrcId, strDesc);
1548 }
1549
1559 public DateTime GetLastTimeStamp(DateTime dtStart, DateTime dtEnd, bool bEndInclusive, int nSrcId = 0, string strDesc = null)
1560 {
1561 return m_db.GetLastTimeStamp(dtStart, dtEnd, bEndInclusive, nSrcId, strDesc);
1562 }
1563
1564
1572 public DateTime GetLastTimeStamp(out int nIndex, int nSrcId = 0, string strDesc = null)
1573 {
1574 return m_db.GetLastTimeStamp(out nIndex, nSrcId, strDesc);
1575 }
1576
1587 public DateTime GetLastTimeStamp(DateTime dtStart, DateTime dtEnd, bool bEndInclusive, out int nIndex, int nSrcId = 0, string strDesc = null)
1588 {
1589 return m_db.GetLastTimeStamp(dtStart, dtEnd, bEndInclusive, out nIndex);
1590 }
1591
1592#pragma warning disable 1591
1593
1594 public List<int> GetAllDataSourceIDs()
1595 {
1596 return m_db.GetAllDataSourcesIDs();
1597 }
1598
1599 public bool ConvertRawImagesSaveToFile(int nIdx, int nCount)
1600 {
1601 return m_db.ConvertRawImagesSaveToFile(nIdx, nCount);
1602 }
1603
1604 public bool ConvertRawImagesSaveToDatabase(int nIdx, int nCount)
1605 {
1606 return m_db.ConvertRawImagesSaveToDatabase(nIdx, nCount);
1607 }
1608
1609 public void UpdateSaveImagesToFile(bool bSaveToFile, int nSrcId = 0)
1610 {
1611 m_db.UpdateSaveImagesToFile(bSaveToFile, nSrcId);
1612 }
1613
1614#pragma warning restore 1591
1615
1621 {
1622 get { return m_nOriginalSourceID; }
1623 set { m_nOriginalSourceID = value; }
1624 }
1625
1626 #endregion
1627
1628
1629 //---------------------------------------------------------------------
1630 // Datasets
1631 //---------------------------------------------------------------------
1632 #region Datasets
1633
1640 public int GetDatasetID(string strDsName, ConnectInfo ci = null)
1641 {
1642 return m_db.GetDatasetID(strDsName, ci);
1643 }
1644
1651 public string GetDatasetName(int nId, ConnectInfo ci = null)
1652 {
1653 return m_db.GetDatasetName(nId, ci);
1654 }
1655
1663 public int AddDataset(DatasetDescriptor ds, ConnectInfo ci = null, bool? bSaveImagesToFileOverride = null)
1664 {
1667
1668 int nDsCreatorID = 0;
1669 if (ds.CreatorName != null)
1670 nDsCreatorID = m_db.GetDatasetCreatorID(ds.CreatorName);
1671
1672 ds.ID = m_db.AddDataset(nDsCreatorID, ds.Name, ds.TestingSource.ID, ds.TrainingSource.ID, ds.DatasetGroup.ID, ds.ModelGroup.ID, ci);
1673 return ds.ID;
1674 }
1675
1687 public int AddDataset(int nDsCreatorID, string strName, int nTestSrcId, int nTrainSrcId, int nDsGroupID = 0, int nModelGroupID = 0, ConnectInfo ci = null)
1688 {
1689 return m_db.AddDataset(nDsCreatorID, strName, nTestSrcId, nTrainSrcId, nDsGroupID, nModelGroupID, ci);
1690 }
1691
1697 public void UpdateDatasetDescription(int nDsId, string strDesc)
1698 {
1699 m_db.UpdateDatasetDescription(nDsId, strDesc);
1700 }
1701
1707 public void UpdateDatasetCounts(int nDsId, ConnectInfo ci = null)
1708 {
1709 Dataset ds = m_db.GetDataset(nDsId, ci);
1710 Database db = new Database();
1711
1712 db.Open(ds.TestingSourceID.GetValueOrDefault(), Database.FORCE_LOAD.NONE, ci);
1713 db.UpdateSourceCounts(ci);
1714 db.UpdateLabelCounts(0, 0, ci);
1715 db.Close();
1716
1717 db.Open(ds.TrainingSourceID.GetValueOrDefault(), Database.FORCE_LOAD.NONE, ci);
1718 db.UpdateSourceCounts(ci);
1719 db.UpdateLabelCounts(0, 0, ci);
1720 db.Close();
1721
1722 m_db.UpdateDatasetCounts(nDsId, ci);
1723 }
1724
1733 public void UpdateDatasetCounts(CancelEvent evtCancel, Log log, int nDatasetCreatorID, List<string> rgstrDs, string strParamNameForDescription)
1734 {
1735 m_db.UpdateDatasetCounts(evtCancel, log, nDatasetCreatorID, rgstrDs, strParamNameForDescription);
1736 }
1737
1744 public string FindDatasetNameFromSourceName(string strTrainSrc, string strTestSrc)
1745 {
1746 return m_db.FindDatasetNameFromSourceName(strTrainSrc, strTestSrc);
1747 }
1748
1754 public int FindDatasetFromSourceId(int nSourceId)
1755 {
1756 return m_db.FindDatasetFromSourceId(nSourceId);
1757 }
1758
1763 public void ResetAllDatasetRelabelWithCreator(int nDsCreatorId)
1764 {
1766 }
1767
1773 public void UpdateDatasetRelabel(int nDsId, bool bRelabel)
1774 {
1775 m_db.UpdateDatasetRelabel(nDsId, bRelabel);
1776 }
1777
1783 public void SetDatasetParameters(int nDsId, Dictionary<string, string> rgP)
1784 {
1785 m_db.SetDatasetParameters(nDsId, rgP);
1786 }
1787
1794 public void SetDatasetParameter(int nDsId, string strParam, string strValue)
1795 {
1796 m_db.SetDatasetParameter(nDsId, strParam, strValue);
1797 }
1798
1805 public string GetDatasetParameter(int nDsId, string strParam)
1806 {
1807 return m_db.GetDatasetParameter(nDsId, strParam);
1808 }
1809
1817 public int GetDatasetParameter(int nDsId, string strParam, int nDefault)
1818 {
1819 return m_db.GetDatasetParameter(nDsId, strParam, nDefault);
1820 }
1821
1829 public bool GetDatasetParameter(int nDsId, string strParam, bool bDefault)
1830 {
1831 return m_db.GetDatasetParameter(nDsId, strParam, bDefault);
1832 }
1833
1841 public double GetDatasetParameter(int nDsId, string strParam, double dfDefault)
1842 {
1843 return m_db.GetDatasetParameter(nDsId, strParam, dfDefault);
1844 }
1845
1851 public int GetDatasetGroupID(string strName)
1852 {
1853 return m_db.GetDatasetGroupID(strName);
1854 }
1855
1856 #endregion
1857
1858 //---------------------------------------------------------------------
1859 // Results
1860 //---------------------------------------------------------------------
1861 #region Results
1862
1870 public List<SimpleResult> QueryAllResults(int nSrcID, bool bRequireExtraData = false, int nMax = -1)
1871 {
1872 List<RawImageResult> rgRes1 = m_db.GetRawImageResults(nSrcID, bRequireExtraData, nMax);
1873 List<SimpleResult> rgRes = new List<SimpleResult>();
1874
1875 foreach (RawImageResult res1 in rgRes1)
1876 {
1877 SimpleResult res = LoadResult(res1, bRequireExtraData);
1878 if (res != null)
1879 rgRes.Add(res);
1880 }
1881
1882 return rgRes;
1883 }
1884
1885 #endregion // Results
1886
1887
1888 //---------------------------------------------------------------------
1889 // Loading Descriptors
1890 //---------------------------------------------------------------------
1891 #region Loading Descriptors
1892
1900 public List<DbItem> LoadImageIndexes(bool bBoostedOnly, bool bIncludeActive = true, bool bIncludeInactive = false)
1901 {
1902 return m_db.GetAllRawImageIndexes(bBoostedOnly, bIncludeActive, bIncludeInactive);
1903 }
1904
1911 public List<ImageDescriptor> LoadImages(CancelEvent evtCancel, params int[] rgSrcId)
1912 {
1913 if (rgSrcId.Length == 0)
1914 throw new Exception("You must specify at least one source ID.");
1915
1916 List<ImageDescriptor> rgImgDesc = new List<ImageDescriptor>();
1917 List<RawImage> rgImg = m_db.QueryRawImages(rgSrcId);
1918
1919 foreach (RawImage img in rgImg)
1920 {
1921 if (evtCancel != null && evtCancel.WaitOne(0))
1922 return null;
1923
1924 rgImgDesc.Add(new ImageDescriptor(img.ID,
1925 img.Height.GetValueOrDefault(0),
1926 img.Width.GetValueOrDefault(0),
1927 img.Channels.GetValueOrDefault(0),
1928 img.Encoded.GetValueOrDefault(false),
1929 img.SourceID.GetValueOrDefault(0),
1930 img.Idx.GetValueOrDefault(0),
1931 img.ActiveLabel.GetValueOrDefault(0),
1932 img.Active.GetValueOrDefault(false),
1933 img.Description,
1934 img.TimeStamp.GetValueOrDefault(DateTime.MinValue)));
1935 }
1936
1937 return rgImgDesc;
1938 }
1939
1949 public SimpleDatum LoadDatum(int nImageId, int nChannels, bool bDataIsReal, int nLabel, int nSrcId = 0)
1950 {
1951 RawImage img = m_db.GetRawImage(nImageId);
1952
1953 if (img == null)
1954 return null;
1955
1956 if (nSrcId == 0)
1957 nSrcId = m_openSource.ID;
1958
1959 if (img.SourceID != nSrcId)
1960 throw new Exception("The source of the raw image with ID = " + nImageId.ToString() + " (SourceID = " + img.SourceID.ToString() + ") does not match the expected source id of " + nSrcId.ToString());
1961
1962 if (img.Channels != nChannels)
1963 throw new Exception("The raw image with ID = " + nImageId.ToString() + " has a different channel count than the expected count of " + nChannels.ToString());
1964
1965 if (img.Encoded.GetValueOrDefault() != bDataIsReal)
1966 throw new Exception("The raw image with ID = " + nImageId.ToString() + " does not have a matching encoding scheme as that of the expected encoded = " + bDataIsReal.ToString());
1967
1968 if (img.ActiveLabel != (int)nLabel)
1969 throw new Exception("The raw image with ID = " + nImageId.ToString() + " does not have a label equal to the expected label of " + nLabel.ToString());
1970
1971 return new Datum(LoadDatum(img));
1972 }
1973
1981 public SimpleDatum LoadDatum(RawImage img, int nPadW = 0, int nPadH = 0)
1982 {
1983 if (img == null)
1984 return null;
1985
1986 byte[] rgDataCriteria = null;
1987 int? nDataCriteriaFormatId = null;
1988 byte[] rgDebugData = null;
1989 int? nDebugDataFormatId = null;
1990 byte[] rgData = m_db.GetRawImageData(img, m_bLoadDataCriteria, m_bLoadDebugData, out rgDataCriteria, out nDataCriteriaFormatId, out rgDebugData, out nDebugDataFormatId);
1991
1992 // Annotation Data is used as the label, so it must be loaded.
1993 if (!m_bLoadDataCriteria &&
1994 (nDataCriteriaFormatId.GetValueOrDefault(0) == (int)SimpleDatum.DATA_FORMAT.SEGMENTATION ||
1995 nDataCriteriaFormatId.GetValueOrDefault(0) == (int)SimpleDatum.DATA_FORMAT.ANNOTATION_DATA))
1996 {
1997 LoadRawImageData(img, true, false);
1998 rgDataCriteria = img.DataCriteria;
1999 }
2000
2001 int nHeight = img.Height.GetValueOrDefault();
2002 int nWidth = img.Width.GetValueOrDefault();
2003 int nChannels = img.Channels.GetValueOrDefault();
2004 SimpleDatum sd = null;
2005
2006 if (img.Encoded.GetValueOrDefault())
2007 {
2008 Tuple<double[], float[]> rgRealData = SimpleDatum.GetRealData(rgData, nPadW, nPadH, nHeight, nWidth, nChannels);
2009 double[] rgDataFloat = rgRealData.Item1;
2010 float[] rgDataDouble = rgRealData.Item2;
2011
2012 if (rgDataFloat != null)
2013 {
2014 sd = new SimpleDatum(img.Encoded.GetValueOrDefault(),
2015 nChannels,
2016 nWidth + nPadW,
2017 nHeight + nPadH,
2018 img.ActiveLabel.GetValueOrDefault(),
2019 img.TimeStamp.GetValueOrDefault(),
2020 rgDataFloat,
2021 img.ActiveBoost.GetValueOrDefault(),
2022 img.AutoLabel.GetValueOrDefault(),
2023 img.Idx.GetValueOrDefault(),
2024 img.VirtualID.GetValueOrDefault(),
2025 img.ID,
2026 img.SourceID.GetValueOrDefault(),
2027 img.OriginalSourceID.GetValueOrDefault());
2028 }
2029 else
2030 {
2031 sd = new SimpleDatum(img.Encoded.GetValueOrDefault(),
2032 nChannels,
2033 nWidth + nPadW,
2034 nHeight + nPadH,
2035 img.ActiveLabel.GetValueOrDefault(),
2036 img.TimeStamp.GetValueOrDefault(),
2037 rgDataDouble,
2038 img.ActiveBoost.GetValueOrDefault(),
2039 img.AutoLabel.GetValueOrDefault(),
2040 img.Idx.GetValueOrDefault(),
2041 img.VirtualID.GetValueOrDefault(),
2042 img.ID,
2043 img.SourceID.GetValueOrDefault(),
2044 img.OriginalSourceID.GetValueOrDefault());
2045 }
2046 }
2047 else
2048 {
2049 byte[] rgDataBytes = SimpleDatum.GetByteData(rgData, nPadW, nPadH, nHeight, nWidth, nChannels);
2050 sd = new SimpleDatum(img.Encoded.GetValueOrDefault(),
2051 nChannels,
2052 nWidth + nPadW,
2053 nHeight + nPadH,
2054 img.ActiveLabel.GetValueOrDefault(),
2055 img.TimeStamp.GetValueOrDefault(),
2056 rgDataBytes,
2057 img.ActiveBoost.GetValueOrDefault(),
2058 img.AutoLabel.GetValueOrDefault(),
2059 img.Idx.GetValueOrDefault(),
2060 img.VirtualID.GetValueOrDefault(),
2061 img.ID,
2062 img.SourceID.GetValueOrDefault(),
2063 img.OriginalSourceID.GetValueOrDefault());
2064 }
2065
2066 sd.OriginalLabel = img.OriginalLabel.GetValueOrDefault();
2067 sd.Description = img.Description;
2068 sd.GroupID = img.GroupID.GetValueOrDefault();
2069 sd.DataCriteria = rgDataCriteria;
2070 sd.DataCriteriaFormat = (SimpleDatum.DATA_FORMAT)nDataCriteriaFormatId.GetValueOrDefault(0);
2071 sd.DebugData = rgDebugData;
2072 sd.DebugDataFormat = (SimpleDatum.DATA_FORMAT)nDebugDataFormatId.GetValueOrDefault(0);
2073
2075
2076 return sd;
2077 }
2078
2086 public SimpleDatum LoadDatum(RawImageMean img, int nPadW = 0, int nPadH = 0)
2087 {
2088 if (img == null)
2089 return null;
2090
2091 int nHeight = img.Height.GetValueOrDefault();
2092 int nWidth = img.Width.GetValueOrDefault();
2093 int nChannels = img.Channels.GetValueOrDefault();
2094 SimpleDatum sd;
2095
2096 if (img.Encoded.GetValueOrDefault())
2097 {
2098 Tuple<double[], float[]> rgRealData = SimpleDatum.GetRealData(img.Data, nPadW, nPadH, nHeight, nWidth, nChannels);
2099 double[] rgDataFloat = rgRealData.Item1;
2100 float[] rgDataDouble = rgRealData.Item2;
2101
2102 if (rgDataFloat != null)
2103 {
2104 sd = new SimpleDatum(img.Encoded.GetValueOrDefault(),
2105 nChannels,
2106 nWidth + nPadW,
2107 nHeight + nPadH,
2108 0,
2109 DateTime.MinValue,
2110 rgDataFloat,
2111 0,
2112 false,
2113 0,
2114 0,
2115 img.ID,
2116 img.SourceID.GetValueOrDefault());
2117 }
2118 else
2119 {
2120 sd = new SimpleDatum(img.Encoded.GetValueOrDefault(),
2121 nChannels,
2122 nWidth + nPadW,
2123 nHeight + nPadH,
2124 0,
2125 DateTime.MinValue,
2126 rgDataDouble,
2127 0,
2128 false,
2129 0,
2130 0,
2131 img.ID,
2132 img.SourceID.GetValueOrDefault());
2133 }
2134 }
2135 else
2136 {
2137 byte[] rgDataBytes = SimpleDatum.GetByteData(img.Data, nPadW, nPadH, nHeight, nWidth, nChannels);
2138 sd = new SimpleDatum(img.Encoded.GetValueOrDefault(),
2139 nChannels,
2140 nWidth + nPadW,
2141 nHeight + nPadH,
2142 0,
2143 DateTime.MinValue,
2144 rgDataBytes,
2145 0,
2146 false,
2147 0,
2148 0,
2149 img.ID,
2150 img.SourceID.GetValueOrDefault());
2151 }
2152
2153 return sd;
2154 }
2155
2162 public SimpleDatum LoadImage(int nImageId, int nSrcId = 0)
2163 {
2164 if (m_db.CurrentSource == null)
2165 throw new Exception("You must open a data source first!");
2166
2167 if (nSrcId == 0)
2168 nSrcId = m_db.CurrentSource.ID;
2169
2170 RawImage img = m_db.GetRawImage(nImageId);
2171 if (img == null || img.SourceID != nSrcId)
2172 return null;
2173
2174 return LoadDatum(img);
2175 }
2176
2183 public SimpleDatum LoadImageMean(int nSrcId, ConnectInfo ci = null)
2184 {
2185 RawImageMean imgMean = m_db.GetRawImageMean(nSrcId, ci);
2186 if (imgMean == null)
2187 return null;
2188
2189 return LoadDatum(imgMean);
2190 }
2191
2202 public SimpleDatum LoadImageAt(int nIdx, bool? bLoadDataCriteria = null, bool? bLoadDebugData = null, int nSrcId = 0, int nPadW = 0, int nPadH = 0)
2203 {
2204 RawImage img = m_db.GetRawImageAt(nIdx, nSrcId);
2205 if (img == null)
2206 return null;
2207
2208 if (!bLoadDataCriteria.HasValue)
2209 bLoadDataCriteria = m_bLoadDataCriteria;
2210
2211 if (bLoadDataCriteria.Value && img.DataCriteria != null)
2212 img.DataCriteria = m_db.GetRawImageDataCriteria(img.DataCriteria);
2213
2214 if (!bLoadDebugData.HasValue)
2215 bLoadDebugData = m_bLoadDebugData;
2216
2217 if (bLoadDebugData.Value && img.DebugData != null)
2218 img.DebugData = m_db.GetRawImageDebugData(img.DebugData);
2219
2220 return LoadDatum(img, nPadW, nPadH);
2221 }
2222
2229 public SimpleResult LoadResult(RawImageResult res, bool bRequireExtraData = false)
2230 {
2231 int nSrcID = res.SourceID.GetValueOrDefault();
2232 DateTime dt = res.TimeStamp.GetValueOrDefault();
2233 int nIdx = res.Idx.GetValueOrDefault();
2234
2235 int nResCount = res.ResultCount.GetValueOrDefault();
2236 int nBatchCount = res.BatchCount.GetValueOrDefault();
2237 List<Tuple<SimpleDatum, List<Result>>> rgRes = ResultDescriptor.GetResults(nBatchCount, res.Results);
2238 List<float> rgResults = new List<float>();
2239
2240 for (int i = 0; i < rgRes.Count; i++)
2241 {
2242 for (int j = 0; j < rgRes[i].Item2.Count; j++)
2243 {
2244 rgResults.Add((float)rgRes[i].Item2[j].Score);
2245 }
2246 }
2247
2248 float[] rgResult1 = rgResults.ToArray();
2249 List<Tuple<DateTime, int>> rgTarget1 = new List<Tuple<DateTime, int>>();
2250
2251 if (res.ExtraData == null && bRequireExtraData)
2252 return null;
2253
2254 rgTarget1 = Database.UnpackExtraData(res.ExtraData);
2255
2256 return new SimpleResult(nSrcID, nIdx, dt, nBatchCount, nResCount, rgResult1, rgTarget1);
2257 }
2258
2265 public void LoadRawData(SimpleDatum sd, bool bLoadDataCriteria, bool bLoadDebugData)
2266 {
2267 if (bLoadDataCriteria && sd.DataCriteria != null)
2269
2270 if (bLoadDebugData && sd.DebugData != null)
2272 }
2273
2282 public List<LabelDescriptor> LoadLabels(int nSrcId = 0, bool bSort = true, bool bWithImagesOnly = false, ConnectInfo ci = null)
2283 {
2284 List<Label> rgLabels = m_db.GetLabels(bSort, bWithImagesOnly, nSrcId, ci);
2285 List<LabelDescriptor> rgDesc = new List<LabelDescriptor>();
2286
2287 foreach (Label l in rgLabels)
2288 {
2289 LabelDescriptor label = new LabelDescriptor(l.Label1.GetValueOrDefault(),
2290 l.ActiveLabel.GetValueOrDefault(),
2291 l.Name,
2292 l.ImageCount.GetValueOrDefault());
2293 rgDesc.Add(label);
2294 }
2295
2296 return rgDesc;
2297 }
2298
2304 public SourceDescriptor LoadSource(string strSource)
2305 {
2306 return LoadSource(m_db.GetSourceID(strSource));
2307 }
2308
2315 public SourceDescriptor LoadSource(int nSrcId, ConnectInfo ci = null)
2316 {
2317 Source src = m_db.GetSource(nSrcId, ci);
2318
2319 if (src == null)
2320 return null;
2321
2322 SourceDescriptor srcDesc = new SourceDescriptor(src.ID,
2323 src.Name,
2324 src.ImageHeight.GetValueOrDefault(),
2325 src.ImageWidth.GetValueOrDefault(),
2326 src.ImageChannels.GetValueOrDefault(),
2327 src.ImageEncoded.GetValueOrDefault(),
2328 src.SaveImagesToFile.GetValueOrDefault(),
2329 src.CopyOfSourceID.GetValueOrDefault(0),
2330 src.OwnerID,
2331 src.ImageCount.GetValueOrDefault());
2332 srcDesc.Labels = LoadLabels(nSrcId, true, false, ci);
2333 srcDesc.LabelCountsAsText = m_db.GetLabelCountsAsText(nSrcId, ci);
2334 srcDesc.SetInactiveImageCount(m_db.GetImageCount(nSrcId, false, true, ci));
2335 srcDesc.Parameters = LoadSourceParameters(srcDesc.ID, ci);
2336
2337 return srcDesc;
2338 }
2339
2347 {
2349
2350 Dictionary<string, string> rgParam = m_db.GetSourceParameters(nSrcId, ci);
2351 foreach (KeyValuePair<string, string> kv in rgParam)
2352 {
2353 col.Add(new ParameterDescriptor(0, kv.Key, kv.Value));
2354 }
2355
2356 return col;
2357 }
2358
2365 public GroupDescriptor LoadDatasetGroup(int nGroupId, ConnectInfo ci = null)
2366 {
2367 DatasetGroup grp = m_db.GetDatasetGroup(nGroupId, ci);
2368
2369 if (grp == null)
2370 return null;
2371
2372 return new GroupDescriptor(nGroupId, grp.Name, grp.OwnerID);
2373 }
2374
2381 public GroupDescriptor LoadModelGroup(int nGroupId, ConnectInfo ci = null)
2382 {
2383 ModelGroup grp = m_db.GetModelGroup(nGroupId, ci);
2384
2385 if (grp == null)
2386 return null;
2387
2388 return new GroupDescriptor(nGroupId, grp.Name, grp.OwnerID);
2389 }
2390
2397 public DatasetDescriptor LoadDataset(string strDataset, ConnectInfo ci = null)
2398 {
2399 return LoadDataset(m_db.GetDatasetID(strDataset, ci), ci);
2400 }
2401
2408 public DatasetDescriptor LoadDataset(int nDatasetID, ConnectInfo ci = null)
2409 {
2410 Dataset ds = m_db.GetDataset(nDatasetID, ci);
2411 if (ds == null)
2412 return null;
2413
2414 return loadDataset(ds, ci);
2415 }
2416
2423 public DatasetDescriptor LoadDataset(int nDatasetID, string strDataset)
2424 {
2425 DatasetDescriptor ds = null;
2426
2427 if (nDatasetID != 0)
2428 ds = LoadDataset(nDatasetID);
2429
2430 if (ds == null && !String.IsNullOrEmpty(strDataset))
2431 ds = LoadDataset(strDataset);
2432
2433 return ds;
2434 }
2435
2442 public DatasetDescriptor LoadDataset(string strTestingSrc, string strTrainingSrc)
2443 {
2444 Dataset ds = m_db.GetDataset(strTestingSrc, strTrainingSrc);
2445 if (ds == null)
2446 return null;
2447
2448 return loadDataset(ds);
2449 }
2450
2456 public List<DatasetDescriptor> LoadAllDatasetsWithCreators(int nGroupId)
2457 {
2458 List<Dataset> rgDs = m_db.GetAllDatasetsWithCreators(nGroupId);
2459 List<DatasetDescriptor> rgDesc = new List<DatasetDescriptor>();
2460
2461 foreach (Dataset ds in rgDs)
2462 {
2463 rgDesc.Add(loadDataset(ds));
2464 }
2465
2466 return rgDesc;
2467 }
2468
2475 public List<DatasetDescriptor> LoadAllDatasetsWithCreator(int nCreatorID, bool? bRelabeled = null)
2476 {
2477 List<Dataset> rgDs = m_db.GetAllDatasetsWithCreator(nCreatorID, bRelabeled);
2478 List<DatasetDescriptor> rgDesc = new List<DatasetDescriptor>();
2479
2480 foreach (Dataset ds in rgDs)
2481 {
2482 rgDesc.Add(LoadDataset(ds.ID));
2483 }
2484
2485 return rgDesc;
2486 }
2487
2494 protected virtual DatasetDescriptor loadDataset(Dataset ds, ConnectInfo ci = null)
2495 {
2496 SourceDescriptor srcTrain = LoadSource(ds.TrainingSourceID.GetValueOrDefault(), ci);
2497 SourceDescriptor srcTest = LoadSource(ds.TestingSourceID.GetValueOrDefault(), ci);
2498 GroupDescriptor dsGroup = LoadDatasetGroup(ds.DatasetGroupID.GetValueOrDefault(), ci);
2499 GroupDescriptor mdlGroup = LoadModelGroup(ds.ModelGroupID.GetValueOrDefault(), ci);
2500 string strCreatorName = m_db.GetDatasetCreatorName(ds.DatasetCreatorID.GetValueOrDefault(), ci);
2501 DatasetDescriptor dsDesc = new DatasetDescriptor(ds.ID, ds.Name, mdlGroup, dsGroup, srcTrain, srcTest, strCreatorName, ds.OwnerID, ds.Description);
2502
2503 dsDesc.Parameters = LoadDatasetParameters(ds.ID, ci);
2504
2505 return dsDesc;
2506 }
2507
2515 {
2517
2518 Dictionary<string, string> rgParam = m_db.GetDatasetParameters(nDsId, ci);
2519 foreach (KeyValuePair<string, string> kv in rgParam)
2520 {
2521 col.Add(new ParameterDescriptor(0, kv.Key, kv.Value));
2522 }
2523
2524 return col;
2525 }
2526
2532 public List<ResultDescriptor> LoadRawImageResults(int nSrcId = 0)
2533 {
2534 List<RawImageResult> rgResults = m_db.GetRawImageResults(nSrcId);
2535 List<ResultDescriptor> rgDesc = new List<ResultDescriptor>();
2536
2537 foreach (RawImageResult res in rgResults)
2538 {
2539 rgDesc.Add(new ResultDescriptor(res.ID, null, null, res.Idx.GetValueOrDefault(), res.Label.GetValueOrDefault(), res.ResultCount.GetValueOrDefault(), res.Results, res.SourceID.GetValueOrDefault(), res.TimeStamp.GetValueOrDefault()));
2540 }
2541
2542 return rgDesc;
2543 }
2544
2545 #endregion
2546 }
2547
2548 class ParamCache
2549 {
2550 List<ParameterData> m_rgParam = new List<ParameterData>();
2551 int m_nMax;
2552
2553 public ParamCache(int nMax)
2554 {
2555 m_nMax = nMax;
2556 }
2557
2558 public int Count
2559 {
2560 get { return m_rgParam.Count; }
2561 }
2562
2563 public void Clear()
2564 {
2565 m_rgParam.Clear();
2566 }
2567
2568 public bool Add(ParameterData p)
2569 {
2570 m_rgParam.Add(p);
2571
2572 if (m_rgParam.Count == m_nMax)
2573 return true;
2574
2575 return false;
2576 }
2577
2578 public List<ParameterData> Parameters
2579 {
2580 get { return m_rgParam; }
2581 }
2582 }
2583
2584 class ImageCache
2585 {
2586 List<RawImage> m_rgImages = new List<RawImage>();
2587 List<List<ParameterData>> m_rgrgParams = new List<List<ParameterData>>();
2588 int m_nMax;
2589
2590 public ImageCache(int nMax)
2591 {
2592 m_nMax = nMax;
2593 }
2594
2595 public int Count
2596 {
2597 get { return m_rgImages.Count; }
2598 }
2599
2600 public void Clear()
2601 {
2602 m_rgImages.Clear();
2603 m_rgrgParams.Clear();
2604 }
2605
2606 public bool Add(RawImage img, SimpleDatum sd, params ParameterData[] rgParams)
2607 {
2608 m_rgImages.Add(img);
2609
2610 List<ParameterData> rgParam = new List<db.image.ParameterData>();
2611
2612 if (sd is Datum)
2613 {
2614 Datum d = sd as Datum;
2615 string strVal = d.Tag as string;
2616 string strTag = d.TagName as string;
2617
2618 if (!String.IsNullOrEmpty(strTag) && !String.IsNullOrEmpty(strVal))
2619 rgParam.Add(new db.image.ParameterData(strTag, strVal, null, null, img.ID, false, img.SourceID.GetValueOrDefault()));
2620 }
2621
2622 foreach (ParameterData param in rgParams)
2623 {
2624 param.ImageID = img.ID;
2625 param.SourceID = img.SourceID.GetValueOrDefault();
2626 rgParam.Add(param);
2627 }
2628
2629 m_rgrgParams.Add(rgParam);
2630
2631 if (m_rgImages.Count == m_nMax)
2632 return true;
2633
2634 return false;
2635 }
2636
2637 public List<RawImage> Images
2638 {
2639 get { return m_rgImages; }
2640 }
2641
2642 public List<List<ParameterData>> Parameters
2643 {
2644 get { return m_rgrgParams; }
2645 }
2646 }
2647
2652 {
2653 int m_nLabel;
2654 double m_dfBoost;
2655
2661 public LabelBoostDescriptor(int nLabel, double dfBoost)
2662 {
2663 m_nLabel = nLabel;
2664 m_dfBoost = dfBoost;
2665 }
2666
2670 public int Label
2671 {
2672 get { return m_nLabel; }
2673 }
2674
2678 public double Boost
2679 {
2680 get { return m_dfBoost; }
2681 }
2682 }
2683}
Defines a collection of AnnotationGroups.
Definition: Annotation.cs:256
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
Definition: CancelEvent.cs:17
WaitHandle[] Handles
Returns the internal wait handle of the CancelEvent.
Definition: CancelEvent.cs:302
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
Definition: ConnectInfo.cs:14
The Datum class is a simple wrapper to the SimpleDatum class to ensure compatibility with the origina...
Definition: Datum.cs:12
The LabelMapping class represents a single label mapping.
The Log class provides general output in text form.
Definition: Log.cs:13
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
string TagName
Returns a user-defined name of the tag associated with the data.
Definition: SimpleDatum.cs:910
int OriginalLabel
Get/set the original known label of the data.
static SimpleDatum CalculateMean(Log log, SimpleDatum[] rgImg, WaitHandle[] rgAbort)
Calculate the mean of an array of SimpleDatum and return the mean as a new SimpleDatum.
byte[] DebugData
Get/set debug data associated with the data.
object Tag
Specifies user data associated with the SimpleDatum.
Definition: SimpleDatum.cs:901
string Description
Get/set a description of the data.
static byte[] GetByteData(byte[] rgData, int nImagePadX, int nImagePadY, int nHeight, int nWidth, int nChannels)
Return the non-real data as a byte array after padding the data.
static AnnotationGroupCollection LoadAnnotationDataFromDataCriteria(byte[] rg, DATA_FORMAT fmt, out ANNOTATION_TYPE type)
Load the AnnotationGroups from the byte array.
int OriginalSourceID
Returns the original source ID which is set when using a virtual ID.
byte[] DataCriteria
Get/set data criteria associated with the data.
DATA_FORMAT
Defines the data format of the DebugData and DataCriteria when specified.
Definition: SimpleDatum.cs:223
int GroupID
Get/set the group ID of the SimpleDatum.
DATA_FORMAT DebugDataFormat
Get/set the data format of the debug data.
int Height
Return the height of the data.
DATA_FORMAT DataCriteriaFormat
Get/set the data format of the data criteria.
static Tuple< double[], float[]> GetRealData(byte[] rgData, int nImagePadX, int nImagePadY, int nHeight, int nWidth, int nChannels)
Return the real data as a double or float array (depending on the original encoding data type) after ...
The SimpleResult class holds the result data stored in the RawImageResults table.
Definition: SimpleResult.cs:14
int SourceID
Returns the source ID of the data source associated with the result.
Definition: SimpleResult.cs:50
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
GroupDescriptor DatasetGroup
Returns the dataset group.
SourceDescriptor TrainingSource
Get/set the training data source.
GroupDescriptor ModelGroup
Get/set the dataset model group.
string CreatorName
Returns the dataset creator name.
SourceDescriptor TestingSource
Get/set the testing data source.
ParameterDescriptorCollection Parameters
Get/set the dataset parameters (if any).
The GroupDescriptor class defines a group.
The ImageDescriptor class describes a single image in the database.
The LabelDescriptor class describes a single label.
The ParameterDescriptorCollection class contains a list of ParameterDescriptor's.
The ParameterDescriptor class describes a parameter in the database.
The ResultDescriptor class describes the results of a run.
static List< Result > GetResults(byte[] rgData)
Extract the results from the binary data.
The SourceDescriptor class contains all information describing a data source.
void SetInactiveImageCount(int nCount)
Set the number of inactive images within this data source.
int CopyOfSourceID
Get/set the Source ID from which this source was copied. If this Source is an original,...
bool IsRealData
Returns whether or not the each data point represents a real or integer number. Integer numbers are u...
List< LabelDescriptor > Labels
Get/set the list of LabelDescriptors that describe the labels used by the data items.
int Height
Returns the height of each data item in the data source.
bool SaveImagesToFile
Gets whether or not the images are saved to the file system (true), or directly to the database (fals...
int Width
Returns the width of each data item in the data source.
ParameterDescriptorCollection Parameters
Get/set the source parameters (if any).
string LabelCountsAsText
Get/set a string that lists the number of images for each label associated with this data source.
int Channels
Returns the item colors - 1 channel = black/white, 3 channels = RGB color.
The Database class manages the actual connection to the physical database using Entity Framworks from...
Definition: Database.cs:23
Dataset GetDataset(int nID, ConnectInfo ci=null)
Returns the Dataset entity for a dataset ID.
Definition: Database.cs:4648
void ActivateRawImageByIndex(int nSrcId, int nIdx, bool bActive)
Activate/deactivate a raw image based on its index.
Definition: Database.cs:1866
bool ChangeRawImageSourceID(int nID, int nNewSrcID, bool bSave=true)
Change the data source ID on a raw image - currently only allowed on virtual raw images.
Definition: Database.cs:1713
void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, params int[] rgSrcId)
Activate all raw images associated with a set of source ID's.
Definition: Database.cs:3024
int GetBoostCount(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Return the number of boosted images for a data source.
Definition: Database.cs:2748
void SetSourceParameter(string strName, string strValue, int nSrcId=0)
Set the value of a data source parameter.
Definition: Database.cs:4361
FORCE_LOAD
Defines the force load type.
Definition: Database.cs:57
string GetDatasetCreatorName(int nDatasetCreatorID, ConnectInfo ci=null)
Returns the name of a dataset creator given its ID.
Definition: Database.cs:5225
List< RawImage > GetRawImagesAt(int nIdx, int nCount, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
Definition: Database.cs:1243
void UpdateSourceCounts(int nImageCount, ConnectInfo ci=null)
Updates the source counts for the open data source.
Definition: Database.cs:3967
List< Tuple< SimpleDatum, List< Result > > > GetRawImageResultBatch(int nBatchCount, byte[] rgResults)
Extracts the raw image result batch from the result binary data.
Definition: Database.cs:3293
void UpdateActiveLabelByIndex(int nSrcId, int nIdx, int nLabel)
Update the label value of a label.
Definition: Database.cs:1774
void DisableLabel(int nSrcId, int nLabel, bool bOriginalLabel=false)
Disable a set of labels within the source specified by the ID.
Definition: Database.cs:1816
virtual void Open(int nSrcId, FORCE_LOAD nForceLoad=FORCE_LOAD.NONE, ConnectInfo ci=null)
Opens a data source.
Definition: Database.cs:188
List< Dataset > GetAllDatasetsWithCreators(int nDatasetGroupID)
Returns a list of all datasets within a group with dataset creators.
Definition: Database.cs:5160
void SetLabelMapping(LabelMapping map, int nSrcId=0)
Saves a label mapping in the database for a data source.
Definition: Database.cs:830
bool ConvertRawImagesSaveToFile(int nIdx, int nCount, CancelEvent evtCancel=null)
The ConvertRawImagesSaveToFile method saves the image in the database to the file system and replaces...
Definition: Database.cs:2126
void ActivateLabels(List< int > rgLabels, bool bActive, params int[] rgSrcId)
Activate (or deactivate) the labels specified for each of the source ID's specified.
Definition: Database.cs:1013
bool GetRawImageParameterExist(string strName, int nSrcId=0, string strType="TEXT")
Returns whether or not a given RawImage parameter exists.
Definition: Database.cs:3681
bool UpdateActiveLabel(int nID, int nLabel, bool bActivate=true, bool bSaveChanges=true)
Update the label value of a label.
Definition: Database.cs:1739
int SetRawImageParameter(int nRawImageID, string strName, string strValue, double? dfVal=null, byte[] rgData=null, bool bSave=true, bool bOnlyAddNew=false, DNNEntities entities=null)
Add a new RawImage parameter (or update an existing if found).
Definition: Database.cs:3527
int GetDatasetCreatorID(string strName)
Returns the ID of a dataset creator given its name.
Definition: Database.cs:5249
bool ConvertRawImagesSaveToDatabase(int nIdx, int nCount, CancelEvent evtCancel=null)
The ConvertRawImagesSaveToDatabase method saves the image in the file system to the database and dele...
Definition: Database.cs:2226
List< Label > GetLabels(bool bSort=true, bool bWithImagesOnly=false, int nSrcId=0, ConnectInfo ci=null)
Returns a list of all labels used by a data source.
Definition: Database.cs:710
virtual void Close()
Close the previously opened data source.
Definition: Database.cs:277
Source CurrentSource
Returns the current entity framwork Source object set during the previous call to Open().
Definition: Database.cs:178
int AddSource(string strName, int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nCopyOfSourceID=0, bool bSaveImagesToFile=true, ConnectInfo ci=null)
Adds a new data source to the database.
Definition: Database.cs:4134
DateTime GetLastTimeStamp(int nSrcId=0, string strDesc=null)
Returns the last time-stamp in the data source.
Definition: Database.cs:4424
int GetRawImageParameterCount(string strName, int nSrcId=0, string strType="TEXT")
Returns the RawImage parameter count for a data source.
Definition: Database.cs:3654
List< RawImageResult > GetRawImageResults(int nSrcId=0, bool bRequireExtraData=false, int nMax=-1)
Returns the RawImageResults for a data source.
Definition: Database.cs:3329
void SetDatasetParameters(int nDsId, Dictionary< string, string > rgP)
Adds a batch of new parametes.
Definition: Database.cs:5059
List< DbItem > GetAllRawImageIndexes(bool bBoostedOnly, bool bIncludeActive=true, bool bIncludeInactive=false)
Returns the list of the image indexes of all images.
Definition: Database.cs:1132
void UpdateLabelName(int nLabel, string strName, int nSrcId=0)
Update the name of a label.
Definition: Database.cs:363
void SaveLabelCache()
Saves the label cache to the database.
Definition: Database.cs:517
byte[] GetRawImageParameterData(int nRawImageID, string strName)
Return the byte array data of a RawImage parameter.
Definition: Database.cs:3483
bool UpdateRawImageSourceID(int nImageID, int nSrcID)
Updates a given image's source ID.
Definition: Database.cs:2968
string GetDatasetName(int nID, ConnectInfo ci=null)
Returns the name of a dataset given its ID.
Definition: Database.cs:4632
void Refresh()
Close and re Open with the current data source.
Definition: Database.cs:294
void UpdateSaveImagesToFile(bool bSaveToFile, int nSrcId=0)
Update the SaveImagesToFile flag in a given Data Source.
Definition: Database.cs:3906
RawImage GetRawImage(int nID)
Returns the RawImage with a given ID.
Definition: Database.cs:2494
List< string > GetRawImageDistinctParameterDescriptions(int nSrcId=0)
Returns a list of distinct RawImage parameter descriptions for a data source.
Definition: Database.cs:3715
static List< Tuple< DateTime, int > > UnpackExtraData(byte[] rg)
Unpack the extra data from a byte array.
Definition: Database.cs:3376
RawImageMean GetRawImageMean(int nSrcId=0, ConnectInfo ci=null)
Return the RawImageMean for the image mean from the open data source.
Definition: Database.cs:2583
string GetSourceParameter(string strName, int nSrcId=0)
Return the data source parameter as a string.
Definition: Database.cs:4283
void ResetLabels(int nProjectId=0, int nSrcId=0)
Resets all labels back to their original labels for a project.
Definition: Database.cs:894
void DeleteLabelBoosts(int nProjectId, int nSrcId=0)
Delete all label boosts for a project.
Definition: Database.cs:916
int AddRawImageGroup(Image img, int nIdx, DateTime dtStart, DateTime dtEnd, List< double > rgProperties)
Adds a new RawImage group to the database.
Definition: Database.cs:3755
void ResetAllActiveLabels(int nSrcId)
Reset the all active labels to their original label within a source.
Definition: Database.cs:1803
int GetSourceID(string strName, ConnectInfo ci=null)
Returns the ID of a data source given its name.
Definition: Database.cs:4018
void UpdateLabelMapping(int nNewLabel, List< int > rgOriginalLabels, int nSrcId=0)
Update a label mapping in the database for a data source.
Definition: Database.cs:866
Dictionary< string, string > GetDatasetParameters(int nDsId, ConnectInfo ci=null)
Returns all dataset parameters for a given dataset.
Definition: Database.cs:4934
void SetDatasetParameter(int nDsId, string strName, string strValue)
Adds a new parameter or Sets the value of an existing dataset parameter.
Definition: Database.cs:5027
void FixupRawImageCopy(int nImageID, int nSecondarySrcId)
The FixupRawImageCopy method is used to fixup the OriginalSourceId by setting it to a secondary sourc...
Definition: Database.cs:2324
int DisableAllNonMatchingImages(int nSrcId, int nWidth, int nHeight)
Disable all images that do not have a matching widxht size.
Definition: Database.cs:1847
Dictionary< string, string > GetSourceParameters(int nSrcId=0, ConnectInfo ci=null)
Returns a dictionary of the data source parameters.
Definition: Database.cs:4258
int FindDatasetFromSourceId(int nSourceId)
Searches for the dataset containing the sourceId.
Definition: Database.cs:4594
List< int > QueryAllRawImageIDs(int nSrcId=0, int nMax=int.MaxValue, int nLabel=-1, int nBoost=-1, bool bBoostIsExact=false, bool bAnnotatedOnly=false, bool bActiveOnly=true)
Returns the ID's of all RawImages within a data source.
Definition: Database.cs:1959
void DeleteSourceData()
Deletes the data source data for the open data source.
Definition: Database.cs:3896
int AddDataset(int nDsCreatorID, string strName, int nTestSrcId, int nTrainSrcId, int nDsGroupID=0, int nModelGroupID=0, ConnectInfo ci=null, bool bVerify=true)
Add a new (or update an existing if exists) dataset to the database.
Definition: Database.cs:4719
int FindRawImageGroupID(int nIdx, DateTime dtStart, DateTime dtEnd)
Searches fro the RawImageGroup ID.
Definition: Database.cs:3850
List< RawImageParameter > QueryRawImageParameters(int nSrcId, string strName)
Query a list of all raw image parameters of a give name stored with a given source ID.
Definition: Database.cs:1179
int GetDatasetID(string strName, ConnectInfo ci=null)
Returns a datasets ID given its name.
Definition: Database.cs:4612
void AddLabelBoost(int nProjectId, int nLabel, double dfBoost, int nSrcId=0)
Add a label boost to the database for a given project.
Definition: Database.cs:794
void DisableAllLabels(int nSrcId)
Disable all labels within the source specified by the ID.
Definition: Database.cs:1833
ModelGroup GetModelGroup(int nGroupID, ConnectInfo ci=null)
Returns the ModelGroup entity given the ID of a model group.
Definition: Database.cs:5487
void UpdateAllActiveLabels(int nSrcId, int nLabel, int? nOriginalLabel)
Update the all items to a label value for the given nSrcId.
Definition: Database.cs:1788
byte[] GetRawImageDataCriteria(RawImage img, out int? nDataCriteriaFmtId)
Returns the raw data criteria data of the RawImage.
Definition: Database.cs:1431
int GetDatasetGroupID(string strName)
Returns the ID of a dataset group given its name.
Definition: Database.cs:5206
void UpdateDatasetImageAnnotations(int nSrcId, int nImageId, AnnotationGroupCollection annotations, bool bSetLabelOnly)
Update the annotations of a given raw image.
Definition: Database.cs:3125
Source GetSource(string strName, ConnectInfo ci=null)
Returns the Source entity given a data source name.
Definition: Database.cs:4051
List< RawImage > GetRawImagesAtID(List< int > rgImageID, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
Definition: Database.cs:1299
void UpdateActiveLabelDirect(int nID, int nLabel)
Directly update the active label and activate the image with the specified ID.
Definition: Database.cs:1880
RawImage CreateRawImage(int nIdx, SimpleDatum d, int nBackgroundWritingThreadCount, string strDescription=null, int? nOriginalSourceID=null, bool bActive=true)
Create a new RawImage but do not add it to the database.
Definition: Database.cs:1998
void UpdateDatasetDescription(int nDsId, string strDesc)
Update the description of a given dataset.
Definition: Database.cs:4802
void PutRawImages(List< RawImage > rgImg, List< List< ParameterData > > rgrgParam=null, ConnectInfo ci=null)
Saves a List of RawImages to the database.
Definition: Database.cs:2413
void UpdateSource(int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nSrcId=0)
Updates a data source.
Definition: Database.cs:3934
RawImage GetRawImageAt(int nIdx, int nSrcId=0)
Returns the RawImage at a given image index.
Definition: Database.cs:1334
int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List< Result > rgResults, bool bInvert, List< Tuple< DateTime, int > > rgExtra=null)
Save the results of a Run as a RawImageResult.
Definition: Database.cs:3199
string GetLabelName(int nLabel, int nSrcId=0)
Get the Label name of a label within a data source.
Definition: Database.cs:416
void UpdateDatasetCounts(int nDsId, ConnectInfo ci=null)
Update the dataset counts.
Definition: Database.cs:4821
int GetRawImageID(DateTime dt, int nSrcId=0)
Returns the RawImage ID for the image with the given time-stamp.
Definition: Database.cs:1359
void ResetAllDatasetRelabelWithCreator(int nDsCreatorID)
Reset all dataset relabel flags with a given creator.
Definition: Database.cs:5266
int GetImageCount()
Returns the number of raw images in the database for the open data source.
Definition: Database.cs:1120
int AddLabel(int nLabel, string strName="", int nSrcId=0, ConnectInfo ci=null)
Add a label to the database for a data source.
Definition: Database.cs:753
int LastIndex
Returns the last image index added to the database.
Definition: Database.cs:143
void DeleteSources(params string[] rgstrSrc)
Delete the list of data sources, listed by name, from the database.
Definition: Database.cs:4197
int ActivateFiltered(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Activate the images that meet the filtering criteria in the Data Source. If no filtering criteria is ...
Definition: Database.cs:2768
bool ActivateRawImage(int nImageID, bool bActivate, bool bSave=true)
Activate/Deactivate a given image.
Definition: Database.cs:2998
void LoadLabelCounts(Dictionary< int, int > rgCounts, int nSrcId=0)
Load the label counts from the database for a data source.
Definition: Database.cs:569
byte[] GetRawImageDebugData(RawImage img, out int? nDebugDataFormatId)
Returns the raw debug data data of the RawImage.
Definition: Database.cs:1463
string GetLabelBoostsAsText(int nProjectId, int nSrcId=0, bool bSort=true)
Returns the Label boosts as a string.
Definition: Database.cs:990
int SetRawImageParameterAt(DateTime dt, string strName, string strValue, double? dfVal, byte[] rgData)
Set the RawImage parameter for all RawImages with the given time-stamp in the data source.
Definition: Database.cs:3623
List< LabelBoost > GetLabelBoosts(int nProjectId, bool bSort=true, int nSrcId=0)
Returns a list of all label boosts set on a project.
Definition: Database.cs:967
string GetSourceName(int nID, ConnectInfo ci=null)
Returns the name of a data source given its ID.
Definition: Database.cs:4035
int PutRawImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0, ConnectInfo ci=null)
Save the SimpleDatum as a RawImageMean in the database.
Definition: Database.cs:2607
string GetLabelCountsAsText(int nSrcId=0, ConnectInfo ci=null)
Returns the label counts for a given data source.
Definition: Database.cs:592
List< RawImage > ReindexRawImages(Log log, CancelEvent evtCancel, int nSrcId=0)
Reindex the RawImages of a data source.
Definition: Database.cs:2915
void SaveChanges()
Saves any changes on the open satabase.
Definition: Database.cs:168
void DeleteLabels(int nSrcId=0)
Delete the labels of a data source from the database.
Definition: Database.cs:733
void UpdateLabelCounts(Dictionary< int, int > rgCounts, DNNEntities entities)
Updates the label counts in the database for the open data source.
Definition: Database.cs:543
int PutRawImage(int nIdx, SimpleDatum d, string strDescription=null)
Save a SimpleDatum as a RawImage in the database.
Definition: Database.cs:2469
bool CopyImageMean(int nSrcIdSrc, int nSrcIdDst, ConnectInfo ci=null)
Copy the raw image mean from one source to another.
Definition: Database.cs:2662
List< RawImage > QueryRawImages(params int[] rgSrcId)
Returns the list of raw images that have a source ID from a selected list.
Definition: Database.cs:1158
void PutRawImageParameters(List< ParameterData > rgParam, ConnectInfo ci=null)
Save a list of raw image parameters.
Definition: Database.cs:2368
void UpdateDatasetRelabel(int nDsID, bool bRelabel)
Update the dataset relabel flag for a dataset.
Definition: Database.cs:5286
DateTime GetFirstTimeStamp(int nSrcId=0, string strDesc=null)
Returns the first time-stamp in the data source.
Definition: Database.cs:4399
byte[] GetRawImageData(RawImage img, bool bLoadDataCriteria, bool bLoadDebugData, out byte[] rgDataCriteria, out int? nDataCriteriaFmtId, out byte[] rgDebugData, out int? nDebugDataFmtId)
Returns the raw data of the RawImage.
Definition: Database.cs:1389
void UpdateActiveLabelByID(int nID, int nLabel)
Update the label value of a label.
Definition: Database.cs:1760
string FindDatasetNameFromSourceName(string strTrainSrc, string strTestSrc)
Searches for the data set name based on the training and testing source names.
Definition: Database.cs:4560
DatasetGroup GetDatasetGroup(int nGroupID, ConnectInfo ci=null)
Returns the DatasetGroup entity given a group ID.
Definition: Database.cs:4897
List< Dataset > GetAllDatasetsWithCreator(int nDsCreatorID, bool? bRelabeled=null)
Returns a list of all datasets within a group with dataset creators.
Definition: Database.cs:5185
string GetDatasetParameter(int nDsId, string strName)
Returns the value of a dataset parameter as a string.
Definition: Database.cs:4957
void UpdateLabelBoost(int? nTgtLbl, bool bTgtLblExact, int? nTgtBst, bool bTgtBstExact, int? nNewLbl, int? nNewBst, params int[] rgSrcId)
Update the label and boost for a given search target criteria.
Definition: Database.cs:1053
bool WaitForFileWriter(int nWait=int.MaxValue)
Wait for the file writer to complete writing all files.
Definition: Database.cs:2062
void DeleteRawImageResults(int nSrcId=0)
Delete all RawImageResults for a data source.
Definition: Database.cs:2564
The DatasetFactory manages the connection to the Database object.
DatasetDescriptor LoadDataset(int nDatasetID, string strDataset)
Load a dataset descriptor from a dataset ID or name, where the ID is tried first and name second.
void PutRawImageParameterCache(int nImageID, string strParam, string strVal, double? dfVal, byte[] rgData, bool bOnlyAddNew)
Add a new parameter to the parameter cache making sure to save once a maximum count is reached.
void DeleteRawImageResults(int nSrcId=0)
Delete all RawImageResults for a data source.
void UpdateDatasetRelabel(int nDsId, bool bRelabel)
Update the dataset relabel flag for a dataset.
int GetRawImageID(DateTime dt, int nSrcId=0)
Returns the RawImage ID for the image with the given time-stamp.
DatasetFactory(bool bLoadDataCriteria, bool bLoadDebugData)
The DatasetFactory constructor.
List< RawImage > QueryRawImages(int nSrcId, bool? bActive=null, bool bLoadCriteria=false, bool bLoadDebug=false, Log log=null, CancelEvent evtCancel=null, int nBoostVal=0, bool bExactBoostVal=false)
Returns the list of raw images that have a source ID from a selected list.
Database m_db
Specifies the Database managed.
DatasetFactory(int nSrcId)
The DatasetFactory constructor.
void LoadRawImageData(RawImage img, bool bLoadCriteria, bool bLoadDebug)
Returns the list of raw images that have a source ID from a selected list.
void AddLabelBoost(int nProjectId, int nLabel, double dfBoost, int nSrcId=0)
Add a label boost to the database for a given project.
void PutRawImageCache(int nIdx, SimpleDatum sd, int nBackgroundWritingThreadCount=0, string strDescription=null, bool bActive=true, params ParameterData[] rgParams)
Add a SimpleDatum to the RawImage cache.
int SetRawImageParameter(int nSrcID, int nRawImageID, string strName, string strValue, double? dfVal=null, byte[] rgData=null)
Add a new or Set an existing RawImage parameter.
int PutRawImage(int nIdx, SimpleDatum sd, string strDescription=null)
Save a SimpleDatum to the database.
double GetDatasetParameter(int nDsId, string strParam, double dfDefault)
Returns the value of a dataset parameter as a double.
int GetSourceParameter(string strParam, int nDefault, int nSrcId=0)
Return the data source parameter as an int.
List< RawImage > GetRawImagesAt(List< int > rgImageIdx, ManualResetEvent evtCancel, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
List< SimpleDatum > GetImagesAt(List< DbItem > rgImageItems, ManualResetEvent evtCancel, int nSrcId=0, string strDescription=null)
Returns a list of SimpleDatum from the database for a data source.
void ResetAllDatasetRelabelWithCreator(int nDsCreatorId)
Reset all dataset relabel flags with a given creator.
DatasetDescriptor LoadDataset(int nDatasetID, ConnectInfo ci=null)
Load a dataset descriptor from a dataset ID.
void UpdateDatasetDescription(int nDsId, string strDesc)
Update the description of a given dataset.
void ResetLabels(int nProjectId=0, int nSrcId=0)
Resets all labels back to their original labels for a project.
void UpdateLabelCounts(Dictionary< int, int > rgCounts)
Updates the label counts in the database for the open data source.
string GetLabelName(int nLabel, int nSrcId=0)
Get the Label name of a label within a data source.
RawImage GetRawImageFromID(int nImageID)
Returns the raw image with a specified image ID.
List< string > GetRawImageDistinctParameterDescriptions(int nSrcId)
Returns a list of distinct RawImage parameter descriptions for a data source.
SimpleDatum QueryImageMean(int nSrcId=0)
Return the SimpleDatum for the image mean from the open data source.
SimpleDatum LoadImage(int nImageId, int nSrcId=0)
Returns the image at a given image ID.
List< RawImageParameter > QueryRawImageParameters(int nSrcId, string strName)
Query a list of all raw image parameters of a give name stored with a given source ID.
int GetSourceID(string strName)
Returns the ID of a data source given its name.
int SetRawImageParameter(int nRawImageID, string strName, string strValue, double? dfVal=null, byte[] rgData=null, bool bOnlyAddNew=false)
Add a new or Set an existing RawImage parameter.
int AddSource(string strName, int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nCopyOfSourceID=0, bool bSaveImagesToFile=true, ConnectInfo ci=null)
Adds a new data source to the database.
void DeleteSources(params string[] rgstrSrc)
Delete the list of data sources, listed by name, from the database.
void UpdateSource(int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nSrcId=0)
Updates a data source.
void SetLoadingParameters(bool bLoadDataCriteria, bool bLoadDebugData)
Sets the loading parameters that are used to determine which data to load with each image.
byte[] GetRawImageDebugData(byte[] rgData, int nOriginalSourceID)
Converts the raw image debug data which may be stored as a path to the underlying data file,...
int AddLabel(int nLabel, string strName, int nSrcId=0, ConnectInfo ci=null)
Add a label to the database for a data source.
void FixupRawImageCopy(int nImageID, int nSecondarySrcId)
The FixupRawImageCopy function is used to fix errors in the copy source ID of a copied raw image....
int GetRawImageMeanID(int nSrcId=0)
Returns the raw image ID for the image mean associated with a data source.
bool SaveImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0)
Save the SimpleDatum as a RawImageMean in the database.
string GetLabelCountsAsText(int nSrcId)
Returns the label counts for a given data source.
SimpleResult LoadResult(RawImageResult res, bool bRequireExtraData=false)
Load the simple results from a RawImageResult row.
void ActivateRawImageByIndex(int nIdx, bool bActive)
Activate/deactivate a raw image based on its index.
bool ActivateRawImage(int nImageID, bool bActive, bool bSave=true)
Activate/Deactivate a given image.
void DeleteSourceData(int nSrcId=0)
Delete the data source data (images, means, results and parameters) from the database.
int AddSource(SourceDescriptor src, ConnectInfo ci=null, bool? bSaveImagesToFileOverride=null)
Adds a new data source to the database.
void UpdateActiveLabelDirect(int nID, int nLabel)
Directly update the active label and activate the image with the specified ID.
virtual DatasetDescriptor loadDataset(Dataset ds, ConnectInfo ci=null)
Loads a dataset creator from a Dataset entity.
DateTime GetLastTimeStamp(DateTime dtStart, DateTime dtEnd, bool bEndInclusive, out int nIndex, int nSrcId=0, string strDesc=null)
Returns the last time stamp within a given time range.
void UpdateSourceCounts()
Saves the label cache, updates the label counts from the database and then updates the source counts ...
RawImageMean GetRawImageMean()
Return the RawImageMean for the open data source.
DateTime GetLastTimeStamp(out int nIndex, int nSrcId=0, string strDesc=null)
Returns the last time-stamp and index in the data source.
List< RawImage > GetRawImagesAtID(List< int > rgImageId, ManualResetEvent evtCancel, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
void Refresh()
Close and re-open the current data source used.
List< ResultDescriptor > LoadRawImageResults(int nSrcId=0)
Loads a list of RawImage results for a data source.
DatasetDescriptor LoadDataset(string strTestingSrc, string strTrainingSrc)
Load the dataset descriptor that contains the testing and training data source names.
byte[] GetRawImageDebugData(int nImgID, int nOriginalSourceID)
Queries the Debug data for an image and then converts the raw image debug data which may be stored as...
DatasetDescriptor LoadDataset(string strDataset, ConnectInfo ci=null)
Load a dataset descriptor from a dataset name.
byte[] GetRawImageParameterData(int nRawImageID, string strParam)
Return the byte array data of a RawImage parameter.
SimpleDatum LoadDatum(RawImage img, int nPadW=0, int nPadH=0)
Loads a new SimpleDatum from a RawImage.
int FindDatasetFromSourceId(int nSourceId)
Searches for the dataset containing the sourceId.
SourceDescriptor m_openSource
Specifies the open source descriptor (if any).
DatasetFactory()
The DatasetFactory constructor.
int SetRawImageParameterAt(DateTime dt, string strName, string strValue, double? dfVal=null, byte[] rgData=null)
Set the RawImage parameter for all RawImages with the given time-stamp in the data source.
ConnectInfo m_ciOpen
Specifies the connection information used on open.
List< RawImage > GetRawImagesAt(int nImageIdx, int nImageCount, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
void Open(int nSrcId, int nCacheMax=500, Database.FORCE_LOAD nForceLoad=Database.FORCE_LOAD.NONE, Log log=null, ConnectInfo ci=null)
Open a given data source.
int ActivateFiltered(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Activate the images that meet the filtering criteria in the Data Source. If no filtering criteria is ...
List< SimpleDatum > GetImagesAt(List< int > rgImageIdx, ManualResetEvent evtCancel, int nSrcId=0, string strDescription=null)
Returns a list of SimpleDatum from the database for a data source.
List< DbItem > LoadImageIndexes(bool bBoostedOnly, bool bIncludeActive=true, bool bIncludeInactive=false)
Returns a list of the image indexes of all boosted images in the Data Source.
void DeleteLabels(int nSrcId=0)
Delete the labels of a data source from the database.
void UpdateLabelMapping(int nNewLabel, List< int > rgOriginalLabels, int nSrcId=0)
Update a label mapping in the database for a data source.
SimpleDatum LoadImageAt(int nIdx, bool? bLoadDataCriteria=null, bool? bLoadDebugData=null, int nSrcId=0, int nPadW=0, int nPadH=0)
Load an image at a given index.
bool m_bLoadDebugData
Specifies whether or not to load the debug data if any exists. When false, the debug data is not load...
void DisableAllLabels()
Disable all labels within the open source.
DatasetFactory(DatasetFactory factory)
The DatasetFactory constructor.
string GetDatasetParameter(int nDsId, string strParam)
Returns the value of a dataset parameter as a string.
bool CopyImageMean(string strSrcSrc, string strDstSrc)
Copy the raw image mean from one source to another.
void UpdateActiveLabelByIndex(int nIdx, int nNewActiveLabel)
Update the active label on a given raw image by its index.
string GetDatasetName(int nId, ConnectInfo ci=null)
Returns the name of a dataset given its ID.
SimpleDatum LoadImageMean(int nSrcId, ConnectInfo ci=null)
Returns the image mean for a give data source.
void SetDatasetParameter(int nDsId, string strParam, string strValue)
Adds a new parameter or Sets the value of an existing dataset parameter.
void LoadRawData(SimpleDatum sd, bool bLoadDataCriteria, bool bLoadDebugData)
Load the data criteria and/or debug data.
bool LoadDebugData
Returns whether or not the image debug data is to be loaded when loading each image.
void UpdateRawImageSourceID(int nImageID, int nSrcID)
Change the source ID on an image to another source ID.
int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List< Result > rgResults, bool bInvert, List< Tuple< DateTime, int > > rgExtra=null)
Save the results of a Run as a RawImageResult.
List< int > QueryRawImageIDs(int nSrcId=0, int nMax=int.MaxValue, int nLabel=-1, int nBoost=-1, bool bBoostIsExact=false, bool bAnnotatedOnly=false)
Returns all raw image IDs for a given data source.
bool UpdateActiveLabel(int nImageID, int nNewActiveLabel, bool bActivate=true, bool bSaveChanges=true)
Update the active label on a given raw image.
ParameterDescriptorCollection LoadDatasetParameters(int nDsId, ConnectInfo ci=null)
Loads the dataset parameters for a given dataset.
int LastIndex
Returns the index of the last image added to the database.
void UpdateActiveLabelByID(int nID, int nNewActiveLabel)
Update the active label on a given raw image by its index.
int GetDatasetID(string strDsName, ConnectInfo ci=null)
Returns a datasets ID given its name.
void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, int? nTgtLabel, bool bTargetLabelExact, int? nTgtBoost, bool bTargetBoostExact, params int[] rgSrcId)
Activate all raw images associated with a set of source ID's.
void SaveChanges()
Save the changes on the open data source.
List< ImageDescriptor > LoadImages(CancelEvent evtCancel, params int[] rgSrcId)
Load the image descriptors for a set of given source ID's.
int AddDataset(DatasetDescriptor ds, ConnectInfo ci=null, bool? bSaveImagesToFileOverride=null)
Adds or updates the training source, testing source, dataset creator and dataset to the database.
GroupDescriptor LoadDatasetGroup(int nGroupId, ConnectInfo ci=null)
Load a dataset group descriptor from a group ID.
List< Label > QueryLabels(int nSrcId=0, ConnectInfo ci=null)
Query the list of labels for a given source.
List< LabelDescriptor > LoadLabels(int nSrcId=0, bool bSort=true, bool bWithImagesOnly=false, ConnectInfo ci=null)
Load a list of LabelDescriptors for a data source.
bool GetSourceParameter(string strParam, bool bDefault, int nSrcId=0)
Return the data source parameter as a bool.
List< RawImage > GetRawImagesAt(List< DbItem > rgImgItems, ManualResetEvent evtCancel, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
DateTime GetLastTimeStamp(DateTime dtStart, DateTime dtEnd, bool bEndInclusive, int nSrcId=0, string strDesc=null)
Returns the last time-stamp in the data source from within a time period.
void UpdateAllActiveLabelsDirect(int nLabel, int? nOriginalLabel=null)
Directly update all active labels and activate all of the images for the open Source ID.
void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, params int[] rgSrcId)
Activates all images with the given source ID's.
double GetSourceParameter(string strParam, double dfDefault, int nSrcId=0)
Return the data source parameter as a double.
SimpleDatum LoadDatum(RawImageMean img, int nPadW=0, int nPadH=0)
Loads a new image mean from a RawImageMean.
bool ChangeRawImageSourceID(int nID, int nNewSrcID, bool bSave=true)
Change the data source ID on a raw image - currently only allowed on virtual raw images.
int AddRawImageGroup(Image img, int nIdx, DateTime dtStart, DateTime dtEnd, List< double > rgProperties)
Adds a new RawImage group to the database.
int PutRawImageMean(SimpleDatum sd, bool bUpdate, ConnectInfo ci=null)
Save the SimpleDatum as a RawImageMean in the database for the open data source.
List< RawImageParameter > QueryRawImageParameters(int nImageID)
Query all image parameters for a given image.
void Close()
Close the current data source used.
string GetSourceParameter(string strParam, int nSrcId=0)
Return the data source parameter as a string.
void ClearImageCache(bool bSave)
Clear the RawImage cache and optionally save the images.
void SetLabelMapping(LabelMapping map, int nSrcId=0)
Saves a label mapping in the database for a data source.
void UpdateLabelBoost(int? nTgtLbl, bool bTgtLblExact, int? nTgtBst, bool bTgtBstExact, int? nNewLbl, int? nNewBst, params int[] rgSrcId)
Update the label and boost for a given search target criteria.
void UpdateDatasetImageAnnotations(int nSrcId, int nImageId, AnnotationGroupCollection annotations, bool bSetLabelOnly)
Update the annotations on a given RawImage.
byte[] GetRawImageDataCriteria(byte[] rgData, int nOriginalSourceID)
Converts the raw image data criteria data which may be stored as a path to the underlying data file,...
int GetImageCount()
Returns the number of images in the database for the open data source.
bool GetRawImageParameterExist(string strName, int nSrcId=0, string strType="TEXT")
Returns whether or not a given RawImage parameter exists.
bool ReindexRawImages(Log log, CancelEvent evtCancel, int nSrcId=0, bool bCreateImageMean=false)
Reindex the RawImages of a data source.
List< DatasetDescriptor > LoadAllDatasetsWithCreators(int nGroupId)
Loads all dataset descriptors within a group that have a creator.
ParameterDescriptorCollection LoadSourceParameters(int nSrcId, ConnectInfo ci=null)
Loads the data source parameters for a given source.
Dictionary< int, int > LoadLabelCounts(int nSrcId=0)
Load the label counts from the database for a data source.
bool LoadDataCriteria
Returns whether or not the image data criteria is to be loaded when loading each image.
string FindDatasetNameFromSourceName(string strTrainSrc, string strTestSrc)
Searches for the data set name based on the training and testing source names.
void Dispose()
Releases all resources used.
void SetSourceParameter(string strParam, string strValue, int nSrcId=0)
Set the value of a data source parameter.
void DeleteLabelBoosts(int nProjectId, int nSrcId=0)
Delete all label boosts for a project.
GroupDescriptor LoadModelGroup(int nGroupId, ConnectInfo ci=null)
Load a model group descriptor from a group ID.
void SetDatasetParameters(int nDsId, Dictionary< string, string > rgP)
Set a batch of dataset parameters.
void ResetAllActiveLabels()
Reset all active labels within the open source.
SourceDescriptor LoadSource(string strSource)
Load the source descriptor from a data source name.
void UpdateLabelCounts(int nSrcId=0, int nProjectId=0)
Update the label counts for a given data source and project (optionally) by querying the database for...
void UpdateDatasetCounts(int nDsId, ConnectInfo ci=null)
Updates the dataset counts, and training/testing source counts.
List< SimpleResult > QueryAllResults(int nSrcID, bool bRequireExtraData=false, int nMax=-1)
Load all results for a given data source.
string GetLabelBoostsAsText(int nProjectId, int nSrcId=0, bool bSort=true)
Returns the Label boosts as a string.
List< Tuple< SimpleDatum, List< Result > > > GetRawImageResultBatch(int nBatchCount, byte[] rgResults)
Extracts the raw image result batch from the result binary data.
int FindRawImageGroupID(int nIdx, DateTime dtStart, DateTime dtEnd)
Searches fro the RawImageGroup ID.
void UpdateLabelName(int nLabel, string strName, int nSrcId=0)
Update the name of a label.
int? OriginalSourceID
Get/set the original source ID (if any). This field is used when copying a source and using the virut...
bool m_bLoadDataCriteria
Specifies whether or not to load the data criteria data if any exists. When false,...
int PutRawImageResults(int nSrcId, int nIdx, int nLabel, DateTime dt, List< Tuple< SimpleDatum, List< Result > > > rgrgResults, List< Tuple< DateTime, int > > rgExtra=null)
Save the time-synchronized batch of results of a Run as a RawImageResult.
void ClearParamCache(bool bSave)
Clear the param cache and save when specified.
int GetBoostCount(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Return the number of boosted images for a data source.
int GetDatasetParameter(int nDsId, string strParam, int nDefault)
Returns the value of a dataset parameter as an int.
int AddDataset(int nDsCreatorID, string strName, int nTestSrcId, int nTrainSrcId, int nDsGroupID=0, int nModelGroupID=0, ConnectInfo ci=null)
Add a new (or update an existing if exists) dataset to the database.
List< LabelBoostDescriptor > GetLabelBoosts(int nProjectId, int nSrcId=0)
Returns a list of all label boosts set on a project.
void UpdateDatasetCounts(CancelEvent evtCancel, Log log, int nDatasetCreatorID, List< string > rgstrDs, string strParamNameForDescription)
Updates the dataset counts for a set of datasets.
void Open(SourceDescriptor src, int nCacheMax=500, ConnectInfo ci=null)
Open a given data source.
string GetSourceName(int nId)
Returns the name of a data source given its ID.
DateTime GetFirstTimeStamp(int nSrcId=0, string strDesc=null)
Returns the first time-stamp in the data source.
void DisableLabel(int nLabel, bool bOriginalLabel=false)
Disable a set of labels within the open source.
bool GetDatasetParameter(int nDsId, string strParam, bool bDefault)
Returns the value of a dataset parameter as a bool.
int DisableAllNonMatchingImages(int nWidth, int nHeight)
Disable all images that do not have a matching widxht size.
DateTime GetLastTimeStamp(int nSrcId=0, string strDesc=null)
Returns the last time-stamp in the data source.
int? m_nOriginalSourceID
Specifies the original source ID (if any).
Database Database
Returns the underlying Database object.
int GetRawImageParameterCount(string strParam, int nSrcId=0, string strType="TEXT")
Returns the RawImage parameter count for a data source.
byte[] GetRawImageDataCriteria(int nImgID, int nOriginalSourceID)
Queries the Data Criteria data for an image and then converts the raw image debug data which may be s...
List< SimpleDatum > GetImagesAtID(List< int > rgImageId, int nSrcId=0, string strDescription=null)
Returns a list of SimpleDatum from the database for a data source.
SimpleDatum LoadDatum(int nImageId, int nChannels, bool bDataIsReal, int nLabel, int nSrcId=0)
Loads a new SimpleDataum from a RawImage ID.
int GetDatasetGroupID(string strName)
Returns the ID of a dataset group given its name.
List< DatasetDescriptor > LoadAllDatasetsWithCreator(int nCreatorID, bool? bRelabeled=null)
Loads all dataset descriptors with a given dataset creator.
SourceDescriptor OpenSource
Returns the currently open data source.
SourceDescriptor LoadSource(int nSrcId, ConnectInfo ci=null)
Load the source descriptor from a data source ID.
void ActivateLabels(List< int > rgLabels, bool bActive, params int[] rgSrcId)
Activate (or deactivate) the labels specified for each of the source ID's specified.
The LabelBoostDescriptor class describes a label boost.
LabelBoostDescriptor(int nLabel, double dfBoost)
The LabelBoostDescriptor constructor.
The ParameterData class is used to save and retrieve parameter data.
Definition: Database.cs:5712
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12