MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ModelGym.cs
1using MyCaffe.basecode;
3using MyCaffe.param;
4using MyCaffe;
5using MyCaffe.db.image;
6using System;
7using System.Collections.Generic;
8using System.Diagnostics;
9using System.Drawing;
10using System.Drawing.Drawing2D;
11using System.Drawing.Imaging;
12using System.IO;
13using System.Linq;
14using System.Runtime.InteropServices;
15using System.Text;
16using System.Threading;
17using System.Threading.Tasks;
18using MyCaffe.common;
19using System.Reflection;
20using System.Collections;
21
22namespace MyCaffe.gym
23{
28 public class ModelGym : IXMyCaffeGymData, IDisposable
29 {
30 string m_strName = "Model";
31 string m_strProject = null;
32 string m_strModelDesc;
33 string m_strDataset;
34 int m_nGpuID = 0;
35 byte[] m_rgWeights;
36 Log m_log;
37 Dictionary<string, int> m_rgActions = new Dictionary<string, int>();
38 DATA_TYPE m_dt = DATA_TYPE.VALUES;
39 Phase m_phase = Phase.NONE;
40 MyCaffeControl<float> m_mycaffe = null;
41 Blob<float> m_blobWork = null;
42 IXImageDatabaseBase m_imgdb = null;
43 CancelEvent m_evtCancel = new CancelEvent();
44 int m_nCurrentIdx = 0;
45 DatasetDescriptor m_ds = null;
46 int m_nBatchSize = 16;
47 bool m_bRecreateData = true;
48 ScoreCollection m_scores = new ScoreCollection();
49 int m_nWidth = 0;
50 int m_nDim = 0;
51
52
57 public ModelGym(ModelGym gym = null)
58 {
59 if (gym != null)
60 {
61 m_strName = gym.m_strName;
62 m_strModelDesc = gym.m_strModelDesc;
63 m_strDataset = gym.m_strDataset;
64 m_nGpuID = gym.m_nGpuID;
65 m_rgWeights = gym.m_rgWeights;
66 m_log = gym.m_log;
67
68 m_mycaffe = gym.m_mycaffe;
69 gym.m_mycaffe = null;
70
71 m_imgdb = gym.m_imgdb;
72 gym.m_imgdb = null;
73
74 m_evtCancel = gym.m_evtCancel;
75 gym.m_evtCancel = null;
76 }
77 }
78
82 public void Dispose()
83 {
84 Close();
85 }
86
103 public void Initialize(Log log, PropertySet properties)
104 {
105 m_nGpuID = properties.GetPropertyAsInt("GpuID");
106 m_strModelDesc = properties.GetProperty("ModelDescription");
107 m_strDataset = properties.GetProperty("Dataset");
108 m_rgWeights = properties.GetPropertyBlob("Weights");
109 m_nBatchSize = properties.GetPropertyAsInt("BatchSize", 16);
110 m_bRecreateData = properties.GetPropertyAsBool("RecreateData", false);
111 m_strProject = properties.GetProperty("ProjectName");
112 if (string.IsNullOrEmpty(m_strProject))
113 m_strProject = "default";
114
115 string strCudaPath = properties.GetProperty("CudaPath");
116
118 s.GpuIds = m_nGpuID.ToString();
119 s.DbLoadMethod = DB_LOAD_METHOD.LOAD_ON_DEMAND_BACKGROUND;
120
121 m_imgdb = new MyCaffeImageDatabase2(log);
122 m_imgdb.InitializeWithDsName1(s, m_strDataset);
123 m_ds = m_imgdb.GetDatasetByName(m_strDataset);
124
126 BlobShape shape = new BlobShape(1, sd.Channels, sd.Height, sd.Width);
127
128 if (m_evtCancel == null)
129 m_evtCancel = new CancelEvent();
130
131 m_mycaffe = new MyCaffeControl<float>(s, log, m_evtCancel, null, null, null, null, strCudaPath);
132 m_mycaffe.LoadToRun(m_strModelDesc, m_rgWeights, shape);
133
134 m_log = log;
135 }
136
142 public IXMyCaffeGym Clone(PropertySet properties = null)
143 {
144 return new ModelGym(this);
145 }
146
151 {
152 get { return false; }
153 }
154
159 {
160 get { return m_dt; }
161 }
162
167 {
168 get { return new DATA_TYPE[] { DATA_TYPE.VALUES }; }
169 }
170
174 public string Name
175 {
176 get { return m_strName; }
177 }
178
182 public int UiDelay
183 {
184 get { return 0; }
185 }
186
190 public double TestingPercent
191 {
192 get { return 0; }
193 }
194
199 public Dictionary<string, int> GetActionSpace()
200 {
201 return m_rgActions;
202 }
203
207 public void Close()
208 {
209 if (m_blobWork != null)
210 {
211 m_blobWork.Dispose();
212 m_blobWork = null;
213 }
214
215 if (m_mycaffe != null)
216 {
217 m_mycaffe.Dispose();
218 m_mycaffe = null;
219 }
220
221 if (m_imgdb != null)
222 {
223 ((MyCaffeImageDatabase2)m_imgdb).Dispose();
224 m_imgdb = null;
225 }
226 }
227
236 public Tuple<Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction)
237 {
238 List<double> rgData = new List<double>();
239 return Render(bShowUi, nWidth, nHeight, rgData.ToArray(), bGetAction);
240 }
241
251 public Tuple<Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction)
252 {
253 return null;
254 }
255
262 public Tuple<State, double, bool> Reset(bool bGetLabel, PropertySet props = null)
263 {
264 m_nCurrentIdx = 0;
265 return Step(-1, bGetLabel);
266 }
267
275 public Tuple<State, double, bool> Step(int nAction, bool bGetLabel = false, PropertySet extraProp = null)
276 {
277 DataState data = new DataState();
278 ScoreCollection scores = null;
279
280 if (ActivePhase == Phase.RUN)
281 {
282 if (extraProp == null)
283 throw new Exception("The extra properties are needed when querying data during the RUN phase.");
284
285 int nDataCount = extraProp.GetPropertyAsInt("DataCountRequested");
286 string strStartTime = extraProp.GetProperty("SeedTime");
287
288 int nStartIdx = m_scores.Count - nDataCount;
289 DateTime dt;
290 if (DateTime.TryParse(strStartTime, out dt))
291 nStartIdx = m_scores.FindIndexAt(dt, nDataCount);
292
293 scores = m_scores.CopyFrom(nStartIdx, nDataCount);
294 }
295 else
296 {
297 int nCount = 0;
298
299 m_scores = load(out m_nDim, out m_nWidth);
300
301 if (m_bRecreateData || m_scores.Count != m_ds.TrainingSource.ImageCount)
302 {
303 Stopwatch sw = new Stopwatch();
304 sw.Start();
305
306 m_scores = new ScoreCollection();
307
308 while (m_nCurrentIdx < m_ds.TrainingSource.ImageCount)
309 {
310 // Query images sequentially by index in batches
311 List<SimpleDatum> rgSd = new List<SimpleDatum>();
312
313 for (int i = 0; i < m_nBatchSize; i++)
314 {
315 SimpleDatum sd = m_imgdb.QueryItem(m_ds.TrainingSource.ID, m_nCurrentIdx + i, DB_LABEL_SELECTION_METHOD.NONE, DB_ITEM_SELECTION_METHOD.NONE);
316 rgSd.Add(sd);
317 nCount++;
318
319 if (nCount == m_ds.TrainingSource.ImageCount)
320 break;
321 }
322
323 List<ResultCollection> rgRes = m_mycaffe.Run(rgSd, ref m_blobWork);
324
325 if (m_nWidth == 0)
326 {
327 m_nWidth = rgRes[0].ResultsOriginal.Count;
328 m_nDim = rgRes[0].ResultsOriginal.Count * 2;
329 }
330
331 // Fill SimpleDatum with the ordered label,score pairs starting with the detected label.
332 for (int i = 0; i < rgRes.Count; i++)
333 {
334 m_scores.Add(new Score(rgSd[i].TimeStamp, rgSd[i].Index, rgRes[i]));
335 m_nCurrentIdx++;
336 }
337
338 if (sw.Elapsed.TotalMilliseconds > 1000)
339 {
340 m_log.Progress = (double)m_nCurrentIdx / (double)m_ds.TrainingSource.ImageCount;
341 m_log.WriteLine("Running model on image " + m_nCurrentIdx.ToString() + " of " + m_ds.TrainingSource.ImageCount.ToString() + " of '" + m_strDataset + "' dataset.");
342
343 if (m_evtCancel.WaitOne(0))
344 return null;
345 }
346 }
347
348 save(m_nDim, m_nWidth, m_scores);
349 }
350 else
351 {
352 m_nCurrentIdx = m_scores.Count;
353 }
354
355 scores = m_scores;
356 }
357
358 float[] rgfRes = scores.Data;
359 SimpleDatum sdRes = new SimpleDatum(scores.Count, m_nWidth, 2, rgfRes, 0, rgfRes.Length);
360 data.SetData(sdRes);
361 m_nCurrentIdx = 0;
362
363 return new Tuple<State, double, bool>(data, 0, false);
364 }
365
366 private string save_file
367 {
368 get
369 {
370 string strDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
371 strDir += "\\MyCaffe\\test_data\\gym\\ModelGym\\";
372
373 if (!Directory.Exists(strDir))
374 Directory.CreateDirectory(strDir);
375
376 return strDir + m_strProject + ".bin";
377 }
378 }
379
380 private void save(int nDim, int nWid, ScoreCollection col)
381 {
382 string strFile = save_file;
383
384 using (FileStream fs = File.OpenWrite(strFile))
385 using (BinaryWriter bw = new BinaryWriter(fs))
386 {
387 bw.Write(nDim);
388 bw.Write(nWid);
389
390 col.Save(bw);
391 }
392 }
393
394 private ScoreCollection load(out int nDim, out int nWid)
395 {
396 string strFile = save_file;
397
398 nDim = 0;
399 nWid = 0;
400
401 if (!File.Exists(strFile))
402 return new ScoreCollection();
403
404 m_log.WriteLine("Loading pre-run data from '" + strFile + "'.");
405
406 using (FileStream fs = File.OpenRead(strFile))
407 using (BinaryReader br = new BinaryReader(fs))
408 {
409 nDim = br.ReadInt32();
410 nWid = br.ReadInt32();
411
412 return ScoreCollection.Load(br);
413 }
414 }
415
423 {
424 if (dt == DATA_TYPE.DEFAULT)
425 dt = DATA_TYPE.VALUES;
426
427 if (dt != DATA_TYPE.VALUES)
428 {
429 if (log == null)
430 log = m_log;
431
432 if (log != null)
433 log.WriteLine("WARNING: This gym only supports the VALUE type, the datatype will be changed to VALUE.");
434 else
435 throw new Exception("This gym only supports the VALUE type.");
436
437 dt = DATA_TYPE.VALUES;
438 }
439
440 int nC = 1;
441 int nH = 1;
442 int nW = 0;
443
444 SourceDescriptor srcTrain = new SourceDescriptor((int)GYM_DS_ID.MODEL, Name + ".training", nW, nH, nC, false, false);
445 SourceDescriptor srcTest = new SourceDescriptor((int)GYM_SRC_TEST_ID.MODEL, Name + ".testing", nW, nH, nC, false, false);
446 DatasetDescriptor ds = new DatasetDescriptor((int)GYM_SRC_TRAIN_ID.MODEL, Name, null, null, srcTrain, srcTest, "ModelGym", "Model Gym", null, GYM_TYPE.DATA);
447
448 m_dt = dt;
449
450 return ds;
451 }
452
462 public byte[] ConvertOutput(Stage stage, int nN, float[] rg, out string type)
463 {
464 type = "String";
465
466 Dictionary<int, LabelDescriptor> rgLabels = new Dictionary<int, LabelDescriptor>();
467 foreach (LabelDescriptor lbl in m_ds.TrainingSource.Labels)
468 {
469 if (!rgLabels.ContainsKey(lbl.ActiveLabel))
470 rgLabels.Add(lbl.ActiveLabel, lbl);
471 }
472
473 string str = "";
474 for (int i = 0; i < rg.Length; i++)
475 {
476 int nLabel = (int)rg[i];
477
478 if (rgLabels.ContainsKey(nLabel))
479 str += rgLabels[nLabel].Name;
480 else
481 str += "n/a";
482
483 str += ",";
484 }
485
486 str = str.TrimEnd(',');
487
488 using (MemoryStream ms = new MemoryStream())
489 {
490 foreach (char ch in str)
491 {
492 ms.WriteByte((byte)ch);
493 }
494
495 ms.WriteByte(0);
496
497 return ms.ToArray();
498 }
499 }
500
505 {
506 get { return m_phase; }
507 set { m_phase = value; }
508 }
509 }
510
511 class ScoreCollection : IEnumerable<Score>
512 {
513 List<Score> m_rgItems = new List<Score>();
514
515 public ScoreCollection()
516 {
517 }
518
519 public float[] Scores
520 {
521 get { return m_rgItems.Select(p => p.ScoreValue).ToArray(); }
522 }
523
524 public float[] Labels
525 {
526 get { return m_rgItems.Select(p => (float)p.Label).ToArray(); }
527 }
528
529 public float[] Data
530 {
531 get
532 {
533 float[] rgf = new float[m_rgItems.Count * m_rgItems[0].Results.Count * 2];
534
535 for (int i = 0; i < m_rgItems.Count; i++)
536 {
537 for (int j = 0; j < m_rgItems[i].Results.Count; j++) // results ordered by score (highest first)
538 {
539 int nCount = m_rgItems[i].Results.Count;
540 int nIdx = i * nCount * 2;
541 rgf[nIdx + j] = m_rgItems[i].Results[j].Item1; // label
542 rgf[nIdx + nCount + j] = m_rgItems[i].Results[j].Item2; // score
543 }
544 }
545
546 return rgf;
547 }
548 }
549
550 public int Count
551 {
552 get { return m_rgItems.Count; }
553 }
554
555 public Score this[int nIdx]
556 {
557 get { return m_rgItems[nIdx]; }
558 set { m_rgItems[nIdx] = value; }
559 }
560
561 public void Add(Score r)
562 {
563 m_rgItems.Add(r);
564 }
565
566 public void Clear()
567 {
568 m_rgItems.Clear();
569 }
570
571 public int FindIndexAt(DateTime dt, int nCount)
572 {
573 int nIdx = m_rgItems.Count - nCount;
574
575 for (int i = m_rgItems.Count - 1; i >= 0; i--)
576 {
577 if (m_rgItems[i].TimeStamp >= dt)
578 {
579 if (i < nIdx)
580 return i;
581 else
582 return nIdx;
583 }
584 }
585
586 return nIdx;
587 }
588
589 public ScoreCollection CopyFrom(int nStartIdx, int nCount)
590 {
591 ScoreCollection col = new ScoreCollection();
592
593 for (int i = 0; i < nCount; i++)
594 {
595 if (nStartIdx + i < m_rgItems.Count)
596 col.Add(m_rgItems[nStartIdx + i]);
597 }
598
599 return col;
600 }
601
602 public IEnumerator<Score> GetEnumerator()
603 {
604 return m_rgItems.GetEnumerator();
605 }
606
607 IEnumerator IEnumerable.GetEnumerator()
608 {
609 return m_rgItems.GetEnumerator();
610 }
611
612 public static ScoreCollection Load(BinaryReader br)
613 {
614 ScoreCollection col = new ScoreCollection();
615 int nCount = br.ReadInt32();
616
617 for (int i = 0; i < nCount; i++)
618 {
619 col.Add(Score.Load(br));
620 }
621
622 return col;
623 }
624
625 public void Save(BinaryWriter bw)
626 {
627 bw.Write(m_rgItems.Count);
628
629 for (int i = 0; i < m_rgItems.Count; i++)
630 {
631 m_rgItems[i].Save(bw);
632 }
633 }
634 }
635
636 class Score
637 {
638 int m_nIdx;
639 DateTime m_dt;
640 int m_nLabel;
641 float m_fScore;
642 List<Tuple<int, float>> m_rgResults = new List<Tuple<int, float>>();
643
644 public Score(DateTime dt, int nIdx, ResultCollection res)
645 {
646 m_nIdx = nIdx;
647 m_dt = dt;
648 m_nLabel = res.DetectedLabel;
649 m_fScore = (float)res.DetectedLabelOutput;
650
651 foreach (Result res1 in res.ResultsSorted)
652 {
653 m_rgResults.Add(new Tuple<int, float>(res1.Label, (float)res1.Score));
654 }
655 }
656
657 public Score(DateTime dt, int nIdx, int nLabel, float fScore, List<Tuple<int, float>> rgRes)
658 {
659 m_nIdx = nIdx;
660 m_dt = dt;
661 m_nLabel = nLabel;
662 m_fScore = fScore;
663 m_rgResults = rgRes;
664 }
665
666 public List<Tuple<int, float>> Results
667 {
668 get { return m_rgResults; }
669 }
670
671 public int Index
672 {
673 get { return m_nIdx; }
674 }
675
676 public int Label
677 {
678 get { return m_nLabel; }
679 }
680
681 public DateTime TimeStamp
682 {
683 get { return m_dt; }
684 }
685
686 public float ScoreValue
687 {
688 get { return m_fScore; }
689 }
690
691 public static Score Load(BinaryReader br)
692 {
693 int nIdx = br.ReadInt32();
694 long lTime = br.ReadInt64();
695 int nLabel = br.ReadInt32();
696 float fScore = br.ReadSingle();
697
698 List<Tuple<int, float>> rgResults = new List<Tuple<int, float>>();
699 int nCount = br.ReadInt32();
700
701 for (int i = 0; i < nCount; i++)
702 {
703 int nLabel1 = br.ReadInt32();
704 float fScore1 = br.ReadSingle();
705 rgResults.Add(new Tuple<int, float>(nLabel1, fScore1));
706 }
707
708 return new Score(DateTime.FromFileTime(lTime), nIdx, nLabel, fScore, rgResults);
709 }
710
711 public void Save(BinaryWriter bw)
712 {
713 bw.Write(m_nIdx);
714 bw.Write(m_dt.ToFileTime());
715 bw.Write(m_nLabel);
716 bw.Write(m_fScore);
717
718 bw.Write(m_rgResults.Count);
719
720 for (int i = 0; i < m_rgResults.Count; i++)
721 {
722 bw.Write(m_rgResults[i].Item1);
723 bw.Write(m_rgResults[i].Item2);
724 }
725 }
726 }
727
728 class ModelDataState : State
729 {
730 SimpleDatum m_sd = null;
731
732 public ModelDataState()
733 {
734 }
735
736 public ModelDataState(ModelDataState s)
737 {
738 m_sd = s.m_sd;
739 }
740
741 public override State Clone()
742 {
743 ModelDataState data = new ModelDataState(this);
744 data.SetData(m_sd);
745 return data;
746 }
747
748 public void SetData(SimpleDatum sd)
749 {
750 m_sd = sd;
751 }
752
753 public override SimpleDatum GetData(bool bNormalize, out int nDataLen)
754 {
755 nDataLen = (m_sd == null) ? 0 : m_sd.ItemCount;
756 return m_sd;
757 }
758 }
759}
The MyCaffeControl is the main object used to manage all training, testing and running of the MyCaffe...
void LoadToRun(string strModel, byte[] rgWeights, BlobShape shape, SimpleDatum sdMean=null, TransformationParameter transParam=null, bool bForceBackward=false, bool bConvertToRunNet=true)
The LoadToRun method loads the MyCaffeControl for running only (e.g. deployment).
ResultCollection Run(int nImageIdx, bool bPad=true)
Run on a given image in the MyCaffeImageDatabase based on its image index.
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
Definition: CancelEvent.cs:17
bool WaitOne(int nMs=int.MaxValue)
Waits for the signal state to occur.
Definition: CancelEvent.cs:290
The Log class provides general output in text form.
Definition: Log.cs:13
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
Definition: Log.cs:80
double Progress
Get/set the progress associated with the Log.
Definition: Log.cs:147
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
string GetProperty(string strName, bool bThrowExceptions=true)
Returns a property as a string value.
Definition: PropertySet.cs:146
byte[] GetPropertyBlob(string strName, bool bThrowExceptions=true)
Returns a property blob as a byte array value.
Definition: PropertySet.cs:184
int GetPropertyAsInt(string strName, int nDefault=0)
Returns a property as an integer value.
Definition: PropertySet.cs:287
bool GetPropertyAsBool(string strName, bool bDefault=false)
Returns a property as a boolean value.
Definition: PropertySet.cs:267
The Result class contains a single result.
Definition: Result.cs:14
The SettingsCaffe defines the settings used by the MyCaffe CaffeControl.
DB_LOAD_METHOD DbLoadMethod
Get/set the image database loading method.
string GpuIds
Get/set the default GPU ID's to use when training.
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
int ItemCount
Returns the number of data items.
SimpleDatum Add(SimpleDatum d)
Creates a new SimpleDatum and adds another SimpleDatum to it.
int Channels
Return the number of channels of the data.
int Width
Return the width of the data.
int Height
Return the height of the data.
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...
SourceDescriptor TrainingSource
Get/set the training data source.
The LabelDescriptor class describes a single label.
int ActiveLabel
Specifies the active label (used during training).
The SourceDescriptor class contains all information describing a data source.
List< LabelDescriptor > Labels
Get/set the list of LabelDescriptors that describe the labels used by the data items.
int ImageCount
Returns the number of images within this data source.
The Blob is the main holder of data that moves through the Layers of the Net.
Definition: Blob.cs:25
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
Definition: Blob.cs:402
The ResultCollection contains the result of a given CaffeControl::Run.
List< Result > ResultsSorted
Returns the original results in sorted order.
double DetectedLabelOutput
Returns the detected label output depending on the result type (distance or probability) with a defau...
int DetectedLabel
Returns the detected label depending on the result type (distance or probability) with a default type...
List< Result > ResultsOriginal
Returns the original results.
[V2 Image Database] The MyCaffeImageDatabase2 provides an enhanced in-memory image database used for ...
The Model Gym runs a given Project over the dataset specified within the project where each step adva...
Definition: ModelGym.cs:29
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction)
Render the gym's current state on a bitmap and SimpleDatum.
Definition: ModelGym.cs:236
void Initialize(Log log, PropertySet properties)
Initialize the gym with the specified properties.
Definition: ModelGym.cs:103
Phase ActivePhase
Get/set the active phase under which the reset and next run.
Definition: ModelGym.cs:505
Tuple< State, double, bool > Step(int nAction, bool bGetLabel=false, PropertySet extraProp=null)
Step the gym one step in the data.
Definition: ModelGym.cs:275
double TestingPercent
Returns the testinng percent of 0, which will cause the training data to be used during testing.
Definition: ModelGym.cs:191
DATA_TYPE SelectedDataType
Returns the selected data type.
Definition: ModelGym.cs:159
string Name
Returns the gym's name.
Definition: ModelGym.cs:175
Dictionary< string, int > GetActionSpace()
Returns the action space as a dictionary of name,actionid pairs.
Definition: ModelGym.cs:199
DatasetDescriptor GetDataset(DATA_TYPE dt, Log log=null)
Returns the dataset descriptor of the dynamic dataset produced by the Gym.
Definition: ModelGym.cs:422
ModelGym(ModelGym gym=null)
The constructor.
Definition: ModelGym.cs:57
int UiDelay
Returns the delay to use (if any) when the user-display is visible.
Definition: ModelGym.cs:183
void Dispose()
Release all resources used.
Definition: ModelGym.cs:82
DATA_TYPE[] SupportedDataType
Returns the data types supported by this gym.
Definition: ModelGym.cs:167
void Close()
Shutdown and close the gym.
Definition: ModelGym.cs:207
bool RequiresDisplayImage
Returns true indicating that this Gym requires a display image.
Definition: ModelGym.cs:151
byte[] ConvertOutput(Stage stage, int nN, float[] rg, out string type)
Converts the output values into the native type used by the Gym during queries.
Definition: ModelGym.cs:462
IXMyCaffeGym Clone(PropertySet properties=null)
Create a new copy of the gym.
Definition: ModelGym.cs:142
Tuple< State, double, bool > Reset(bool bGetLabel, PropertySet props=null)
Reset the state of the gym.
Definition: ModelGym.cs:262
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction)
Render the gyms specified data.
Definition: ModelGym.cs:251
State()
The constructor.
Definition: Interfaces.cs:346
Specifies the shape of a Blob.
Definition: BlobShape.cs:15
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.
bool InitializeWithDsName1(SettingsCaffe s, string strDs, string strEvtCancel=null, PropertySet prop=null)
Initializes the image database.
DatasetDescriptor GetDatasetByName(string strDs)
Returns the DatasetDescriptor for a given data set name.
The IXImageDatabaseBase interface defines the general interface to the in-memory image database.
Definition: Interfaces.cs:878
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:192
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:99
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
DB_LOAD_METHOD
Defines how to laod the items into the in-memory database.
Definition: Interfaces.cs:154
Phase
Defines the Phase under which to run a Net.
Definition: Interfaces.cs:61
DB_LABEL_SELECTION_METHOD
Defines the label selection method.
Definition: Interfaces.cs:333
GYM_TYPE
Defines the gym type (if any).
Definition: Interfaces.cs:116
DATA_TYPE
Defines the gym data type.
Definition: Interfaces.cs:135
Stage
Specifies the stage underwhich to run a custom trainer.
Definition: Interfaces.cs:88
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe.gym namespace contains all classes related to the Gym's supported by MyCaffe.
GYM_SRC_TRAIN_ID
Defines the Standard GYM Training Data Source ID's.
Definition: Interfaces.cs:45
GYM_DS_ID
Defines the Standard GYM Dataset ID's.
Definition: Interfaces.cs:18
GYM_SRC_TEST_ID
Defines the Standard GYM Testing Data Source ID's.
Definition: Interfaces.cs:72
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12