MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
EventArgs.cs
1using MyCaffe.basecode;
2using MyCaffe.gym;
3using System;
4using System.Collections.Generic;
6using System.Drawing;
7using System.Linq;
8using System.Text;
9using System.Threading;
10using System.Threading.Tasks;
11
12namespace MyCaffe.trainers
13{
18 public class ApplyUpdateArgs<T> : EventArgs
19 {
20 MyCaffeControl<T> m_mycaffeWorker;
21 int m_nIteration;
22 double m_dfLearningRate;
23
29 public ApplyUpdateArgs(int nIteration, MyCaffeControl<T> mycaffeWorker)
30 {
31 m_nIteration = nIteration;
32 m_mycaffeWorker = mycaffeWorker;
33 }
34
39 {
40 get { return m_mycaffeWorker; }
41 }
42
46 public int Iteration
47 {
48 get { return m_nIteration; }
49 }
50
54 public double LearningRate
55 {
56 get { return m_dfLearningRate; }
57 set { m_dfLearningRate = value; }
58 }
59 }
60
64 public class WaitArgs : EventArgs
65 {
66 int m_nWait;
67
72 public WaitArgs(int nWait)
73 {
74 m_nWait = nWait;
75 }
76
80 public int Wait
81 {
82 get { return m_nWait; }
83 }
84 }
85
89 public class InitializeArgs : EventArgs
90 {
91 ConnectInfo m_ci = null;
92 int m_nOriginalDsId = 0;
93 int m_nDsID = 0;
94 Component m_caffe;
95 Log m_log;
96
101 public InitializeArgs(Component mycaffe)
102 {
103 m_caffe = mycaffe;
104
105 if (mycaffe is MyCaffeControl<double>)
106 {
108 m_log = mycaffe1.Log;
109 m_nOriginalDsId = mycaffe1.CurrentProject.Dataset.ID;
110 }
111 else
112 {
113 MyCaffeControl<float> mycaffe1 = mycaffe as MyCaffeControl<float>;
114 m_log = mycaffe1.Log;
115 m_nOriginalDsId = mycaffe1.CurrentProject.Dataset.ID;
116 }
117 }
118
123 {
124 get { return m_log; }
125 }
126
131 {
132 get { return m_caffe; }
133 }
134
139 {
140 get { return m_ci; }
141 set { m_ci = value; }
142 }
143
148 {
149 get { return m_nOriginalDsId; }
150 }
151
155 public int DatasetID
156 {
157 get { return m_nDsID; }
158 set { m_nDsID = value; }
159 }
160 }
161
165 public class GetStatusArgs : EventArgs
166 {
167 int m_nIndex = 0;
168 int m_nNewFrameCount = 0;
169 int m_nTotalFrames = 0;
170 int m_nMaxFrames = 0;
171 int m_nIteration = 0;
172 double m_dfTotalReward = 0;
173 double m_dfReward = 0;
174 double m_dfExplorationRate = 0;
175 double m_dfOptimalCoeff = 0;
176 double m_dfLoss = 0;
177 double m_dfLearningRate = 0;
178 bool m_bModelUpdated = false;
179
194 public GetStatusArgs(int nIndex, int nIteration, int nFrames, int nMaxFrames, double dfTotalReward, double dfReward, double dfExplorationRate, double dfOptimalCoeff, double dfLoss, double dfLearningRate, bool bModelUpdated = false)
195 {
196 m_nIndex = nIndex;
197 m_nIteration = nIteration;
198 m_nTotalFrames = nFrames;
199 m_nMaxFrames = nMaxFrames;
200 m_dfTotalReward = dfTotalReward;
201 m_dfReward = dfReward;
202 m_dfExplorationRate = dfExplorationRate;
203 m_dfOptimalCoeff = dfOptimalCoeff;
204 m_dfLoss = dfLoss;
205 m_dfLearningRate = dfLearningRate;
206 m_bModelUpdated = bModelUpdated;
207 }
208
212 public int Index
213 {
214 get { return m_nIndex; }
215 }
216
220 public int Iteration
221 {
222 get { return m_nIteration; }
223 }
224
228 public int NewFrameCount
229 {
230 get { return m_nNewFrameCount; }
231 set { m_nNewFrameCount = value; }
232 }
233
237 public int Frames
238 {
239 get { return m_nTotalFrames; }
240 }
241
245 public int MaxFrames
246 {
247 get { return m_nMaxFrames; }
248 }
249
253 public bool ModelUpdated
254 {
255 get { return m_bModelUpdated; }
256 }
257
261 public double Loss
262 {
263 get { return m_dfLoss; }
264 }
265
269 public double LearningRate
270 {
271 get { return m_dfLearningRate; }
272 }
273
277 public double TotalReward
278 {
279 get { return m_dfTotalReward; }
280 }
281
285 public double Reward
286 {
287 get { return m_dfReward; }
288 }
289
293 public double ExplorationRate
294 {
295 get { return m_dfExplorationRate; }
296 }
297
302 {
303 get { return m_dfOptimalCoeff; }
304 }
305 }
306
310 public class ConvertOutputArgs : EventArgs
311 {
312 float[] m_rgOutput;
313 string m_type;
314 int m_nN;
315 byte[] m_rgRawOutput;
316
322 public ConvertOutputArgs(int nN, float[] rgOutput)
323 {
324 m_nN = nN;
325 m_rgOutput = rgOutput;
326 }
327
331 public int ResultCount
332 {
333 get { return m_nN; }
334 }
335
339 public float[] Output
340 {
341 get { return m_rgOutput; }
342 }
343
347 public string RawType
348 {
349 get { return m_type; }
350 }
351
355 public byte[] RawOutput
356 {
357 get { return m_rgRawOutput; }
358 }
359
365 public void SetRawOutput(byte[] rgData, string type)
366 {
367 m_rgRawOutput = rgData;
368 m_type = type;
369 }
370 }
371
375 public class OverlayArgs : EventArgs
376 {
377 Bitmap m_bmp;
378
383 public OverlayArgs(Bitmap bmp)
384 {
385 m_bmp = bmp;
386 }
387
391 public Bitmap DisplayImage
392 {
393 get { return m_bmp; }
394 set { m_bmp = value; }
395 }
396 }
397
401 public class GetDataArgs : EventArgs
402 {
403 int m_nAction;
404 bool m_bReset;
405 Component m_caffe;
406 Log m_log;
407 ManualResetEvent m_evtDataReady = null;
408 CancelEvent m_evtCancel;
409 StateBase m_state = null;
410 int m_nIndex = 0;
411 bool m_bGetLabel = false;
412 Phase m_phase = Phase.NONE;
413 PropertySet m_properties = null;
414 IxTrainerGetDataCallback m_iOnGetData = null;
415
430 public GetDataArgs(Phase phase, int nIdx, Component mycaffe, Log log, CancelEvent evtCancel, bool bReset, int nAction = -1, bool bAllowUi = true, bool bGetLabel = false, bool bBatchMode = false, IxTrainerGetDataCallback iOnGetData = null)
431 {
432 if (bBatchMode)
433 m_evtDataReady = new ManualResetEvent(false);
434
435 m_phase = phase;
436 m_nIndex = nIdx;
437 m_nAction = nAction;
438 m_caffe = mycaffe;
439 m_log = log;
440 m_evtCancel = evtCancel;
441 m_bReset = bReset;
442 m_bGetLabel = bGetLabel;
443 m_iOnGetData = iOnGetData;
444 }
445
450 {
451 get { return m_iOnGetData; }
452 }
453
458 {
459 get { return m_properties; }
460 set { m_properties = value; }
461 }
462
467 {
468 get { return m_phase; }
469 }
470
475 public ManualResetEvent DataReady
476 {
477 get { return m_evtDataReady; }
478 }
479
483 public int Index
484 {
485 get { return m_nIndex; }
486 set { m_nIndex = value; }
487 }
488
492 public bool GetLabel
493 {
494 get { return m_bGetLabel; }
495 }
496
501 {
502 get { return m_log; }
503 }
504
509 {
510 get { return m_evtCancel; }
511 }
512
517 {
518 get { return m_state; }
519 set { m_state = value; }
520 }
521
525 public int Action
526 {
527 get { return m_nAction; }
528 set { m_nAction = value; }
529 }
530
535 {
536 get { return m_caffe; }
537 }
538
542 public bool Reset
543 {
544 get { return m_bReset; }
545 set { m_bReset = value; }
546 }
547 }
548
552 public class TestAccuracyUpdateArgs : EventArgs
553 {
554 int m_nDetectedLabel;
555 int m_nExpectedLabel;
556 bool m_bIsCorrect;
557 bool m_bHandled = false;
558
564 public TestAccuracyUpdateArgs(int nDetectedLabel, int nExpectedLabel)
565 {
566 m_nDetectedLabel = nDetectedLabel;
567 m_nExpectedLabel = nExpectedLabel;
568 m_bIsCorrect = false;
569 }
570
574 public int DetectedLabel
575 {
576 get { return m_nDetectedLabel; }
577 }
578
582 public int ExpectedLabel
583 {
584 get { return m_nExpectedLabel; }
585 }
586
590 public bool IsCorrect
591 {
592 get { return m_bIsCorrect; }
593 set
594 {
595 m_bIsCorrect = value;
596 m_bHandled = true;
597 }
598 }
599
603 public bool Handled
604 {
605 get { return m_bHandled; }
606 }
607 }
608}
The MyCaffeControl is the main object used to manage all training, testing and running of the MyCaffe...
Log Log
Returns the Log (for output) used.
ProjectEx CurrentProject
Returns the name of the currently loaded project.
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
Definition: CancelEvent.cs:17
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
Definition: ConnectInfo.cs:14
The Log class provides general output in text form.
Definition: Log.cs:13
DatasetDescriptor Dataset
Return the descriptor of the dataset used.
Definition: ProjectEx.cs:896
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
The State class defines an abstract base class for the state information and gym data.
Definition: Interfaces.cs:337
The ApplyUpdateArgs is passed to the OnApplyUpdates event.
Definition: EventArgs.cs:19
int Iteration
Returns the iteration from which the gradients are to be applied.
Definition: EventArgs.cs:47
double LearningRate
Returns the learning rate at the time the gradients were applied.
Definition: EventArgs.cs:55
ApplyUpdateArgs(int nIteration, MyCaffeControl< T > mycaffeWorker)
The constructor.
Definition: EventArgs.cs:29
MyCaffeControl< T > MyCaffeWorker
Returns the MyCaffe worker instance whos gradients are to be applied.
Definition: EventArgs.cs:39
The ConvertOutputArgs is passed to the OnConvertOutput event.
Definition: EventArgs.cs:311
byte[] RawOutput
Specifies the raw output byte stream.
Definition: EventArgs.cs:356
ConvertOutputArgs(int nN, float[] rgOutput)
The constructor.
Definition: EventArgs.cs:322
float[] Output
Specifies the output to convert.
Definition: EventArgs.cs:340
void SetRawOutput(byte[] rgData, string type)
Sets the raw output byte stream and type.
Definition: EventArgs.cs:365
string RawType
Specifies the type of the raw output byte stream.
Definition: EventArgs.cs:348
int ResultCount
Returns the number of results.
Definition: EventArgs.cs:332
The GetDataArgs is passed to the OnGetData event to retrieve data.
Definition: EventArgs.cs:402
Log OutputLog
Returns the output log for general output.
Definition: EventArgs.cs:501
Phase ActivePhase
Returns the active phase under which to get the data.
Definition: EventArgs.cs:467
PropertySet ExtraProperties
Get/set extra properties.
Definition: EventArgs.cs:458
bool GetLabel
Returns whether or not to retrieve the label in addition to the data.
Definition: EventArgs.cs:493
bool Reset
Returns whether or not to reset the observation environment or not.
Definition: EventArgs.cs:543
ManualResetEvent DataReady
Returns the data ready event that is set once the data has been retrieved. This field is only used wh...
Definition: EventArgs.cs:476
int Action
Returns the action to run. If less than zero, this parameter is ignored.
Definition: EventArgs.cs:526
GetDataArgs(Phase phase, int nIdx, Component mycaffe, Log log, CancelEvent evtCancel, bool bReset, int nAction=-1, bool bAllowUi=true, bool bGetLabel=false, bool bBatchMode=false, IxTrainerGetDataCallback iOnGetData=null)
The constructor.
Definition: EventArgs.cs:430
int Index
Returns the index of the thread asking for the gym.
Definition: EventArgs.cs:484
IxTrainerGetDataCallback GetDataCallback
Returns the OnGetData Callback called just after rendering yet before displaying the gym image.
Definition: EventArgs.cs:450
The GetStatusArgs is passed to the OnGetStatus event.
Definition: EventArgs.cs:166
bool ModelUpdated
Returns whether or not the model has been updated or not.
Definition: EventArgs.cs:254
double Loss
Returns the loss value.
Definition: EventArgs.cs:262
double OptimalSelectionCoefficient
Returns the optimal selection coefficient.
Definition: EventArgs.cs:302
int MaxFrames
Returns the maximum frame count.
Definition: EventArgs.cs:246
int Iteration
Returns the number of iterations (steps) run.
Definition: EventArgs.cs:221
int Frames
Returns the total frame count across all agents.
Definition: EventArgs.cs:238
int NewFrameCount
Get/set the new frame count.
Definition: EventArgs.cs:229
double ExplorationRate
Returns the current exploration rate.
Definition: EventArgs.cs:294
double TotalReward
Returns the total rewards.
Definition: EventArgs.cs:278
int Index
Returns the index of the caller.
Definition: EventArgs.cs:213
double Reward
Returns the immediate reward for the current episode.
Definition: EventArgs.cs:286
double LearningRate
Returns the current learning rate.
Definition: EventArgs.cs:270
GetStatusArgs(int nIndex, int nIteration, int nFrames, int nMaxFrames, double dfTotalReward, double dfReward, double dfExplorationRate, double dfOptimalCoeff, double dfLoss, double dfLearningRate, bool bModelUpdated=false)
The constructor.
Definition: EventArgs.cs:194
The InitializeArgs is passed to the OnInitialize event.
Definition: EventArgs.cs:90
int DatasetID
Get/set a new Dataset ID which is actually used.
Definition: EventArgs.cs:156
ConnectInfo DatasetConnectInfo
Specifies the dataset connection information (if provided).
Definition: EventArgs.cs:139
InitializeArgs(Component mycaffe)
The constructor.
Definition: EventArgs.cs:101
int OriginalDatasetID
Returns the original Dataset ID of the open project held by the MyCaffeControl.
Definition: EventArgs.cs:148
Log OutputLog
Returns the output log.
Definition: EventArgs.cs:123
The OverlayArgs is passed ot the OnOverlay event, optionally fired just before displaying a gym image...
Definition: EventArgs.cs:376
OverlayArgs(Bitmap bmp)
The constructor.
Definition: EventArgs.cs:383
Bitmap DisplayImage
Get/set the display image.
Definition: EventArgs.cs:392
The StateBase is the base class for the state of each observation - this is defined by actual trainer...
Definition: StateBase.cs:16
The TestAccuracyUpdateArgs are passed to the OnTestAccuracyUpdate event.
Definition: EventArgs.cs:553
int ExpectedLabel
Returns the expected label.
Definition: EventArgs.cs:583
bool Handled
Get whether or not the event was handled.
Definition: EventArgs.cs:604
bool IsCorrect
Get/set whether or not the expected and detected label match in a correct way.
Definition: EventArgs.cs:591
TestAccuracyUpdateArgs(int nDetectedLabel, int nExpectedLabel)
The constructor.
Definition: EventArgs.cs:564
int DetectedLabel
Returns the detected label.
Definition: EventArgs.cs:575
The WaitArgs is passed to the OnWait event.
Definition: EventArgs.cs:65
WaitArgs(int nWait)
The constructor.
Definition: EventArgs.cs:72
int Wait
Returns the amount of time to wait in milliseconds.
Definition: EventArgs.cs:81
The Component class is a standard Microsoft.NET class that implements the IComponent interface and is...
Definition: Component.cs:18
The IxTrainerGetDataCallback interface is called right after rendering the output image and just befo...
Definition: Interfaces.cs:335
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
Phase
Defines the Phase under which to run a Net.
Definition: Interfaces.cs:61
The MyCaffe.gym namespace contains all classes related to the Gym's supported by MyCaffe.
The MyCaffe.trainers namespace contains all reinforcement and recurrent learning trainers.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12