MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffe.common.PersistCaffe< T > Class Template Reference

The PersistCaffe class is used to load and save weight files in the .caffemodel format. More...

Inheritance diagram for MyCaffe.common.PersistCaffe< T >:
MyCaffe.common.IXPersist< T >

Public Member Functions

 PersistCaffe (Log log, bool bFailOnFirstTry)
 The PersistCaffe constructor. More...
 
bool IsMyCaffe (byte[] rgWeights, out string strVer)
 This method returns whether or not the weights have been marked as 'mycaffe.ai'. More...
 
byte[] SaveSolverState (SolverState state, SolverParameter.SolverType type=SolverParameter.SolverType.SGD)
 Save the solver state to a byte array. More...
 
SolverState LoadSolverState (byte[] rgState, SolverParameter.SolverType type=SolverParameter.SolverType.SGD)
 Load the solver state from a byte array. More...
 
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 More...
 
WeightInfo< T > LoadWeightInfo (byte[] rgWeights)
 Returns the weight information describing the weights containined within the weight bytes. More...
 
WeightInfo< T > LoadWeightInfo (BlobCollection< T > colBlobs)
 Returns the weight information describing the weights containined within the Blob collection. More...
 
byte[] SaveWeights (BlobCollection< T > colBlobs, bool bSaveDiffs=false)
 Save the weights to a byte array. More...
 
BlobProto LoadBlobProto (byte[] rg, int nFieldId)
 The LoadBlobProto function loads a BlobProto from a proto buffer. More...
 
BlobProto LoadBlobProto (string strFile, int nFieldId)
 The LoadBlobProto function loads a BlobProto from a file. More...
 

Properties

string MyCaffeTag [get]
 This tag is used to mark the ending section of each weighting file with 'MyCaffe' specific information. More...
 

Detailed Description

The PersistCaffe class is used to load and save weight files in the .caffemodel format.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.

Definition at line 19 of file PersistCaffe.cs.

Constructor & Destructor Documentation

◆ PersistCaffe()

MyCaffe.common.PersistCaffe< T >.PersistCaffe ( Log  log,
bool  bFailOnFirstTry 
)

The PersistCaffe constructor.

Parameters
logSpecifies the log used for output.
bFailOnFirstTrySpecifies whether or not to try to load the weights file. On the first try the Caffe model format is attempted, and on the second the MyCaffe format is used.

Definition at line 30 of file PersistCaffe.cs.

Member Function Documentation

◆ IsMyCaffe()

bool MyCaffe.common.PersistCaffe< T >.IsMyCaffe ( byte[]  rgWeights,
out string  strVer 
)

This method returns whether or not the weights have been marked as 'mycaffe.ai'.

Parameters
rgWeightsSpecifies the weights.
strVerReturns the version of this file.
Returns
If the weights contain mycaffe weights, true is returned, false otherwise.

Definition at line 51 of file PersistCaffe.cs.

◆ LoadBlobProto() [1/2]

BlobProto MyCaffe.common.PersistCaffe< T >.LoadBlobProto ( byte[]  rg,
int  nFieldId 
)

The LoadBlobProto function loads a BlobProto from a proto buffer.

Parameters
rgSpecifies the bytes containing the BlobProto in proto buffer format.
nFieldIdSpecifies the field ID to use for the BlobProto.
Returns
The new BlobProt is returned.

Definition at line 353 of file PersistCaffe.cs.

◆ LoadBlobProto() [2/2]

BlobProto MyCaffe.common.PersistCaffe< T >.LoadBlobProto ( string  strFile,
int  nFieldId 
)

The LoadBlobProto function loads a BlobProto from a file.

Parameters
strFileSpecifies the binary file containing the blob proto.
nFieldIdSpecifies the field ID to use for the BlobProto.
Returns
The new BlobProt is returned.

Definition at line 450 of file PersistCaffe.cs.

◆ LoadSolverState()

SolverState MyCaffe.common.PersistCaffe< T >.LoadSolverState ( byte[]  rgState,
SolverParameter.SolverType  type = SolverParameter.SolverType.SGD 
)

Load the solver state from a byte array.

Parameters
rgStateSpecifies the byte array containing the solver state.
typeSpecifies the solver type.
Returns
The SolverState loaded is returned.

Implements MyCaffe.common.IXPersist< T >.

Definition at line 116 of file PersistCaffe.cs.

