MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
EventArgs.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.param;
6using MyCaffe.basecode;
7
8namespace MyCaffe.common
9{
16 public class WorkspaceArgs : EventArgs
17 {
18 ulong m_lWorkspaceSize = 0;
19 long m_hWorkspaceData = 0; // underlying storage.
20
26 public WorkspaceArgs(long hData, ulong lSize)
27 {
28 m_hWorkspaceData = hData;
29 m_lWorkspaceSize = lSize;
30 }
31
35 public long WorkspaceData
36 {
37 get { return m_hWorkspaceData; }
38 set { m_hWorkspaceData = value; }
39 }
40
45 {
46 get { return m_lWorkspaceSize; }
47 set { m_lWorkspaceSize = value; }
48 }
49 }
50
55 public class GetConversionBlobArgs<T> : EventArgs
56 {
57 Blob<T> m_blobBaseWork;
58 Blob<T> m_blobHalfWork;
59
64 {
65 }
66
71 {
72 get { return m_blobBaseWork; }
73 set { m_blobBaseWork = value; }
74 }
75
80 {
81 get { return m_blobHalfWork; }
82 set { m_blobHalfWork = value; }
83 }
84 }
85
90 public class GetWorkBlobArgs<T> : EventArgs
91 {
92 Blob<T> m_work = null;
93
98 {
99 }
100
105 {
106 get { return m_work; }
107 set { m_work = value; }
108 }
109 }
110
115 public class TestResultArgs<T> : EventArgs
116 {
117 BlobCollection<T> m_results;
118 double m_dfAccuracy;
119 bool m_bAccuracyValid = false;
120
126 {
127 m_results = res;
128 m_dfAccuracy = 0;
129 }
130
135 {
136 get { return m_results; }
137 }
138
142 public double Accuracy
143 {
144 get { return m_dfAccuracy; }
145 set
146 {
147 m_dfAccuracy = value;
148 m_bAccuracyValid = true;
149 }
150 }
151
155 public bool AccuracyValid
156 {
157 get { return m_bAccuracyValid; }
158 set { m_bAccuracyValid = value; }
159 }
160 }
161
168 public class TestArgs : EventArgs
169 {
170 int m_nIterationOverride = -1;
171 int m_nTestNetID = 0;
172 double m_dfAccuracy = 0;
173
179 public TestArgs(int nIterationOverride, int nTestNetID)
180 {
181 m_nIterationOverride = nIterationOverride;
182 m_nTestNetID = nTestNetID;
183 }
184
189 {
190 get { return m_nIterationOverride; }
191 }
192
196 public int TestNetID
197 {
198 get { return m_nTestNetID; }
199 }
200
204 public double Accuracy
205 {
206 get { return m_dfAccuracy; }
207 set { m_dfAccuracy = value; }
208 }
209 }
210
215 public class TestingIterationArgs<T> : EventArgs
216 {
217 double m_dfAccuracy;
218 int m_nIteration;
219 double m_dfMsTiming = 0;
220
227 public TestingIterationArgs(int nIteration, double dfAccuracy, double dfMsTiming)
228 {
229 m_dfAccuracy = dfAccuracy;
230 m_nIteration = nIteration;
231 m_dfMsTiming = dfMsTiming;
232 }
233
237 public double Accuracy
238 {
239 get { return m_dfAccuracy; }
240 }
241
245 public int Iteration
246 {
247 get { return m_nIteration; }
248 }
249
253 public double Timing
254 {
255 get { return m_dfMsTiming; }
256 }
257 }
258
264 {
265 double m_dfLoss;
266 double m_dfSmoothedLoss;
267 double m_dfBestSmoothedLoss;
268 bool m_bWeightsUpdated = false;
269 string m_strActiveLabelCounts = "";
270 string m_strLabelQueryHitPercents = "";
271 string m_strLabelQueryEpochs = "";
272 string m_strBoostQueryHitPercents = "";
273 double m_dfLearningRate = 0;
274 DebugInformation<T> m_dbgInfo = null;
275
292 public TrainingIterationArgs(int nIteration, double dfAccuracy, double dfLoss, double dfSmoothedLoss, double dfBestSmoothedLoss, bool bWeightsUpdated, string strActiveLabelCounts, string strLabelQueryHitPercents, string strLabelQueryEpochs, string strBoostQueryHitPercents, double dfLearningRate, double dfMsTiming, DebugInformation<T> dbgInfo = null)
293 : base(nIteration, dfAccuracy, dfMsTiming)
294 {
295 m_dfLoss = dfLoss;
296 m_dfSmoothedLoss = dfSmoothedLoss;
297 m_dfBestSmoothedLoss = dfBestSmoothedLoss;
298 m_bWeightsUpdated = bWeightsUpdated;
299 m_strActiveLabelCounts = strActiveLabelCounts;
300 m_strLabelQueryHitPercents = strLabelQueryHitPercents;
301 m_strLabelQueryEpochs = strLabelQueryEpochs;
302 m_strBoostQueryHitPercents = strBoostQueryHitPercents;
303 m_dfLearningRate = dfLearningRate;
304 m_dbgInfo = dbgInfo;
305 }
306
310 public double Loss
311 {
312 get { return m_dfLoss; }
313 }
314
318 public double SmoothedLoss
319 {
320 get { return m_dfSmoothedLoss; }
321 }
322
326 public double BestSmoothedLoss
327 {
328 get { return m_dfBestSmoothedLoss; }
329 }
330
334 public bool WeightsUpdated
335 {
336 get { return m_bWeightsUpdated; }
337 }
338
342 public string ActiveLabelCounts
343 {
344 get { return m_strActiveLabelCounts; }
345 }
346
351 {
352 get { return m_strLabelQueryHitPercents; }
353 }
354
358 public string LabelQueryEpochs
359 {
360 get { return m_strLabelQueryEpochs; }
361 }
362
367 {
368 get { return m_strBoostQueryHitPercents; }
369 }
370
374 public double LearningRate
375 {
376 get { return m_dfLearningRate; }
377 }
378
383 {
384 get { return m_dbgInfo; }
385 }
386 }
387
391 public class GetBytesArgs : EventArgs
392 {
393 byte[] m_rgBytes = null;
394
399 {
400 }
401
405 public byte[] Data
406 {
407 get { return m_rgBytes; }
408 set { m_rgBytes = value; }
409 }
410 }
411
415 public class SnapshotArgs : EventArgs
416 {
417 byte[] m_rgWeights = null;
418 byte[] m_rgState = null;
419 double m_dfAccuracy = 0;
420 double m_dfError = 0;
421 int m_nIteration = 0;
423 bool m_bIncludeWeights = true;
424 bool m_bIncludeState = false;
425 bool m_bSingleStep = false;
426 bool m_bForced = false;
427 bool m_bScheduled = true;
428 bool m_bUpdateDatabase = true;
429
430
437 public event EventHandler<GetBytesArgs> OnGetWeights;
444 public event EventHandler<GetBytesArgs> OnGetState;
445
455 public SnapshotArgs(byte[] rgState, byte[] rgWeights, double dfAccuracy, double dfError, int nIteration, SNAPSHOT_WEIGHT_UPDATE_METHOD favor)
456 {
457 m_rgState = rgState;
458 m_rgWeights = rgWeights;
459 m_dfAccuracy = dfAccuracy;
460 m_dfError = dfError;
461 m_nIteration = nIteration;
462 m_favor = favor;
463 }
464
469 public byte[] UpdateState()
470 {
471 if (OnGetState != null)
472 {
473 GetBytesArgs args = new common.GetBytesArgs();
474 OnGetState(this, args);
475 m_rgState = args.Data;
476 return m_rgState;
477 }
478
479 return null;
480 }
481
486 public byte[] UpdateWeights()
487 {
488 if (OnGetWeights != null)
489 {
490 GetBytesArgs args = new common.GetBytesArgs();
491 OnGetWeights(this, args);
492 m_rgWeights = args.Data;
493 return m_rgWeights;
494 }
495
496 return null;
497 }
498
502 public byte[] State
503 {
504 get { return m_rgState; }
505 set { m_rgState = value; }
506 }
507
511 public byte[] Weights
512 {
513 get { return m_rgWeights; }
514 set { m_rgWeights = value; }
515 }
516
520 public double Accuracy
521 {
522 get { return m_dfAccuracy; }
523 }
524
528 public double Error
529 {
530 get { return m_dfError; }
531 }
532
536 public int Iteration
537 {
538 get { return m_nIteration; }
539 }
540
545 {
546 get { return m_favor; }
547 }
548
552 public bool IncludeWeights
553 {
554 get { return m_bIncludeWeights; }
555 set { m_bIncludeWeights = value; }
556 }
557
561 public bool IncludeState
562 {
563 get { return m_bIncludeState; }
564 set { m_bIncludeState = value; }
565 }
566
570 public bool SingleStep
571 {
572 get { return m_bSingleStep; }
573 set { m_bSingleStep = value; }
574 }
575
579 public bool Forced
580 {
581 get { return m_bForced; }
582 set { m_bForced = value; }
583 }
584
588 public bool Scheduled
589 {
590 get { return m_bScheduled; }
591 set { m_bScheduled = value; }
592 }
593
597 public bool UpdateDatabase
598 {
599 get { return m_bUpdateDatabase; }
600 set { m_bUpdateDatabase = value; }
601 }
602 }
603
608 public class CustomForwardBackArgs<T> : EventArgs
609 {
610 Net<T> m_net;
611 TRAIN_STEP m_step;
612 bool m_bFwdPassNanFree = true;
613 double m_dfLocalLoss = 0;
614
621 {
622 m_net = net;
623 m_step = step;
624 }
625
629 public Net<T> net
630 {
631 get { return m_net; }
632 }
633
638 {
639 get { return m_step; }
640 }
641
645 public bool FwdPassNanFree
646 {
647 get { return m_bFwdPassNanFree; }
648 set { m_bFwdPassNanFree = value; }
649 }
650
654 public double LocalLoss
655 {
656 get { return m_dfLocalLoss; }
657 set { m_dfLocalLoss = value; }
658 }
659 }
660
665 public class ForwardArgs<T>
666 {
667 BlobCollection<T> m_colTop;
668 BlobCollection<T> m_colBottom;
669
676 {
677 m_colTop = colTop;
678 m_colBottom = colBottom;
679 }
680
685 {
686 get { return m_colBottom; }
687 }
688
693 {
694 get { return m_colTop; }
695 }
696 }
697
702 public class BackwardArgs<T> : ForwardArgs<T>
703 {
704 List<bool> m_rgbPropagateDown;
705
712 public BackwardArgs(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
713 : base(colBottom, colTop)
714 {
715 m_rgbPropagateDown = rgbPropagateDown;
716 }
717
721 public List<bool> PropagateDown
722 {
723 get { return m_rgbPropagateDown; }
724 }
725 }
726
733 public class GradientsReadyArgs : EventArgs
734 {
739 {
740 }
741 }
742
747 public class GetIterationArgs : EventArgs
748 {
749 int m_nIteration = 0;
750 Phase m_phase = Phase.TRAIN;
751
756 {
757 }
758
764 public void SetIteration(Phase p, int nIteration)
765 {
766 m_phase = p;
767 m_nIteration = nIteration;
768 }
769
773 public int Iteration
774 {
775 get { return m_nIteration; }
776 }
777
782 {
783 get { return m_phase; }
784 }
785 }
786}
The BackwardArgs are passed to the OnBackward event of the EventLayer.
Definition: EventArgs.cs:703
BackwardArgs(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
The constructor.
Definition: EventArgs.cs:712
List< bool > PropagateDown
Returns the list on whether or not to propagate down.
Definition: EventArgs.cs:722
The BlobCollection contains a list of Blobs.
The Blob is the main holder of data that moves through the Layers of the Net.
Definition: Blob.cs:25
The CustomForwardBackArgs provide the arguments to the OnCustomForwardBack event within the Solver St...
Definition: EventArgs.cs:609
double LocalLoss
Get/set the local loss of the pass.
Definition: EventArgs.cs:655
TRAIN_STEP step
Returns whether or not to step the operation.
Definition: EventArgs.cs:638
Net< T > net
Returns the training network.
Definition: EventArgs.cs:630
bool FwdPassNanFree
Get/set whether or a NAN was detected in the forward pass.
Definition: EventArgs.cs:646
CustomForwardBackArgs(Net< T > net, TRAIN_STEP step)
The constructor.
Definition: EventArgs.cs:620
The DebugInformation contains information used to help debug the Layers of a Net while it is training...
The ForwardArgs are passed to the OnForward event of the EventLayer.
Definition: EventArgs.cs:666
BlobCollection< T > BottomVec
Returns the bottom blobs.
Definition: EventArgs.cs:685
ForwardArgs(BlobCollection< T > colBottom, BlobCollection< T > colTop)
The constructor.
Definition: EventArgs.cs:675
BlobCollection< T > TopVec
Returns the top blobs.
Definition: EventArgs.cs:693
The GetBytesArgs is passed along to the SnapshotArgs::OnGetWeights and SnapshotArgs::OnGetState event...
Definition: EventArgs.cs:392
byte[] Data
Get/set the data as an array of bytes.
Definition: EventArgs.cs:406
GetBytesArgs()
The GetBytesArgs constructor.
Definition: EventArgs.cs:398
The GetConversionBlobArgs are passed to the Layer::OnGetConversionBlobs event which fires each time a...
Definition: EventArgs.cs:56
GetConversionBlobArgs()
The constructor.
Definition: EventArgs.cs:63
Blob< T > BaseWork
The work blob in the base size.
Definition: EventArgs.cs:71
Blob< T > HalfWork
The work blob in the half size.
Definition: EventArgs.cs:80
The GetIterationArgs is sent bubbled up to the solver when a layer needs to know the curret training ...
Definition: EventArgs.cs:748
GetIterationArgs()
The constructor.
Definition: EventArgs.cs:755
int Iteration
Returns the iteration.
Definition: EventArgs.cs:774
Phase CurrentPhase
Returns the phase.
Definition: EventArgs.cs:782
void SetIteration(Phase p, int nIteration)
The SetIteration method is used to set the iteration and the phase.
Definition: EventArgs.cs:764
The GetWorkBlobArgs are passed to the Layer::OnGetWorkBlob event which is supported for debugging onl...
Definition: EventArgs.cs:91
GetWorkBlobArgs()
The constructor.
Definition: EventArgs.cs:97
The GradientsReadyArgs is sent to the Solver::OnGradientsReady event which fires at the end of each S...
Definition: EventArgs.cs:734
GradientsReadyArgs()
The GradientReadyArgs constructor.
Definition: EventArgs.cs:738
Connects Layer's together into a direct acrylic graph (DAG) specified by a NetParameter
Definition: Net.cs:23
The SnapshotArgs is sent to the Solver::OnSnapshot event which fires each time the Solver::Snapshot m...
Definition: EventArgs.cs:416
byte[] UpdateWeights()
Retrieves the updated training Net weights as an array of bytes.
Definition: EventArgs.cs:486
int Iteration
Returns the current iteration of the current training session.
Definition: EventArgs.cs:537
bool Forced
Get/set whether or not the snapshot was forced or not.
Definition: EventArgs.cs:580
byte[] UpdateState()
Retrieves the updated Solver state as an array of bytes.
Definition: EventArgs.cs:469
bool SingleStep
Get/set the Solver single step.
Definition: EventArgs.cs:571
bool IncludeWeights
Get/set whether or not to include the weights in the snapshot.
Definition: EventArgs.cs:553
bool Scheduled
Get/set whether or not the snapshot is a regular scheduled snapshot (e.g. not an improved accuracy or...
Definition: EventArgs.cs:589
bool IncludeState
Get/set whether or not to include the Solver state in the snapshot.
Definition: EventArgs.cs:562
byte[] State
Get/set the Solver State.
Definition: EventArgs.cs:503
SnapshotArgs(byte[] rgState, byte[] rgWeights, double dfAccuracy, double dfError, int nIteration, SNAPSHOT_WEIGHT_UPDATE_METHOD favor)
The SnapshotArgs constructor.
Definition: EventArgs.cs:455
byte[] Weights
Get/set the Weights.
Definition: EventArgs.cs:512
EventHandler< GetBytesArgs > OnGetState
Specifies the OnGetState event which fires when the SnapshotArgs::UpdateState method is called.
Definition: EventArgs.cs:444
double Accuracy
Returns the last observed Solver accuracy for the current training session.
Definition: EventArgs.cs:521
bool UpdateDatabase
Get/set whether or not to update the database (default = true).
Definition: EventArgs.cs:598
SNAPSHOT_WEIGHT_UPDATE_METHOD Favor
Specifies whether to favor the error, the accuracy or both when deciding whether a snapshot should ta...
Definition: EventArgs.cs:545
EventHandler< GetBytesArgs > OnGetWeights
Specifies the OnGetWeights event which fires when the SnapshotArgs::UpdateWeights method is called.
Definition: EventArgs.cs:437
double Error
Returns the last observed Solver error for the current training session.
Definition: EventArgs.cs:529
The TestArgs are passed to the Solver::OnTest event.
Definition: EventArgs.cs:169
TestArgs(int nIterationOverride, int nTestNetID)
The TestArgs constructor.
Definition: EventArgs.cs:179
int IterationOverride
Returns the testing iteration override. When set to -1, the solver description test iteration is used...
Definition: EventArgs.cs:189
double Accuracy
Get/set the accuracy for the test run. When overriding the testing, the override should set the accur...
Definition: EventArgs.cs:205
int TestNetID
Returns the test Net identifier of the Solver test Net to run.
Definition: EventArgs.cs:197
The TestResultArgs are passed to the Solver::OnTestResults event.
Definition: EventArgs.cs:116
bool AccuracyValid
Get/set the accuracy valid flag. When not valid, the OnTestResults event is ignored.
Definition: EventArgs.cs:156
BlobCollection< T > Results
Returns the results from the test.
Definition: EventArgs.cs:135
TestResultArgs(BlobCollection< T > res)
The constructor.
Definition: EventArgs.cs:125
double Accuracy
Get/set the accuracy. The recipient of this event should set this value.
Definition: EventArgs.cs:143
Specifies the TestingIterationArgs sent to the Solver::OnTestingIteration, which is called at the end...
Definition: EventArgs.cs:216
double Timing
Return the timing of the test cycle in ms.
Definition: EventArgs.cs:254
double Accuracy
Return the accuracy of the test cycle.
Definition: EventArgs.cs:238
int Iteration
Return the iteration of the test cycle.
Definition: EventArgs.cs:246
TestingIterationArgs(int nIteration, double dfAccuracy, double dfMsTiming)
The TestingIterationArgs constructor.
Definition: EventArgs.cs:227
The TrainingIterationArgs is sent to the Solver::OnTrainingIteration event that fires at the end of a...
Definition: EventArgs.cs:264
string ActiveLabelCounts
Returns the current active label counts as a string.
Definition: EventArgs.cs:343
double LearningRate
Return the current learning rate.
Definition: EventArgs.cs:375
string LabelQueryEpochs
Returns the current label epochs per label observed at this point in training.
Definition: EventArgs.cs:359
double BestSmoothedLoss
Returns the best smoothed loss observed during the training.
Definition: EventArgs.cs:327
double Loss
Returns the loss of the training cycle.
Definition: EventArgs.cs:311
double SmoothedLoss
Retunrs the average loss after the training cycle.
Definition: EventArgs.cs:319
string LabelQueryHitPercents
Returns the current label query hit percentages observed at this point in training.
Definition: EventArgs.cs:351
string BoostQueryHitPercents
Returns the current boost query hit percentages observed at this point in training.
Definition: EventArgs.cs:367
bool WeightsUpdated
Returns whether or not the weights have been updated.
Definition: EventArgs.cs:335
TrainingIterationArgs(int nIteration, double dfAccuracy, double dfLoss, double dfSmoothedLoss, double dfBestSmoothedLoss, bool bWeightsUpdated, string strActiveLabelCounts, string strLabelQueryHitPercents, string strLabelQueryEpochs, string strBoostQueryHitPercents, double dfLearningRate, double dfMsTiming, DebugInformation< T > dbgInfo=null)
The TrainingIterationArgs constructor.
Definition: EventArgs.cs:292
The WorkspaceArgs are passed to both the Layer::OnSetWorkspace and Layer::OnGetWorkspace events.
Definition: EventArgs.cs:17
long WorkspaceData
Get/set the handle to workspace data in GPU memory.
Definition: EventArgs.cs:36
ulong WorkspaceSizeInBytes
Get/set the workspace memory size in bytes.
Definition: EventArgs.cs:45
WorkspaceArgs(long hData, ulong lSize)
The WorkspaceArgs constructor.
Definition: EventArgs.cs:26
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
SNAPSHOT_WEIGHT_UPDATE_METHOD
Defines the snapshot weight update method.
Definition: Interfaces.cs:181
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
TRAIN_STEP
Defines the training stepping method (if any).
Definition: Interfaces.cs:131
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