2using System.Collections.Generic;
9using System.Threading.Tasks;
45 ImageCache m_imageCache =
null;
46 ParamCache m_paramCache =
null;
185 log.WriteLine(
"WARNING: Closing currently open source ID of " +
m_openSource.
ID.ToString() +
" and opening new Source ID of " + nSrcId.ToString() +
".");
194 m_imageCache =
new ImageCache(nCacheMax);
195 m_paramCache =
new ParamCache(nCacheMax);
251 if (m_paramCache.Count == 0)
257 m_paramCache.Clear();
272 if (m_imageCache.Add(img, sd, rgParams))
282 if (m_imageCache ==
null || m_imageCache.Count == 0)
291 m_imageCache.Clear();
316 public int SetRawImageParameter(
int nRawImageID,
string strName,
string strValue,
double? dfVal =
null,
byte[] rgData =
null,
bool bOnlyAddNew =
false)
331 public int SetRawImageParameter(
int nSrcID,
int nRawImageID,
string strName,
string strValue,
double? dfVal =
null,
byte[] rgData =
null)
345 public int SetRawImageParameterAt(DateTime dt,
string strName,
string strValue,
double? dfVal =
null,
byte[] rgData =
null)
388 public List<RawImage>
GetRawImagesAt(
int nImageIdx,
int nImageCount,
int nSrcId = 0,
string strDescription =
null)
401 public List<RawImage>
GetRawImagesAt(List<int> rgImageIdx, ManualResetEvent evtCancel,
int nSrcId = 0,
string strDescription =
null)
403 List<RawImage> rgImg =
new List<RawImage>();
405 while (rgImageIdx.Count > 0)
407 List<int> rgIdx =
new List<int>();
409 for (
int i=0; i<rgImageIdx.Count && i < 100; i++)
411 rgIdx.Add(rgImageIdx[i]);
415 rgImg.AddRange(rgImg1);
417 for (
int i = 0; i < rgIdx.Count; i++)
419 rgImageIdx.RemoveAt(0);
422 if (evtCancel.WaitOne(0))
437 public List<RawImage>
GetRawImagesAtID(List<int> rgImageId, ManualResetEvent evtCancel,
int nSrcId = 0,
string strDescription =
null)
439 List<RawImage> rgImg =
new List<RawImage>();
441 while (rgImageId.Count > 0)
443 List<int> rgIdx =
new List<int>();
445 for (
int i = 0; i < rgImageId.Count && i < 100; i++)
447 rgIdx.Add(rgImageId[i]);
451 rgImg.AddRange(rgImg1);
453 for (
int i = 0; i < rgIdx.Count; i++)
455 rgImageId.RemoveAt(0);
458 if (evtCancel.WaitOne(0))
473 public List<RawImage>
GetRawImagesAt(List<DbItem> rgImgItems, ManualResetEvent evtCancel,
int nSrcId = 0,
string strDescription =
null)
475 List<RawImage> rgImg =
new List<RawImage>();
477 while (rgImgItems.Count > 0)
479 List<int> rgID =
new List<int>();
481 for (
int i = 0; i < rgImgItems.Count && i < 100; i++)
483 rgID.Add(rgImgItems[i].ID);
487 rgImg.AddRange(rgImg1);
489 for (
int i = 0; i < rgID.Count; i++)
491 rgImgItems.RemoveAt(0);
494 if (evtCancel.WaitOne(0))
509 public List<SimpleDatum>
GetImagesAt(List<int> rgImageIdx, ManualResetEvent evtCancel,
int nSrcId = 0,
string strDescription =
null)
511 List<RawImage> rgImg =
GetRawImagesAt(rgImageIdx, evtCancel, nSrcId, strDescription);
515 List<SimpleDatum> rgSd =
new List<SimpleDatum>();
517 foreach (RawImage img
in rgImg)
533 public List<SimpleDatum>
GetImagesAt(List<DbItem> rgImageItems, ManualResetEvent evtCancel,
int nSrcId = 0,
string strDescription =
null)
535 List<RawImage> rgImg =
GetRawImagesAt(rgImageItems, evtCancel, nSrcId, strDescription);
539 List<SimpleDatum> rgSd =
new List<SimpleDatum>();
541 foreach (RawImage img
in rgImg)
556 public List<SimpleDatum>
GetImagesAtID(List<int> rgImageId,
int nSrcId = 0,
string strDescription =
null)
562 List<SimpleDatum> rgSd =
new List<SimpleDatum>();
564 foreach (RawImage img
in rgImg)
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)
586 List<RawImage> rgImg =
m_db.
QueryRawImages(nSrcId, bActive, nBoostVal, bExactBoostVal);
588 if (!bLoadCriteria && !bLoadDebug)
591 Stopwatch sw =
new Stopwatch();
594 for (
int i = 0; i < rgImg.Count; i++)
604 if (evtCancel !=
null && evtCancel.WaitOne(0))
609 if (sw.Elapsed.TotalMilliseconds > 1000)
611 log.Progress = (double)i / (
double)rgImg.Count;
612 log.WriteLine(
"loading " + i.ToString(
"N0") +
" of " + rgImg.Count.ToString(
"N0") +
"...");
708 public List<int>
QueryRawImageIDs(
int nSrcId = 0,
int nMax =
int.MaxValue,
int nLabel = -1,
int nBoost = -1,
bool bBoostIsExact =
false,
bool bAnnotatedOnly =
false)
721 return (img ==
null) ? 0 : img.ID;
765 public int PutRawImageResults(
int nSrcId,
int nIdx,
int nLabel, DateTime dt, List<Result> rgResults,
bool bInvert, List<Tuple<DateTime, int>> rgExtra =
null)
780 public int PutRawImageResults(
int nSrcId,
int nIdx,
int nLabel, DateTime dt, List<Tuple<
SimpleDatum, List<Result>>> rgrgResults, List<Tuple<DateTime, int>> rgExtra =
null)
805 public int AddRawImageGroup(Image img,
int nIdx, DateTime dtStart, DateTime dtEnd, List<double> rgProperties)
875 public bool UpdateActiveLabel(
int nImageID,
int nNewActiveLabel,
bool bActivate =
true,
bool bSaveChanges =
true)
1010 public void ActivateAllRawImages(
bool bActive,
bool bAnnotatedOnly,
int? nTgtLabel,
bool bTargetLabelExact,
int? nTgtBoost,
bool bTargetBoostExact, params
int[] rgSrcId)
1012 m_db.
ActivateAllRawImages(bActive, bAnnotatedOnly, nTgtLabel, bTargetLabelExact, nTgtBoost, bTargetBoostExact, rgSrcId);
1105 List<LabelBoostDescriptor> rgDesc =
new List<LabelBoostDescriptor>();
1107 foreach (LabelBoost b
in rgBoosts)
1109 rgDesc.Add(
new LabelBoostDescriptor(b.ActiveLabel.GetValueOrDefault(), (
double)b.Boost.GetValueOrDefault(1)));
1163 public void AddLabelBoost(
int nProjectId,
int nLabel,
double dfBoost,
int nSrcId = 0)
1187 Dictionary<int, int> rgCounts =
new Dictionary<int, int>();
1286 public void UpdateLabelBoost(
int? nTgtLbl,
bool bTgtLblExact,
int? nTgtBst,
bool bTgtBstExact,
int? nNewLbl,
int? nNewBst, params
int[] rgSrcId)
1288 m_db.
UpdateLabelBoost(nTgtLbl, bTgtLblExact, nTgtBst, bTgtBstExact, nNewLbl, nNewBst, rgSrcId);
1339 bool bSaveImagesToFile = bSaveImagesToFileOverride.GetValueOrDefault(src.
SaveImagesToFile);
1357 public int AddSource(
string strName,
int nChannels,
int nWidth,
int nHeight,
bool bDataIsReal,
int nCopyOfSourceID = 0,
bool bSaveImagesToFile =
true,
ConnectInfo ci =
null)
1359 return m_db.
AddSource(strName, nChannels, nWidth, nHeight, bDataIsReal, nCopyOfSourceID, bSaveImagesToFile, ci);
1387 public int GetBoostCount(
int nSrcId = 0,
string strFilterVal =
null,
int? nBoostVal =
null)
1418 if (bCreateImageMean)
1420 bool bOpened =
false;
1427 List<SimpleDatum> rgSd =
new List<SimpleDatum>();
1428 foreach (RawImage img
in rgImg)
1455 public void UpdateSource(
int nChannels,
int nWidth,
int nHeight,
bool bDataIsReal,
int nSrcId = 0)
1559 public DateTime
GetLastTimeStamp(DateTime dtStart, DateTime dtEnd,
bool bEndInclusive,
int nSrcId = 0,
string strDesc =
null)
1587 public DateTime
GetLastTimeStamp(DateTime dtStart, DateTime dtEnd,
bool bEndInclusive, out
int nIndex,
int nSrcId = 0,
string strDesc =
null)
1592#pragma warning disable 1591
1594 public List<int> GetAllDataSourceIDs()
1596 return m_db.GetAllDataSourcesIDs();
1599 public bool ConvertRawImagesSaveToFile(
int nIdx,
int nCount)
1604 public bool ConvertRawImagesSaveToDatabase(
int nIdx,
int nCount)
1609 public void UpdateSaveImagesToFile(
bool bSaveToFile,
int nSrcId = 0)
1614#pragma warning restore 1591
1668 int nDsCreatorID = 0;
1687 public int AddDataset(
int nDsCreatorID,
string strName,
int nTestSrcId,
int nTrainSrcId,
int nDsGroupID = 0,
int nModelGroupID = 0,
ConnectInfo ci =
null)
1689 return m_db.
AddDataset(nDsCreatorID, strName, nTestSrcId, nTrainSrcId, nDsGroupID, nModelGroupID, ci);
1870 public List<SimpleResult>
QueryAllResults(
int nSrcID,
bool bRequireExtraData =
false,
int nMax = -1)
1873 List<SimpleResult> rgRes =
new List<SimpleResult>();
1875 foreach (RawImageResult res1
in rgRes1)
1891 #region Loading Descriptors
1900 public List<DbItem>
LoadImageIndexes(
bool bBoostedOnly,
bool bIncludeActive =
true,
bool bIncludeInactive =
false)
1913 if (rgSrcId.Length == 0)
1914 throw new Exception(
"You must specify at least one source ID.");
1916 List<ImageDescriptor> rgImgDesc =
new List<ImageDescriptor>();
1919 foreach (RawImage img
in rgImg)
1921 if (evtCancel !=
null && evtCancel.WaitOne(0))
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),
1934 img.TimeStamp.GetValueOrDefault(DateTime.MinValue)));
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());
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());
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());
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());
1986 byte[] rgDataCriteria =
null;
1987 int? nDataCriteriaFormatId =
null;
1988 byte[] rgDebugData =
null;
1989 int? nDebugDataFormatId =
null;
1998 rgDataCriteria = img.DataCriteria;
2001 int nHeight = img.Height.GetValueOrDefault();
2002 int nWidth = img.Width.GetValueOrDefault();
2003 int nChannels = img.Channels.GetValueOrDefault();
2006 if (img.Encoded.GetValueOrDefault())
2008 Tuple<double[], float[]> rgRealData =
SimpleDatum.
GetRealData(rgData, nPadW, nPadH, nHeight, nWidth, nChannels);
2009 double[] rgDataFloat = rgRealData.Item1;
2010 float[] rgDataDouble = rgRealData.Item2;
2012 if (rgDataFloat !=
null)
2014 sd =
new SimpleDatum(img.Encoded.GetValueOrDefault(),
2018 img.ActiveLabel.GetValueOrDefault(),
2019 img.TimeStamp.GetValueOrDefault(),
2021 img.ActiveBoost.GetValueOrDefault(),
2022 img.AutoLabel.GetValueOrDefault(),
2023 img.Idx.GetValueOrDefault(),
2024 img.VirtualID.GetValueOrDefault(),
2026 img.SourceID.GetValueOrDefault(),
2027 img.OriginalSourceID.GetValueOrDefault());
2031 sd =
new SimpleDatum(img.Encoded.GetValueOrDefault(),
2035 img.ActiveLabel.GetValueOrDefault(),
2036 img.TimeStamp.GetValueOrDefault(),
2038 img.ActiveBoost.GetValueOrDefault(),
2039 img.AutoLabel.GetValueOrDefault(),
2040 img.Idx.GetValueOrDefault(),
2041 img.VirtualID.GetValueOrDefault(),
2043 img.SourceID.GetValueOrDefault(),
2044 img.OriginalSourceID.GetValueOrDefault());
2050 sd =
new SimpleDatum(img.Encoded.GetValueOrDefault(),
2054 img.ActiveLabel.GetValueOrDefault(),
2055 img.TimeStamp.GetValueOrDefault(),
2057 img.ActiveBoost.GetValueOrDefault(),
2058 img.AutoLabel.GetValueOrDefault(),
2059 img.Idx.GetValueOrDefault(),
2060 img.VirtualID.GetValueOrDefault(),
2062 img.SourceID.GetValueOrDefault(),
2063 img.OriginalSourceID.GetValueOrDefault());
2068 sd.
GroupID = img.GroupID.GetValueOrDefault();
2091 int nHeight = img.
Height.GetValueOrDefault();
2092 int nWidth = img.Width.GetValueOrDefault();
2093 int nChannels = img.Channels.GetValueOrDefault();
2096 if (img.Encoded.GetValueOrDefault())
2098 Tuple<double[], float[]> rgRealData =
SimpleDatum.
GetRealData(img.Data, nPadW, nPadH, nHeight, nWidth, nChannels);
2099 double[] rgDataFloat = rgRealData.Item1;
2100 float[] rgDataDouble = rgRealData.Item2;
2102 if (rgDataFloat !=
null)
2104 sd =
new SimpleDatum(img.Encoded.GetValueOrDefault(),
2116 img.SourceID.GetValueOrDefault());
2120 sd =
new SimpleDatum(img.Encoded.GetValueOrDefault(),
2132 img.SourceID.GetValueOrDefault());
2138 sd =
new SimpleDatum(img.Encoded.GetValueOrDefault(),
2150 img.SourceID.GetValueOrDefault());
2165 throw new Exception(
"You must open a data source first!");
2171 if (img ==
null || img.SourceID != nSrcId)
2186 if (imgMean ==
null)
2202 public SimpleDatum LoadImageAt(
int nIdx,
bool? bLoadDataCriteria =
null,
bool? bLoadDebugData =
null,
int nSrcId = 0,
int nPadW = 0,
int nPadH = 0)
2208 if (!bLoadDataCriteria.HasValue)
2211 if (bLoadDataCriteria.Value && img.DataCriteria !=
null)
2214 if (!bLoadDebugData.HasValue)
2217 if (bLoadDebugData.Value && img.DebugData !=
null)
2231 int nSrcID = res.
SourceID.GetValueOrDefault();
2232 DateTime dt = res.TimeStamp.GetValueOrDefault();
2233 int nIdx = res.Idx.GetValueOrDefault();
2235 int nResCount = res.ResultCount.GetValueOrDefault();
2236 int nBatchCount = res.BatchCount.GetValueOrDefault();
2238 List<float> rgResults =
new List<float>();
2240 for (
int i = 0; i < rgRes.Count; i++)
2242 for (
int j = 0; j < rgRes[i].Item2.Count; j++)
2244 rgResults.Add((
float)rgRes[i].Item2[j].Score);
2248 float[] rgResult1 = rgResults.ToArray();
2249 List<Tuple<DateTime, int>> rgTarget1 =
new List<Tuple<DateTime, int>>();
2251 if (res.ExtraData ==
null && bRequireExtraData)
2256 return new SimpleResult(nSrcID, nIdx, dt, nBatchCount, nResCount, rgResult1, rgTarget1);
2270 if (bLoadDebugData && sd.
DebugData !=
null)
2282 public List<LabelDescriptor>
LoadLabels(
int nSrcId = 0,
bool bSort =
true,
bool bWithImagesOnly =
false,
ConnectInfo ci =
null)
2284 List<Label> rgLabels =
m_db.
GetLabels(bSort, bWithImagesOnly, nSrcId, ci);
2285 List<LabelDescriptor> rgDesc =
new List<LabelDescriptor>();
2287 foreach (Label l
in rgLabels)
2290 l.ActiveLabel.GetValueOrDefault(),
2292 l.ImageCount.GetValueOrDefault());
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),
2331 src.ImageCount.GetValueOrDefault());
2351 foreach (KeyValuePair<string, string> kv
in rgParam)
2427 if (nDatasetID != 0)
2430 if (ds ==
null && !String.IsNullOrEmpty(strDataset))
2459 List<DatasetDescriptor> rgDesc =
new List<DatasetDescriptor>();
2461 foreach (Dataset ds
in rgDs)
2478 List<DatasetDescriptor> rgDesc =
new List<DatasetDescriptor>();
2480 foreach (Dataset ds
in rgDs)
2519 foreach (KeyValuePair<string, string> kv
in rgParam)
2535 List<ResultDescriptor> rgDesc =
new List<ResultDescriptor>();
2537 foreach (RawImageResult res
in rgResults)
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()));
2550 List<ParameterData> m_rgParam =
new List<ParameterData>();
2553 public ParamCache(
int nMax)
2560 get {
return m_rgParam.Count; }
2568 public bool Add(ParameterData p)
2572 if (m_rgParam.Count == m_nMax)
2578 public List<ParameterData> Parameters
2580 get {
return m_rgParam; }
2586 List<RawImage> m_rgImages =
new List<RawImage>();
2587 List<List<ParameterData>> m_rgrgParams =
new List<List<ParameterData>>();
2590 public ImageCache(
int nMax)
2597 get {
return m_rgImages.Count; }
2603 m_rgrgParams.Clear();
2606 public bool Add(RawImage img,
SimpleDatum sd, params ParameterData[] rgParams)
2608 m_rgImages.Add(img);
2610 List<ParameterData> rgParam =
new List<db.image.ParameterData>();
2615 string strVal = d.
Tag as string;
2616 string strTag = d.
TagName as string;
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()));
2622 foreach (ParameterData param
in rgParams)
2624 param.ImageID = img.ID;
2625 param.SourceID = img.SourceID.GetValueOrDefault();
2629 m_rgrgParams.Add(rgParam);
2631 if (m_rgImages.Count == m_nMax)
2637 public List<RawImage> Images
2639 get {
return m_rgImages; }
2642 public List<List<ParameterData>> Parameters
2644 get {
return m_rgrgParams; }
2664 m_dfBoost = dfBoost;
2672 get {
return m_nLabel; }
2680 get {
return m_dfBoost; }
Defines a collection of AnnotationGroups.
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
WaitHandle[] Handles
Returns the internal wait handle of the CancelEvent.
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
The Datum class is a simple wrapper to the SimpleDatum class to ensure compatibility with the origina...
The LabelMapping class represents a single label mapping.
The Log class provides general output in text form.
The SimpleDatum class holds a data input within host memory.
string TagName
Returns a user-defined name of the tag associated with the data.
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.
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.
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.
int SourceID
Returns the source ID of the data source associated with the result.
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...
Dataset GetDataset(int nID, ConnectInfo ci=null)
Returns the Dataset entity for a dataset ID.
void ActivateRawImageByIndex(int nSrcId, int nIdx, bool bActive)
Activate/deactivate a raw image based on its index.
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.
void ActivateAllRawImages(bool bActive, bool bAnnotatedOnly, params int[] rgSrcId)
Activate all raw images associated with a set of source ID's.
int GetBoostCount(int nSrcId=0, string strFilterVal=null, int? nBoostVal=null)
Return the number of boosted images for a data source.
void SetSourceParameter(string strName, string strValue, int nSrcId=0)
Set the value of a data source parameter.
FORCE_LOAD
Defines the force load type.
string GetDatasetCreatorName(int nDatasetCreatorID, ConnectInfo ci=null)
Returns the name of a dataset creator given its ID.
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.
void UpdateSourceCounts(int nImageCount, ConnectInfo ci=null)
Updates the source counts for the open data source.
List< Tuple< SimpleDatum, List< Result > > > GetRawImageResultBatch(int nBatchCount, byte[] rgResults)
Extracts the raw image result batch from the result binary data.
void UpdateActiveLabelByIndex(int nSrcId, int nIdx, int nLabel)
Update the label value of a label.
void DisableLabel(int nSrcId, int nLabel, bool bOriginalLabel=false)
Disable a set of labels within the source specified by the ID.
virtual void Open(int nSrcId, FORCE_LOAD nForceLoad=FORCE_LOAD.NONE, ConnectInfo ci=null)
Opens a data source.
List< Dataset > GetAllDatasetsWithCreators(int nDatasetGroupID)
Returns a list of all datasets within a group with dataset creators.
void SetLabelMapping(LabelMapping map, int nSrcId=0)
Saves a label mapping in the database for a data source.
bool ConvertRawImagesSaveToFile(int nIdx, int nCount, CancelEvent evtCancel=null)
The ConvertRawImagesSaveToFile method saves the image in the database to the file system and replaces...
void ActivateLabels(List< int > rgLabels, bool bActive, params int[] rgSrcId)
Activate (or deactivate) the labels specified for each of the source ID's specified.
bool GetRawImageParameterExist(string strName, int nSrcId=0, string strType="TEXT")
Returns whether or not a given RawImage parameter exists.
bool UpdateActiveLabel(int nID, int nLabel, bool bActivate=true, bool bSaveChanges=true)
Update the label value of a label.
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).
int GetDatasetCreatorID(string strName)
Returns the ID of a dataset creator given its name.
bool ConvertRawImagesSaveToDatabase(int nIdx, int nCount, CancelEvent evtCancel=null)
The ConvertRawImagesSaveToDatabase method saves the image in the file system to the database and dele...
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.
virtual void Close()
Close the previously opened data source.
Source CurrentSource
Returns the current entity framwork Source object set during the previous call to Open().
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.
DateTime GetLastTimeStamp(int nSrcId=0, string strDesc=null)
Returns the last time-stamp in the data source.
int GetRawImageParameterCount(string strName, int nSrcId=0, string strType="TEXT")
Returns the RawImage parameter count for a data source.
List< RawImageResult > GetRawImageResults(int nSrcId=0, bool bRequireExtraData=false, int nMax=-1)
Returns the RawImageResults for a data source.
void SetDatasetParameters(int nDsId, Dictionary< string, string > rgP)
Adds a batch of new parametes.
List< DbItem > GetAllRawImageIndexes(bool bBoostedOnly, bool bIncludeActive=true, bool bIncludeInactive=false)
Returns the list of the image indexes of all images.
void UpdateLabelName(int nLabel, string strName, int nSrcId=0)
Update the name of a label.
void SaveLabelCache()
Saves the label cache to the database.
byte[] GetRawImageParameterData(int nRawImageID, string strName)
Return the byte array data of a RawImage parameter.
bool UpdateRawImageSourceID(int nImageID, int nSrcID)
Updates a given image's source ID.
string GetDatasetName(int nID, ConnectInfo ci=null)
Returns the name of a dataset given its ID.
void Refresh()
Close and re Open with the current data source.
void UpdateSaveImagesToFile(bool bSaveToFile, int nSrcId=0)
Update the SaveImagesToFile flag in a given Data Source.
RawImage GetRawImage(int nID)
Returns the RawImage with a given ID.
List< string > GetRawImageDistinctParameterDescriptions(int nSrcId=0)
Returns a list of distinct RawImage parameter descriptions for a data source.
static List< Tuple< DateTime, int > > UnpackExtraData(byte[] rg)
Unpack the extra data from a byte array.
RawImageMean GetRawImageMean(int nSrcId=0, ConnectInfo ci=null)
Return the RawImageMean for the image mean from the open data source.
string GetSourceParameter(string strName, int nSrcId=0)
Return the data source parameter as a string.
void ResetLabels(int nProjectId=0, int nSrcId=0)
Resets all labels back to their original labels for a project.
void DeleteLabelBoosts(int nProjectId, int nSrcId=0)
Delete all label boosts for a project.
int AddRawImageGroup(Image img, int nIdx, DateTime dtStart, DateTime dtEnd, List< double > rgProperties)
Adds a new RawImage group to the database.
void ResetAllActiveLabels(int nSrcId)
Reset the all active labels to their original label within a source.
int GetSourceID(string strName, ConnectInfo ci=null)
Returns the ID of a data source given its name.
void UpdateLabelMapping(int nNewLabel, List< int > rgOriginalLabels, int nSrcId=0)
Update a label mapping in the database for a data source.
Dictionary< string, string > GetDatasetParameters(int nDsId, ConnectInfo ci=null)
Returns all dataset parameters for a given dataset.
void SetDatasetParameter(int nDsId, string strName, string strValue)
Adds a new parameter or Sets the value of an existing dataset parameter.
void FixupRawImageCopy(int nImageID, int nSecondarySrcId)
The FixupRawImageCopy method is used to fixup the OriginalSourceId by setting it to a secondary sourc...
int DisableAllNonMatchingImages(int nSrcId, int nWidth, int nHeight)
Disable all images that do not have a matching widxht size.
Dictionary< string, string > GetSourceParameters(int nSrcId=0, ConnectInfo ci=null)
Returns a dictionary of the data source parameters.
int FindDatasetFromSourceId(int nSourceId)
Searches for the dataset containing the sourceId.
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.
void DeleteSourceData()
Deletes the data source data for the open data source.
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.
int FindRawImageGroupID(int nIdx, DateTime dtStart, DateTime dtEnd)
Searches fro the RawImageGroup 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 GetDatasetID(string strName, ConnectInfo ci=null)
Returns a datasets ID given its name.
void AddLabelBoost(int nProjectId, int nLabel, double dfBoost, int nSrcId=0)
Add a label boost to the database for a given project.
void DisableAllLabels(int nSrcId)
Disable all labels within the source specified by the ID.
ModelGroup GetModelGroup(int nGroupID, ConnectInfo ci=null)
Returns the ModelGroup entity given the ID of a model group.
void UpdateAllActiveLabels(int nSrcId, int nLabel, int? nOriginalLabel)
Update the all items to a label value for the given nSrcId.
byte[] GetRawImageDataCriteria(RawImage img, out int? nDataCriteriaFmtId)
Returns the raw data criteria data of the RawImage.
int GetDatasetGroupID(string strName)
Returns the ID of a dataset group given its name.
void UpdateDatasetImageAnnotations(int nSrcId, int nImageId, AnnotationGroupCollection annotations, bool bSetLabelOnly)
Update the annotations of a given raw image.
Source GetSource(string strName, ConnectInfo ci=null)
Returns the Source entity given a data source name.
List< RawImage > GetRawImagesAtID(List< int > rgImageID, int nSrcId=0, string strDescription=null)
Returns a list of RawImages from the database for a data source.
void UpdateActiveLabelDirect(int nID, int nLabel)
Directly update the active label and activate the image with the specified ID.
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.
void UpdateDatasetDescription(int nDsId, string strDesc)
Update the description of a given dataset.
void PutRawImages(List< RawImage > rgImg, List< List< ParameterData > > rgrgParam=null, ConnectInfo ci=null)
Saves a List of RawImages to the database.
void UpdateSource(int nChannels, int nWidth, int nHeight, bool bDataIsReal, int nSrcId=0)
Updates a data source.
RawImage GetRawImageAt(int nIdx, int nSrcId=0)
Returns the RawImage at a given image index.
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.
string GetLabelName(int nLabel, int nSrcId=0)
Get the Label name of a label within a data source.
void UpdateDatasetCounts(int nDsId, ConnectInfo ci=null)
Update the dataset counts.
int GetRawImageID(DateTime dt, int nSrcId=0)
Returns the RawImage ID for the image with the given time-stamp.
void ResetAllDatasetRelabelWithCreator(int nDsCreatorID)
Reset all dataset relabel flags with a given creator.
int GetImageCount()
Returns the number of raw images in the database for the open data source.
int AddLabel(int nLabel, string strName="", int nSrcId=0, ConnectInfo ci=null)
Add a label to the database for a data source.
int LastIndex
Returns the last image index added to the database.
void DeleteSources(params string[] rgstrSrc)
Delete the list of data sources, listed by name, from the database.
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 ...
bool ActivateRawImage(int nImageID, bool bActivate, bool bSave=true)
Activate/Deactivate a given image.
void LoadLabelCounts(Dictionary< int, int > rgCounts, int nSrcId=0)
Load the label counts from the database for a data source.
byte[] GetRawImageDebugData(RawImage img, out int? nDebugDataFormatId)
Returns the raw debug data data of the RawImage.
string GetLabelBoostsAsText(int nProjectId, int nSrcId=0, bool bSort=true)
Returns the Label boosts as a string.
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.
List< LabelBoost > GetLabelBoosts(int nProjectId, bool bSort=true, int nSrcId=0)
Returns a list of all label boosts set on a project.
string GetSourceName(int nID, ConnectInfo ci=null)
Returns the name of a data source given its ID.
int PutRawImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0, ConnectInfo ci=null)
Save the SimpleDatum as a RawImageMean in the database.
string GetLabelCountsAsText(int nSrcId=0, ConnectInfo ci=null)
Returns the label counts for a given data source.
List< RawImage > ReindexRawImages(Log log, CancelEvent evtCancel, int nSrcId=0)
Reindex the RawImages of a data source.
void SaveChanges()
Saves any changes on the open satabase.
void DeleteLabels(int nSrcId=0)
Delete the labels of a data source from the database.
void UpdateLabelCounts(Dictionary< int, int > rgCounts, DNNEntities entities)
Updates the label counts in the database for the open data source.
int PutRawImage(int nIdx, SimpleDatum d, string strDescription=null)
Save a SimpleDatum as a RawImage in the database.
bool CopyImageMean(int nSrcIdSrc, int nSrcIdDst, ConnectInfo ci=null)
Copy the raw image mean from one source to another.
List< RawImage > QueryRawImages(params int[] rgSrcId)
Returns the list of raw images that have a source ID from a selected list.
void PutRawImageParameters(List< ParameterData > rgParam, ConnectInfo ci=null)
Save a list of raw image parameters.
void UpdateDatasetRelabel(int nDsID, bool bRelabel)
Update the dataset relabel flag for a dataset.
DateTime GetFirstTimeStamp(int nSrcId=0, string strDesc=null)
Returns the first time-stamp in the data source.
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.
void UpdateActiveLabelByID(int nID, int nLabel)
Update the label value of a label.
string FindDatasetNameFromSourceName(string strTrainSrc, string strTestSrc)
Searches for the data set name based on the training and testing source names.
DatasetGroup GetDatasetGroup(int nGroupID, ConnectInfo ci=null)
Returns the DatasetGroup entity given a group ID.
List< Dataset > GetAllDatasetsWithCreator(int nDsCreatorID, bool? bRelabeled=null)
Returns a list of all datasets within a group with dataset creators.
string GetDatasetParameter(int nDsId, string strName)
Returns the value of a dataset parameter as a string.
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.
bool WaitForFileWriter(int nWait=int.MaxValue)
Wait for the file writer to complete writing all files.
void DeleteRawImageResults(int nSrcId=0)
Delete all RawImageResults for a data source.
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.
int Label
Returns the label.
double Boost
Returns the boost.
LabelBoostDescriptor(int nLabel, double dfBoost)
The LabelBoostDescriptor constructor.
The ParameterData class is used to save and retrieve parameter data.
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.
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...