2using System.Collections.Generic;
29 bool m_bEnableNoise =
false;
30 double m_dfSigmaInit = 0;
31 Blob<T> m_blobEpsilonWeight =
null;
32 Blob<T> m_blobEpsilonBias =
null;
34 double m_dfBiasGradScale = 1.0;
58 m_blobBiasMultiplier =
new Blob<T>(cuda, log);
63 m_blobEpsilonWeight =
new Blob<T>(cuda, log);
68 m_blobEpsilonBias =
new Blob<T>(cuda, log);
79 dispose(ref m_blobBiasMultiplier);
80 dispose(ref m_blobEpsilonWeight);
93 col.
Add(m_blobBiasMultiplier);
95 if (m_blobEpsilonWeight !=
null)
96 col.
Add(m_blobEpsilonWeight);
98 if (m_blobEpsilonBias !=
null)
99 col.
Add(m_blobEpsilonBias);
136 base.ReInitializeParameters(target);
160 if (colBottom.
Count > 1)
171 List<int> rgShape = colBottom[0].shape();
172 int nShapeCount = rgShape.
Count;
178 if (nShapeCount != rgShape.Count)
186 m_nK = colBottom[0].count(nAxis);
200 rgWeightShape[0] = m_nK;
201 rgWeightShape[1] = m_nN;
205 rgWeightShape[0] = m_nN;
206 rgWeightShape[1] = m_nK;
209 double dfNoiseRange = 1.0 / Math.Sqrt(rgWeightShape[1]);
216 blobWeight.
Reshape(rgWeightShape);
218 weight_filler.
Fill(blobWeight);
235 blobBias.Reshape(rgBiasShape);
237 bias_filler.
Fill(blobBias);
240 blobBias.scale_data(dfNoiseRange);
257 blobSigmaWeight.
SetData(m_dfSigmaInit / Math.Sqrt(blobSigmaWeight.
shape(1)));
267 blobSigmaBias.
SetData(m_dfSigmaInit / Math.Sqrt(blobSigmaBias.
shape(0)));
286 List<int> rgShape =
new List<int>(colBottom[0].shape());
297 int nNewK = colBottom[0].count(nAxis);
299 m_log.
CHECK_EQ(m_nK, nNewK,
"Input size incompatible with inner product parameters.");
303 m_nM = colBottom[0].count(0, nAxis);
307 List<int> rgTopShape =
Utility.Clone<
int>(colBottom[0].shape(), nAxis + 1);
308 rgTopShape[nAxis] = m_nN;
324 m_blobBiasMultiplier.
Reshape(rgBiasShape);
325 m_blobBiasMultiplier.
SetData(1.0);
337 m_fillerEpsilon.
Fill(m_blobEpsilonWeight);
342 m_fillerEpsilon.
Fill(m_blobEpsilonBias);
360 long hBottomData = colBottom[0].gpu_data;
361 long hTopData = colTop[0].mutable_gpu_data;
363 long hBias = (m_bBiasTerm) ?
m_colBlobs[1].gpu_data : 0;
371 hWeight = m_blobEpsilonWeight.
gpu_diff;
388 m_cuda.axpy(m_nN, m_blobBiasMultiplier.
GetData(0), hBias, hTopData);
392 m_cuda.gemm(
false, (m_bTranspose) ? false :
true, m_nM, m_nN, m_nK,
m_tOne, hBottomData, hWeight,
m_tZero, hTopData);
412 long hTopDiff = colTop[0].gpu_diff;
417 long hBottomData = colBottom[0].gpu_data;
428 if (m_dfBiasGradScale != 1)
429 m_blobBiasMultiplier.
scale_data(m_dfBiasGradScale);
433 if (m_dfBiasGradScale != 1)
435 double dfUnScale = 1.0 / m_dfBiasGradScale;
442 if (rgbPropagateDown[0])
The Log class provides general output in text form.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
The Utility class provides general utility funtions.
static List< int > Create(int nCount, int nStart, int nInc)
Create a new List and fill it with values starting with start and incrementing by inc.
The BlobCollection contains a list of Blobs.
void Add(Blob< T > b)
Add a new Blob to the collection.
int Count
Returns the number of items in the collection.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
The Blob is the main holder of data that moves through the Layers of the Net.
void SetData(T[] rgData, int nCount=-1, bool bSetCount=true)
Sets a number of items within the Blob's data.
long mutable_gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
BLOB_TYPE type
Returns the BLOB_TYPE of the Blob.
void scale_data(double df)
Scale the data by a scaling factor.
List< int > shape()
Returns an array where each element contains the shape of an axis of the Blob.
T GetData(int nIdx)
Returns the data at a given flat index within the Blob.
void ReshapeLike(Blob< T > b, bool? bUseHalfSize=null)
Reshape this Blob to have the same shape as another Blob.
string Name
Get/set the name of the Blob.
long gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
long gpu_data
Returns the data GPU handle used by the CudaDnn connection.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
Abstract Filler class used to fill blobs with values.
void Fill(Blob< T > b)
Fill the blob with values based on the actual filler used.
static Filler< T > Create(CudaDnn< T > cuda, Log log, FillerParameter p)
Create a new Filler instance.
The InnerProductLayer, also know as a 'fully-connected' layer, computes the inner product with a set ...
override int MaxBottomBlobs
Returns the exact number of required bottom (input) Blobs: input, num_output.
override void dispose()
Releases all GPU and host resources used by the Layer.
override bool ReInitializeParameters(WEIGHT_TARGET target)
Re-initialize the parameters of the layer.
override int MinBottomBlobs
Returns the exact number of required bottom (input) Blobs: input.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: ip
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
The forward computation.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the inner product loss error gradient w.r.t the outputs.
void ResetNoise()
Resample the noise for both weights and bias (if used).
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
InnerProductLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The InnerProductLayer constructor.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
An interface for the units of computation which can be composed into a Net.
Log m_log
Specifies the Log for output.
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
T m_tZero
Specifies a generic type equal to 0.0.
T m_tOne
Specifies a generic type equal to 1.0.
bool shareParameter(Blob< T > b, List< int > rgMinShape, bool bAllowEndsWithComparison=false)
Attempts to share a parameter Blob if another parameter Blob with the same name and accpetable size i...
float convertF(T df)
Converts a generic to a float value.
BlobCollection< T > m_colInternalBlobs
Specifies internal blobs used by the layer.
Phase m_phase
Specifies the Phase under which the Layer is run.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
BlobCollection< T > m_colBlobs
Specifies the learnable parameter Blobs of the Layer.
DictionaryMap< bool > m_rgbParamPropagateDown
Specifies whether or not to compute the learnable diff of each parameter Blob.
Specifies the filler parameters used to create each Filler.
double min
Specifies the minimum value to use with the 'uniform' filler.
double max
Specifies the maximum value to use with the 'uniform' filler.
double sigma_init
Specifies the initialization value for the sigma weight and sigma bias used when 'enable_noise' = tru...
FillerParameter weight_filler
The filler for the weights.
int axis
Specifies the first axis to be lumped into a single inner product computation; all preceding axes are...
bool enable_noise
Enable/disable noise in the inner-product layer (default = false).
double bias_grad_scale
Specifies a scaling value applied to the bias mutliplier and then unapplied after calculating the bia...
int min_top_axes
Optionally, specifies the minimum top axes (default = -1, which ignores this setting).
bool transpose
Specifies whether to transpose the weight matrix or not. If transpose == true, any operations will be...
FillerParameter bias_filler
The filler for the bias.
uint num_output
The number of outputs for the layer.
bool output_contains_predictions
Specifies that the output contains predictions and that the output blob is marked as BLOB_TYPE....
bool bias_term
Whether to have bias terms or not.
Specifies the base parameter for all layers.
string name
Specifies the name of this LayerParameter.
InnerProductParameter inner_product_param
Returns the parameter set when initialized with LayerType.INNERPRODUCT
LayerType
Specifies the layer type.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Phase
Defines the Phase under which to run a Net.
The MyCaffe.common namespace contains common MyCaffe classes.
BLOB_TYPE
Defines the tpe of data held by a given Blob.
WEIGHT_TARGET
Defines the type of weight to target in re-initializations.
The MyCaffe.fillers namespace contains all fillers including the Filler class.
The MyCaffe.layers namespace contains all layers that have a solidified code base,...
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-...