◆ LoadWeightInfo() [1/2]

WeightInfo< T > MyCaffe.common.PersistCaffe< T >.LoadWeightInfo ( BlobCollection< T >  colBlobs)

Returns the weight information describing the weights containined within the Blob collection.

Parameters
colBlobsSpecifies the Blob collection containing the weights.
Returns
The weight information is returned.

Implements MyCaffe.common.IXPersist< T >.

Definition at line 267 of file PersistCaffe.cs.

◆ LoadWeightInfo() [2/2]

WeightInfo< T > MyCaffe.common.PersistCaffe< T >.LoadWeightInfo ( byte[]  rgWeights)

Returns the weight information describing the weights containined within the weight bytes.

Parameters
rgWeightsSpecifies the bytes containing the weights.
Returns
The weight information is returned.

Implements MyCaffe.common.IXPersist< T >.

Definition at line 252 of file PersistCaffe.cs.

◆ LoadWeights()

BlobCollection< T > MyCaffe.common.PersistCaffe< 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

NOTE: In order to maintain compatibility with the C++ Caffe, extra MyCaffe features may be added to the end of the weight file. After saving weights (see SaveWeights) in the format used by the C++ Caffe, MyCaffe writes the bytes "mycaffe.ai". All information after these bytes are specific to MyCaffe and allow for loading weights for models by Blob name and shape and loosen the C++ Caffe requirement that the 'number' of blobs match. Adding this functionality allows for training model, changing the model structure, and then re-using the trained weights in the new model.

Parameters
rgWeightsSpecifies the weights themselves.
rgExpectedShapesSpecifies a list of expected shapes for each Blob where the weights are to be loaded.
colBlobsSpecifies the Blobs to load with the weights.
bSizeToFitSpecifies wether or not the weights should be re-sized. Note: resizing can render the weights useless, especially in deeper, layers.
bLoadedDiffsReturns whether or not the diffs were loaded.
inputWtInfoOptionally, specifies the weight info describing the input weight blobs to import by name. Note when used the number of blobs must match the number of targetWtInfo blobs. Otherwise, when null this parameter is ignored.
targetWtInfoOptionally, specifies the weight info describing the target weight blobs to import by name. Note when used the number of blobs must match the number of inputWtInfo blobs. Otherwise, when null this parameter is ignored.
strSkipBlobTypeOptionally, specifies a blob type where weights are NOT loaded. See Blob.BLOB_TYPE for the types of Blobs.
Returns
The collection of Blobs with newly loaded weights is returned.

Implements MyCaffe.common.IXPersist< T >.

Definition at line 209 of file PersistCaffe.cs.

◆ SaveSolverState()

byte[] MyCaffe.common.PersistCaffe< T >.SaveSolverState ( SolverState  state,
SolverParameter.SolverType  type = SolverParameter.SolverType.SGD 
)

Save the solver state to a byte array.

Parameters
stateSpecifies the solver state to save.
typeSpecifies the solver type.
Returns
A byte array containing the solver state is returned.

Implements MyCaffe.common.IXPersist< T >.

Definition at line 75 of file PersistCaffe.cs.

◆ SaveWeights()

byte[] MyCaffe.common.PersistCaffe< T >.SaveWeights ( BlobCollection< T >  colBlobs,
bool  bSaveDiffs = false 
)

Save the weights to a byte array.

NOTE: In order to maintain compatibility with the C++ Caffe, extra MyCaffe features may be added to the end of the weight file. After saving weights in the format used by the C++ Caffe, MyCaffe writes the bytes "mycaffe.ai". All information after these bytes are specific to MyCaffe and allow for loading weights for models by Blob name and shape and loosen the C++ Caffe requirement that the 'number' of blobs match. Adding this functionality allows for training model, changing the model structure, and then re-using the trained weights in the new model.

Parameters
colBlobsSpecifies the Blobs to save with the weights.
bSaveDiffsOptionally, specifies to save the diff values - currently this parameter is not used.
Returns
The byte array containing the weights is returned.

Implements MyCaffe.common.IXPersist< T >.

Definition at line 291 of file PersistCaffe.cs.

Property Documentation

◆ MyCaffeTag

string MyCaffe.common.PersistCaffe< T >.MyCaffeTag
get

This tag is used to mark the ending section of each weighting file with 'MyCaffe' specific information.

Definition at line 40 of file PersistCaffe.cs.


The documentation for this class was generated from the following file: