2using System.Collections.Generic;
8using System.Threading.Tasks;
25 List<SimpleDatum> m_rgImg =
new List<SimpleDatum>();
38 public event EventHandler<ProgressArgs>
OnError;
54 m_evtCancel = evtCancel;
58 private string dataset_name
60 get {
return "CIFAR-10"; }
75 reportProgress(nIdx, 0,
"Loading database " + dataset_name +
"...");
79 string strTrainSrc = dataset_name +
".training";
84 if (!loadFile(m_param.
DataBatchFile1, strTrainSrc, nTotal, ref nIdx, m_log))
87 if (!loadFile(m_param.
DataBatchFile2, strTrainSrc, nTotal, ref nIdx, m_log))
90 if (!loadFile(m_param.
DataBatchFile3, strTrainSrc, nTotal, ref nIdx, m_log))
93 if (!loadFile(m_param.
DataBatchFile4, strTrainSrc, nTotal, ref nIdx, m_log))
96 if (!loadFile(m_param.
DataBatchFile5, strTrainSrc, nTotal, ref nIdx, m_log))
102 m_rgImg =
new List<SimpleDatum>();
106 string strTestSrc = dataset_name +
".testing";
111 if (!loadFile(m_param.
TestBatchFile, strTestSrc, nTotal, ref nIdx, m_log))
123 catch (Exception excpt)
134 private void Log_OnWriteLine(
object sender,
LogArg e)
139 private bool loadFile(
string strImagesFile,
string strSourceName,
int nTotal, ref
int nIdx,
Log log)
141 Stopwatch sw =
new Stopwatch();
144 reportProgress(nIdx, nTotal,
" Source: " + strSourceName);
145 reportProgress(nIdx, nTotal,
" loading " + strImagesFile +
"...");
147 FileStream fs =
null;
151 fs =
new FileStream(strImagesFile, FileMode.Open, FileAccess.Read);
152 using (BinaryReader br =
new BinaryReader(fs))
156 int nSrcId = m_factory.
AddSource(strSourceName, 3, 32, 32,
false, 0,
true);
164 for (
int i = 0; i < 10000; i++)
166 int nLabel = (int)br.ReadByte();
167 byte[] rgImgBytes = br.ReadBytes(3072);
168 Bitmap img = createImage(rgImgBytes);
177 if (sw.ElapsedMilliseconds > 1000)
179 reportProgress(nStart + i, nTotal,
"loading " + strImagesFile +
" " + i.ToString(
"N0") +
" of 10,000...");
202 private Bitmap createImage(
byte[] rgImg)
210 Bitmap bmp =
new Bitmap(32, 32);
212 for (
int i = 0; i < 1024; i++)
214 byte bR = rgImg[nRoffset + i];
215 byte bG = rgImg[nGoffset + i];
216 byte bB = rgImg[nBoffset + i];
217 Color clr = Color.FromArgb(bR, bG, bB);
219 bmp.SetPixel(nX, nY, clr);
233 private void reportProgress(
int nIdx,
int nTotal,
string strMsg)
236 OnProgress(
this,
new ProgressArgs(
new ProgressInfo(nIdx, nTotal, strMsg)));
239 private void reportError(
int nIdx,
int nTotal, Exception err)
242 OnError(
this,
new ProgressArgs(
new ProgressInfo(nIdx, nTotal,
"ERROR", err)));
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
void Reset()
Resets the event clearing any signaled state.
bool WaitOne(int nMs=int.MaxValue)
Waits for the signal state to occur.
The Datum class is a simple wrapper to the SimpleDatum class to ensure compatibility with the origina...
The ImageData class is a helper class used to convert between Datum, other raw data,...
static Datum GetImageDataD(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap=true, int[] rgFocusMap=null)
The GetImageDataD function converts a Bitmap into a Datum using the double type for real data.
The LogArg is passed as an argument to the Log::OnWriteLine event.
string Message
Returns the message logged.
The Log class provides general output in text form.
double Progress
Returns the progress value.
The SimpleDatum class holds a data input within host memory.
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.
int ID
Get/set the database ID of the item.
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
The SourceDescriptor class contains all information describing a data source.
The CiFar10DataLoader is used to create the CIFAR-10 dataset and load it into the database managed by...
EventHandler< ProgressArgs > OnError
The OnError event fires when an error occurs.
bool LoadDatabase(int nCreatorID=0)
Create the dataset and load it into the database.
CiFar10DataLoader(CiFar10DataParameters param, Log log, CancelEvent evtCancel)
The constructor.
EventHandler OnCompleted
The OnComplete event fires once the dataset creation has completed.
EventHandler< ProgressArgs > OnProgress
The OnProgress event fires during the creation process to show the progress.
Contains the dataset parameters used to create the CIFAR-10 dataset.
string DataBatchFile2
Specifies the second training dataset file 'data_batch_2.bin'
string TestBatchFile
Specifies the testing dataset file 'test_batch.bin'
string DataBatchFile3
Specifies the third training dataset file 'data_batch_3.bin'
string DataBatchFile1
Specifies the first training dataset file 'data_batch_1.bin'
string DataBatchFile4
Specifies the fourth training dataset file 'data_batch_4.bin'
string DataBatchFile5
Specifies the fifth training dataset file 'data_batch_5.bin'
The Database class manages the actual connection to the physical database using Entity Framworks from...
FORCE_LOAD
Defines the force load type.
The DatasetFactory manages the connection to the Database object.
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 GetSourceID(string strName)
Returns the ID of a data source given its name.
bool SaveImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0)
Save the SimpleDatum as a RawImageMean in the database.
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 UpdateSourceCounts()
Saves the label cache, updates the label counts from the database and then updates the source counts ...
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.
void ClearImageCache(bool bSave)
Clear the RawImage cache and optionally save the images.
SourceDescriptor LoadSource(string strSource)
Load the source descriptor from a data source name.
void UpdateDatasetCounts(int nDsId, ConnectInfo ci=null)
Updates the dataset counts, and training/testing source counts.
void Open(SourceDescriptor src, int nCacheMax=500, ConnectInfo ci=null)
Open a given data source.
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.data namespace contains dataset creators used to create common testing datasets such as M...
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-...