MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
Interfaces.cs
1using MyCaffe.basecode;
3using MyCaffe.db.image;
4using MyCaffe.param;
5using System;
6using System.Collections.Generic;
7using System.Drawing;
8using System.IO;
9using System.Linq;
10using System.Runtime.Serialization;
11using System.Text;
12using System.Threading;
13using System.Threading.Tasks;
14
18namespace MyCaffe.common
19{
25 public delegate void onSetWorkspace(object sender, WorkspaceArgs e);
31 public delegate void onGetWorkspace(object sender, WorkspaceArgs e);
32
36 [Serializable]
37 public enum WEIGHT_TARGET
38 {
42 NONE,
46 WEIGHTS,
50 BIAS,
54 BOTH
55 }
56
60 [Serializable]
61 public enum BLOB_TYPE
62 {
66 UNKNOWN = 0x0000,
70 DATA = 0x0001,
74 IP_WEIGHT = 0x0002,
78 WEIGHT = 0x0004,
82 LOSS = 0x0008,
86 ACCURACY = 0x0010,
90 CLIP = 0x0020,
106 MULTIBBOX = 0x0040,
110 INTERNAL = 0x0080,
114 TARGET = 0x0100,
118 PREDICTION = 0x0200,
122 ATTENTION = 0x0400
123 }
124
128 [Serializable]
129 [DataContract]
130 public enum TRAIN_STEP
131 {
135 [EnumMember]
136 NONE = 0x0000,
140 [EnumMember]
141 FORWARD = 0x0001,
145 [EnumMember]
146 BACKWARD = 0x0002,
150 [EnumMember]
151 BOTH = 0x0003
152 }
153
158 public interface IXDebugData<T>
159 {
171 string name { get; }
175 long kernel_handle { get; }
179 int load_count { get; }
180 }
181
186 public interface IXPersist<T>
187 {
200 byte[] SaveWeights(BlobCollection<T> colBlobs, bool bSaveDiffs = false);
201
220 BlobCollection<T> LoadWeights(byte[] rgWeights, List<string> rgExpectedShapes, BlobCollection<T> colBlobs, bool bSizeToFit, out bool bLoadedDiffs, List<string> inputWtInfo = null, List<string> targetWtInfo = null, string strSkipBlobType = null);
221
229
237
243 WeightInfo<T> LoadWeightInfo(byte[] rgWeights);
244
251 }
252
257 public interface IXMyCaffeState<T>
258 {
263 void SetOnTestOverride(EventHandler<TestArgs> onTest);
264
269 void AddCancelOverrideByName(string strEvtCancel);
270
276
281 void RemoveCancelOverrideByName(string strEvtCancel);
282
288
295 bool EnableBlobDebugging { get; set; }
302 bool EnableBreakOnFirstNaN { get; set; }
306 bool EnableDetailedNanDetection { get; set; }
313 bool EnableSingleStep { get; set; }
320 bool EnableLayerDebugging { get; set; }
321
330
338 List<int> ActiveGpus { get; }
345 string ActiveLabelCounts { get; }
352 string LabelQueryHitPercents { get; }
359 string LabelQueryEpochs { get; }
363 string CurrentDevice { get; }
371 int CurrentIteration { get; }
375 int MaximumIteration { get; }
386 string GetDeviceName(int nDeviceID);
394 bool ReInitializeParameters(WEIGHT_TARGET target, params string[] rgstrLayers);
402 bool VerifyCompute(string strExtra = null, int nDeviceID = -1, bool bThrowException = true);
403 }
404
409 public interface IXMyCaffe<T>
410 {
428 bool Load(Phase phase, ProjectEx p, DB_LABEL_SELECTION_METHOD? labelSelectionOverride = null, DB_ITEM_SELECTION_METHOD? itemSelectionOverride = null, bool bResetFirst = false, IXDatabaseBase db = null, bool bUseDb = true, bool bCreateRunNet = true, string strStage = null, bool bEnableMemTrace = false);
448 bool Load(Phase phase, string strSolver, string strModel, byte[] rgWeights, DB_LABEL_SELECTION_METHOD? labelSelectionOverride = null, DB_ITEM_SELECTION_METHOD? itemSelectionOverride = null, bool bResetFirst = false, IXDatabaseBase db = null, bool bUseDb = true, bool bCreateRunNet = true, string strStage = null, bool bEnableMemTrace = false);
454 void Unload(bool bUnloadDb = true, bool bIgnoreExceptions = false);
463 void Train(int nIterationOverride = -1, int nTrainingTimeLimitInMinutes = 0, TRAIN_STEP step = TRAIN_STEP.NONE, double dfLearningRateOverride = 0, bool bReset = false);
469 double Test(int nIterationOverride = -1);
488 List<Tuple<SimpleDatum, ResultCollection>> TestMany(int nCount, bool bOnTrainingSet, bool bOnTargetSet = false, DB_ITEM_SELECTION_METHOD imgSelMethod = DB_ITEM_SELECTION_METHOD.RANDOM, int nImageStartIdx = 0, DateTime? dtImageStartTime = null, double? dfThreshold = null);
495 ResultCollection Run(int nImageIdx, bool bPad = true);
501 List<ResultCollection> Run(List<int> rgImageIdx);
509 ResultCollection Run(SimpleDatum d, bool bSort = true, bool bUseSolverNet = false);
517 Bitmap GetTestImage(Phase phase, out int nLabel, out string strLabel);
524 Bitmap GetTestImage(Phase phase, int nLabel);
539 byte[] GetWeights();
545 void UpdateRunWeights(bool bOutputStatus = false, bool bVerifyWeights = true);
550 void UpdateWeights(byte[] rgWeights);
556 string GetLicenseText(string strOtherLicenses);
557 }
558
563 public interface IXMyCaffeNoDb<T>
564 {
579 void LoadToRun(string strModel, byte[] rgWeights, BlobShape shape, SimpleDatum sdMean = null, TransformationParameter transParam = null, bool bForceBackward = false, bool bConvertToRunNet = true);
587 Blob<T> CreateDataBlob(SimpleDatum d, Blob<T> blob = null, bool bPad = true);
598 ResultCollection Run(Bitmap img, bool bSort = true, bool bPad = true);
606 ResultCollection Run(SimpleDatum d, bool bSort = true, bool bPad = true);
607 }
608
613 public interface IXMyCaffeExtension<T>
614 {
620 long CreateExtension(string strExtensionDLLPath);
625 void FreeExtension(long hExtension);
633 T[] RunExtension(long hExtension, long lfnIdx, T[] rgParam);
641 double[] RunExtensionD(long hExtension, long lfnIdx, double[] rgParam);
649 float[] RunExtensionF(long hExtension, long lfnIdx, float[] rgParam);
650 }
651}
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
Definition: CancelEvent.cs:17
The ProjectEx class manages a project containing the solver description, model description,...
Definition: ProjectEx.cs:15
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
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 ResultCollection contains the result of a given CaffeControl::Run.
The WeightInfo class describes the weights of a given weight set including the blob names and sizes o...
Definition: WeightInfo.cs:15
The WorkspaceArgs are passed to both the Layer::OnSetWorkspace and Layer::OnGetWorkspace events.
Definition: EventArgs.cs:17
The Database class manages the actual connection to the physical database using Entity Framworks from...
Definition: Database.cs:23
Specifies the shape of a Blob.
Definition: BlobShape.cs:15
The SolverParameter is a parameter for the solver, specifying the train and test networks.
SolverType
Defines the type of solver.
The SolverState specifies the state of a given solver.
Definition: SolverState.cs:17
Stores parameters used to apply transformation to the data layer's data.
The IXDatabaseBase interface defines the general interface to the in-memory database.
Definition: Interfaces.cs:444
The IXDebugData interface is implemented by the DebugLayer to give access to the debug information ma...
Definition: Interfaces.cs:159
long kernel_handle
Returns the handle to the kernel within the low-level Cuda Dnn DLL that where the data memory resides...
Definition: Interfaces.cs:175
int load_count
Returns the number of data items loaded into the collection.
Definition: Interfaces.cs:179
BlobCollection< T > data
Returns the collection of data blobs.
Definition: Interfaces.cs:163
BlobCollection< T > labels
Returns the collection of label blobs.
Definition: Interfaces.cs:167
string name
Returns the name of the data set.
Definition: Interfaces.cs:171
The IXMyCaffeExtension interface allows for easy extension management of the low-level software that ...
Definition: Interfaces.cs:614
void FreeExtension(long hExtension)
Free an existing extension and unload it.
T[] RunExtension(long hExtension, long lfnIdx, T[] rgParam)
Run a function on an existing extension.
long CreateExtension(string strExtensionDLLPath)
Create and load a new extension DLL.
float[] RunExtensionF(long hExtension, long lfnIdx, float[] rgParam)
Run a function on an existing extension using the float base type.
double[] RunExtensionD(long hExtension, long lfnIdx, double[] rgParam)
Run a function on an existing extension using the double base type.
The IXMyCaffe interface contains functions used to perform MyCaffe operations that work with the MyCa...
Definition: Interfaces.cs:410
SimpleDatum GetItemMean()
Returns the image mean used by the solver network used during training.
void Unload(bool bUnloadDb=true, bool bIgnoreExceptions=false)
Unload the currently loaded project.
bool Load(Phase phase, string strSolver, string strModel, byte[] rgWeights, DB_LABEL_SELECTION_METHOD? labelSelectionOverride=null, DB_ITEM_SELECTION_METHOD? itemSelectionOverride=null, bool bResetFirst=false, IXDatabaseBase db=null, bool bUseDb=true, bool bCreateRunNet=true, string strStage=null, bool bEnableMemTrace=false)
Load a project and optionally the MyCaffeImageDatabase.
ResultCollection Run(SimpleDatum d, bool bSort=true, bool bUseSolverNet=false)
Run on a given Datum.
void Train(int nIterationOverride=-1, int nTrainingTimeLimitInMinutes=0, TRAIN_STEP step=TRAIN_STEP.NONE, double dfLearningRateOverride=0, bool bReset=false)
Train the network a set number of iterations and allow for single stepping.
DatasetDescriptor GetDataset()
Returns the current dataset used when training and testing.
bool Load(Phase phase, ProjectEx p, DB_LABEL_SELECTION_METHOD? labelSelectionOverride=null, DB_ITEM_SELECTION_METHOD? itemSelectionOverride=null, bool bResetFirst=false, IXDatabaseBase db=null, bool bUseDb=true, bool bCreateRunNet=true, string strStage=null, bool bEnableMemTrace=false)
Load a project and optionally the MyCaffeImageDatabase.
PropertySet TestMany(PropertySet customInput)
Runs test many on a set of custom input data.
List< Tuple< SimpleDatum, ResultCollection > > TestMany(int nCount, bool bOnTrainingSet, bool bOnTargetSet=false, DB_ITEM_SELECTION_METHOD imgSelMethod=DB_ITEM_SELECTION_METHOD.RANDOM, int nImageStartIdx=0, DateTime? dtImageStartTime=null, double? dfThreshold=null)
Test on a number of images by selecting random images from the database, running them through the Run...
Bitmap GetTestImage(Phase phase, out int nLabel, out string strLabel)
Retrieves a random image from either the training or test set depending on the Phase specified.
byte[] GetWeights()
Retrieves the weights of the training network.
Bitmap GetTestImage(Phase phase, int nLabel)
Retrieves a random image from either the training or test set depending on the Phase specified.
void UpdateWeights(byte[] rgWeights)
Loads the training Net with new weights.
double Test(int nIterationOverride=-1)
Test the network a given number of iterations.
ResultCollection Run(int nImageIdx, bool bPad=true)
Run on a given image in the MyCaffeImageDatabase based on its image index.
List< ResultCollection > Run(List< int > rgImageIdx)
Run on a set of images in the MyCaffeImageDatabase based on their image indexes.
string GetLicenseText(string strOtherLicenses)
Returns the license text for MyCaffe.
void UpdateRunWeights(bool bOutputStatus=false, bool bVerifyWeights=true)
Loads the weights from the training net into the Net used for running.
The IXMyCaffeNoDb interface contains functions used to perform MyCaffe operations that run in a light...
Definition: Interfaces.cs:564
ResultCollection Run(SimpleDatum d, bool bSort=true, bool bPad=true)
Run on a given Datum.
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).
Blob< T > CreateDataBlob(SimpleDatum d, Blob< T > blob=null, bool bPad=true)
Create a data blob from a SimpleDatum by transforming the data and placing the results in the blob re...
ResultCollection Run(Bitmap img, bool bSort=true, bool bPad=true)
Run on a given bitmap image.
The IXMyCaffeState interface contains functions related to the MyCaffeComponent state.
Definition: Interfaces.cs:258
string LabelQueryEpochs
Returns a string describing the label query epochs observed during training.
Definition: Interfaces.cs:359
IXPersist< T > Persist
Returns the persist used to load and save weights.
Definition: Interfaces.cs:325
ProjectEx CurrentProject
Returns the name of the currently loaded project.
Definition: Interfaces.cs:367
bool EnableBlobDebugging
Enable/disable blob debugging.
Definition: Interfaces.cs:295
string GetDeviceName(int nDeviceID)
Returns the device name of a given device ID.
int MaximumIteration
Returns the maximum iteration.
Definition: Interfaces.cs:375
void AddCancelOverride(CancelEvent evtCancel)
Add a cancel override.
void AddCancelOverrideByName(string strEvtCancel)
Add a cancel override.
void RemoveCancelOverrideByName(string strEvtCancel)
Remove a cancel override.
bool VerifyCompute(string strExtra=null, int nDeviceID=-1, bool bThrowException=true)
VerifyCompute compares the current compute of the current device (or device specified) against the re...
bool ReInitializeParameters(WEIGHT_TARGET target, params string[] rgstrLayers)
Re-initializes each of the specified layers by re-running the filler (if any) specified by the layer....
string CurrentDevice
Returns the name of the current device used.
Definition: Interfaces.cs:363
bool EnableLayerDebugging
Enable/disable layer debugging which causes each layer to check for NAN/INF on each forward/backward ...
Definition: Interfaces.cs:320
void RemoveCancelOverride(CancelEvent evtCancel)
Remove a cancel override.
int GetDeviceCount()
Returns the total number of devices installed on this computer.
bool EnableBreakOnFirstNaN
Enable/disable break training after first detecting a NaN.
Definition: Interfaces.cs:302
bool EnableDetailedNanDetection
When enabled (requires EnableBlobDebugging = true), the detailed Nan (and Infinity) detection is pero...
Definition: Interfaces.cs:306
string LabelQueryHitPercents
Returns a string describing the label query hit percentages observed during training.
Definition: Interfaces.cs:352
List< int > ActiveGpus
Returns a list of Active GPU's used by the control.
Definition: Interfaces.cs:338
int CurrentIteration
Returns the current iteration.
Definition: Interfaces.cs:371
string ActiveLabelCounts
Returns a string describing the active label counts observed during training.
Definition: Interfaces.cs:345
bool EnableSingleStep
Enable/disable single step training.
Definition: Interfaces.cs:313
void SetOnTestOverride(EventHandler< TestArgs > onTest)
Sets the root solver's onTest event function.
The IXPersist interface is used by the CaffeControl to load and save weights.
Definition: Interfaces.cs:187
BlobCollection< T > LoadWeights(byte[] rgWeights, List< string > rgExpectedShapes, BlobCollection< T > colBlobs, bool bSizeToFit, out bool bLoadedDiffs, List< string > inputWtInfo=null, List< string > targetWtInfo=null, string strSkipBlobType=null)
Loads new weights into a BlobCollection
SolverState LoadSolverState(byte[] rgState, SolverParameter.SolverType type=SolverParameter.SolverType.SGD)
Load the solver state from a byte array.
WeightInfo< T > LoadWeightInfo(BlobCollection< T > colBlobs)
Returns the weight information describing the weights containined within the Blob collection.
WeightInfo< T > LoadWeightInfo(byte[] rgWeights)
Returns the weight information describing the weights containined within the weight bytes.
byte[] SaveSolverState(SolverState state, SolverParameter.SolverType type=SolverParameter.SolverType.SGD)
Save the solver state to a byte array.
byte[] SaveWeights(BlobCollection< T > colBlobs, bool bSaveDiffs=false)
Save the weights to a byte array.
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
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
@ DATA
Specifies a data gym that collects data from a data source, such as a database.
@ NONE
No training category specified.
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
delegate void onSetWorkspace(object sender, WorkspaceArgs e)
Delegate used to set the OnSetworkspace event.
BLOB_TYPE
Defines the tpe of data held by a given Blob.
Definition: Interfaces.cs:62
@ ATTENTION
The blob contains attention scores.
@ MULTIBBOX
The blob holds multi-boundingbox data.
@ ACCURACY
The Blob holds Accuracy Data.
@ INTERNAL
The blob is an internal blob used within the layer.
@ UNKNOWN
The blob is an unknown type.
@ TARGET
The blob contains target data.
@ IP_WEIGHT
The Blob holds an inner product weight.
@ CLIP
The blob holds Clip data.
@ PREDICTION
The blob contains prediction data.
@ LOSS
The Blob holds Loss Data.
delegate void onGetWorkspace(object sender, WorkspaceArgs e)
Delegate used to set the OnGetworkspace event.
TRAIN_STEP
Defines the training stepping method (if any).
Definition: Interfaces.cs:131
@ BACKWARD
Step only in the backward direction.
@ FORWARD
Step only in the forward direction.
WEIGHT_TARGET
Defines the type of weight to target in re-initializations.
Definition: Interfaces.cs:38
@ BOTH
Both weights and bias are targeted.
@ BIAS
Bias weights are targeted.
@ WEIGHTS
Generic weights are targeted.
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
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