MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DB.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.db.image;
6using MyCaffe.basecode;
8
9namespace MyCaffe.data
10{
14 public class DB<T>
15 {
16 IXImageDatabaseBase m_db = null;
17 int m_nSrcID = 0;
18 string m_strSrc = null;
19
24 public DB(IXImageDatabaseBase imgDb)
25 {
26 m_db = imgDb;
27 }
28
33 public void Open(string strSrc)
34 {
35 m_strSrc = strSrc;
36 m_nSrcID = m_db.GetSourceID(strSrc);
37 }
38
42 public void Close()
43 {
44 m_nSrcID = 0;
45 }
46
53 public Cursor<T> NewCursor(DataTransformer<T> transformer, Log log = null)
54 {
55 return new Cursor<T>(m_db, transformer, m_strSrc, log);
56 }
57 }
58
62 public class Cursor<T>
63 {
64 Log m_log = null;
65 string m_strSrc;
67 DataTransformer<T> m_transformer;
68 int m_nSrcID = 0;
69 int m_nCount = 0;
70 int m_nIdx = 0;
71
79 public Cursor(IXImageDatabaseBase db, DataTransformer<T> transformer, string strSrc, Log log = null)
80 {
81 m_log = log;
82 m_db = db;
83 m_transformer = transformer;
84 SourceDescriptor src = m_db.GetSourceByName(strSrc);
85 m_strSrc = src.Name;
86 m_nSrcID = src.ID;
87 m_nCount = src.ImageCount;
88 }
89
93 public void Reset()
94 {
95 m_nIdx = 0;
96 }
97
101 public void Next()
102 {
103 m_nIdx++;
104 }
105
109 public int Count
110 {
111 get { return m_nCount; }
112 }
113
118 public bool IsValid
119 {
120 get
121 {
122 if (m_nIdx >= m_nCount)
123 return false;
124
125 return true;
126 }
127 }
128
132 public void SeekToFirst()
133 {
134 m_nIdx = 0;
135 }
136
144 public SimpleDatum GetValue(int? nLabel = null, bool bLoadDataCriteria = false, DB_ITEM_SELECTION_METHOD? imgSel = null)
145 {
146 SimpleDatum sd = m_db.QueryItem(m_nSrcID, m_nIdx, null, imgSel, nLabel, bLoadDataCriteria, false);
147
148 if (m_log != null)
149 m_log.WriteLine(m_strSrc + ": Idx = " + sd.Index.ToString() + " Label = " + sd.Label.ToString());
150
151 m_transformer.TransformLabel(sd);
152
153 return sd;
154 }
155 }
156}
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
int Index
Returns the index of the SimpleDatum.
int Label
Return the known label of the data.
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The SourceDescriptor class contains all information describing a data source.
int ImageCount
Returns the number of images within this data source.
The Cursor is used to traverse through a given data source within the database.
Definition: DB.cs:63
void Reset()
Resets the current index bact to the start.
Definition: DB.cs:93
void SeekToFirst()
Move the cursor to the beginning of the data source.
Definition: DB.cs:132
bool IsValid
Queryies to see if we are still within the bounds of the data source, if so true is returned,...
Definition: DB.cs:119
SimpleDatum GetValue(int? nLabel=null, bool bLoadDataCriteria=false, DB_ITEM_SELECTION_METHOD? imgSel=null)
Retrieve the Datum at the current cursor location within the data source.
Definition: DB.cs:144
int Count
Returns the number of items traversed.
Definition: DB.cs:110
void Next()
Traverses to the next item within the data source.
Definition: DB.cs:101
Cursor(IXImageDatabaseBase db, DataTransformer< T > transformer, string strSrc, Log log=null)
The Cursor constructor.
Definition: DB.cs:79
A generic database class used to connect to the underlying database and create a Cursor that traverse...
Definition: DB.cs:15
Cursor< T > NewCursor(DataTransformer< T > transformer, Log log=null)
Creates and returns a new Cursor used to traverse through a data source within the database.
Definition: DB.cs:53
DB(IXImageDatabaseBase imgDb)
The DB Constructor.
Definition: DB.cs:24
void Close()
Closes the last Open session.
Definition: DB.cs:42
void Open(string strSrc)
Opens the underlying database with a given data source.
Definition: DB.cs:33
Applies common transformations to the input data, such as scaling, mirroring, subtracting the image m...
int TransformLabel(SimpleDatum sd)
When active (label_mapping.Active = true), transforms the label if mapped using the label and boost....
SimpleDatum QueryItem(int nSrcId, int nIdx, DB_LABEL_SELECTION_METHOD? labelSelectionOverride=null, DB_ITEM_SELECTION_METHOD? imageSelectionOverride=null, int? nLabel=null, bool bLoadDataCriteria=false, bool bLoadDebugData=false)
Query an image in a given data source.
SourceDescriptor GetSourceByName(string strSrc)
Returns the SourceDescriptor for a given data source name.
The IXImageDatabaseBase interface defines the general interface to the in-memory image database.
Definition: Interfaces.cs:878
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
DB_ITEM_SELECTION_METHOD
Defines the item (e.g., image or temporal item) selection method.
Definition: Interfaces.cs:278
The MyCaffe.data namespace contains dataset creators used to create common testing datasets such as M...
Definition: BinaryFile.cs:16
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