2using System.Collections.Generic;
32 int? m_nIgnoreLabel =
null;
51 m_blobProb =
new Blob<T>(cuda, log);
60 if (m_softmaxLayer !=
null)
61 m_softmaxLayer.Dispose();
106 base.LayerSetUp(colBottom, colTop);
117 m_colSoftmaxBottom.
Add(colBottom[0]);
118 m_colSoftmaxTop.
Add(m_blobProb);
119 m_softmaxLayer.Setup(m_colSoftmaxBottom, m_colSoftmaxTop);
131 base.Reshape(colBottom, colTop);
133 m_softmaxLayer.Reshape(m_colSoftmaxBottom, m_colSoftmaxTop);
135 m_nOuterNum = colBottom[0].count(0, m_nSoftmaxAxis);
136 m_nInnerNum = colBottom[0].count(m_nSoftmaxAxis + 1);
140 m_log.
CHECK_EQ(
m_nOuterNum *
m_nInnerNum, colBottom[1].count(),
"Number of labels must match number of predictions; e.g., if softmax axis == 1 and prediction shape is (N, C, H, W), label count (number of labels) must be N*H*W, with integer values in {0, 1, ..., C-1}.");
142 if (colTop.
Count >= 2)
170 m_softmaxLayer.Forward(m_colSoftmaxBottom, m_colSoftmaxTop);
172 long hProbData = m_blobProb.
gpu_data;
173 long hLabel = colBottom[1].gpu_data;
179 long hLossData = colBottom[0].mutable_gpu_diff;
186 T fLoss =
m_cuda.asum(nCount, hLossData);
187 double dfValidCount = -1;
196 double dfFinalLoss = dfLoss / dfNormalizer;
198 colTop[0].
SetData(dfFinalLoss, 0);
200 if (colTop.
Count == 2)
201 colTop[1].ShareData(m_blobProb);
239 if (!rgbPropagateDown[0])
242 long hBottomDiff = colBottom[0].mutable_gpu_diff;
243 long hProbData = m_blobProb.
gpu_data;
244 long hTopData = colTop[0].gpu_data;
246 m_cuda.copy(m_blobProb.
count(), hProbData, hBottomDiff);
248 long hLabel = colBottom[1].gpu_data;
258 double dfValidCount = -1;
265 double dfTopDiff =
convertD(colTop[0].GetDiff(0));
267 double dfLossWeight = dfTopDiff / dfNormalizer;
The Log class provides general output in text form.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
The BlobCollection contains a list of Blobs.
void Add(Blob< T > b)
Add a new Blob to the collection.
void SetData(double df)
Set all blob data to the value specified.
void SetDiff(double df)
Set all blob diff to the value specified.
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.
long mutable_gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
int count()
Returns the total number of items in the Blob.
string Name
Get/set the name of the Blob.
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
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.
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.
double convertD(T df)
Converts a generic to a double value.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
The LossLayer provides an interface for Layer's that take two blobs as input – usually (1) prediction...
bool m_bIgnoreLabels
Set to true when labels are to be ignored.
int m_nOuterNum
Specifies the outer num, such as the batch count (e.g. count(0, axis)). Each derivative class must se...
int m_nInnerNum
Specifies the inner num, such as the channel + height + width (e.g. count(axis + 1))....
virtual double get_normalizer(LossParameter.NormalizationMode normalization_mode, int nValidCount)
Returns the normalizer used to normalize the loss.
LossParameter.NormalizationMode m_normalization
Specifies the normalization mode used to normalize the loss.
The SoftmaxLayer computes the softmax function. This layer is initialized with the MyCaffe....
Computes the multinomial logistic loss for a one-of-many classification task, passing real-valued pre...
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
SoftmaxLossLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
Constructor.
override void dispose()
Releases all GPU and host resources used by the Layer.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the softmax loss error gradient w.r.t the predictions.
override int MaxTopBlobs
Returns the maximum number of required top (output) Blobs: loss, labels
override int MinTopBlobs
Returns the minimum number of required top (output) Blobs: loss.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs as variable.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
The forward computation.
Specifies the base parameter for all layers.
string name
Specifies the name of this LayerParameter.
List< double > loss_weight
Specifies the loss weight.
SoftmaxParameter softmax_param
Returns the parameter set when initialized with LayerType.SOFTMAX
void SetType(LayerType type, bool bNewParam=true)
Set the layer type.
LayerType
Specifies the layer type.
LossParameter loss_param
Returns the parameter set when initialized with LayerType.LOSS
virtual LayerParameter Clone(bool bCloneBlobs)
Creates a new copy of this instance of the parameter.
Stores the parameters used by loss layers.
NormalizationMode
How to normalize the loss for loss layers that aggregate across batches, spatial dimensions,...
int? ignore_label
If specified, the ignore instances with the given label.
Specifies the parameters for the SoftmaxLayer
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
int axis
The axis along which to perform the softmax – may be negative to index from the end (e....
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
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-...