2using System.Collections.Generic;
43 m_blobBiasMultiplier =
new Blob<T>(cuda, log);
44 m_blobBiasMultiplier.Name =
m_param.
name +
" bias_mult";
50 m_blobBiasMultiplier.Dispose();
60 col.
Add(m_blobBiasMultiplier);
94 base.ReInitializeParameters(target);
120 else if (colBottom.
Count == 1)
124 int nAxis = colBottom[0].CanonicalAxisIndex(p.
axis);
127 m_log.
CHECK_GE(nNumAxes, -1,
"num_axes must be non-negative, or -1 to extend to end of bottom[0].");
130 m_log.
CHECK_GE(colBottom[0].num_axes, nAxis + nNumAxes,
"bias blob's shape extends past bottom[0]'s shape when applied starting with bottom[0] axis = " + nAxis.ToString());
134 List<int> rgBiasShape =
new List<int>();
136 int nEnd = (nNumAxes == -1) ? colBottom[0].shape().
Count : nStart + nNumAxes;
138 for (
int i = nStart; i < nEnd; i++)
140 rgBiasShape.Add(colBottom[0].shape(i));
156 filler.
Fill(blobBias);
178 int nAxis = (blobBias.
num_axes == 0) ? 0 : colBottom[0].CanonicalAxisIndex(p.
axis);
180 m_log.
CHECK_GE(colBottom[0].num_axes, nAxis + blobBias.
num_axes,
"bias blob's shape extends past bottom[0]'s shape when applied starting with bottom[0] axis = " + nAxis.ToString());
182 for (
int i = 0; i < blobBias.
num_axes; i++)
184 m_log.
CHECK_EQ(colBottom[0].shape(nAxis + i), blobBias.
shape(i),
"dimension mismatch between bottom[0]->shape(" + (nAxis + i).ToString() +
") and bias->shape(" + i.ToString() +
")");
187 m_nOuterDim = colBottom[0].count(0, nAxis);
188 m_nBiasDim = blobBias.
count();
189 m_nInnerDim = colBottom[0].count(nAxis + blobBias.
num_axes);
190 m_nDim = m_nBiasDim * m_nInnerDim;
192 if (colBottom[0] != colTop[0])
195 m_blobBiasMultiplier.Reshape(
new List<int>() { m_nInnerDim });
196 m_blobBiasMultiplier.SetData(1.0);
206 int nCount = colTop[0].count();
207 long hBottomData = colBottom[0].gpu_data;
208 long hBiasData = ((colBottom.
Count > 1) ? colBottom[1].gpu_data :
m_colBlobs[0].gpu_data);
209 long hTopData = colTop[0].mutable_gpu_data;
211 m_cuda.bias_fwd(nCount, hBottomData, hBiasData, m_nBiasDim, m_nInnerDim, hTopData);
222 if (rgbPropagateDown[0] && colBottom[0] != colTop[0])
224 long hTopDiff = colTop[0].gpu_diff;
225 long hBottomDiff = colBottom[0].mutable_gpu_diff;
226 int nCount = colBottom[0].count();
228 m_cuda.copy(nCount, hTopDiff, hBottomDiff);
232 bool bBiasParam = (colBottom.
Count == 1) ?
true :
false;
236 long hTopDiff = colTop[0].gpu_diff;
237 long hBiasDiff = (bBiasParam) ?
m_colBlobs[0].mutable_gpu_diff : colBottom[1].mutable_gpu_diff;
238 double dfAccum = (bBiasParam) ? 1.0 : 0.0;
239 int nTopDiffOffset = 0;
241 for (
int n = 0; n < m_nOuterDim; n++)
243 m_cuda.gemv(
false, m_nBiasDim, m_nInnerDim,
m_tOne, hTopDiff, m_blobBiasMultiplier.gpu_data,
convert(dfAccum), hBiasDiff, nTopDiffOffset);
244 nTopDiffOffset += m_nDim;
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.
void CHECK_GE(double df1, double df2, string str)
Test whether one number is greater than or equal to another.
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 ReshapeLike(BlobCollection< T > src)
Reshapes all blobs in the collection to the sizes of the source.
The Blob is the main holder of data that moves through the Layers of the Net.
int num_axes
Returns the number of axes in the Blob.
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.
List< int > shape()
Returns an array where each element contains the shape of an axis of the Blob.
int count()
Returns the total number of items in the Blob.
string Name
Get/set the name of the Blob.
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 BiasLayer computes a sum of two input Blobs, with the shape of the latter Blob 'broadcast' to mat...
BiasLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The BiasLayer constructor.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
The Forward computation.
override void dispose()
Releases all GPU and host resources used by the Layer.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: bias
override bool ReInitializeParameters(WEIGHT_TARGET target)
Re-initialize the parameters of the layer.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
override int MaxBottomBlobs
Returns the maximum number of required bottom (input) Blobs: input1, input2
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t. the input.
override int MinBottomBlobs
Returns the minimum number of required bottom (input) Blobs: input1
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.
void convert(BlobCollection< T > col)
Convert a collection of blobs from / to half size.
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...
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 parameters for the BiasLayer
int axis
The first axis of bottom[0] (the first input Blob) along which to apply bottom[1] (the second input B...
int num_axes
(num_axes is ignored unless just one bottom is given and the bias is a learned parameter of the layer...
FillerParameter filler
(filler is ignored unless just one bottom is given and the bias is a learned parameter of the layer....
Specifies the filler parameters used to create each Filler.
Specifies the base parameter for all layers.
string name
Specifies the name of this LayerParameter.
BiasParameter bias_param
Returns the parameter set when initialized with LayerType.BIAS
LayerType
Specifies the layer type.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
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-...