2using System.Collections.Generic;
24 double m_dfInputScale;
25 double m_dfInputShift;
26 double m_dfBackwardNumScale;
53 base.LayerSetUp(colBottom, colTop);
58 m_log.
CHECK_GT(dfBase, 0,
"base_val must be strictly positive.");
62 double dfLogBase = (dfBase == -1) ? 1 : Math.Log(dfBase);
64 m_log.
CHECK(!
double.IsNaN(dfLogBase),
"NaN result: log(base) == log(" + dfBase.ToString() +
") = " + dfLogBase.ToString());
65 m_log.
CHECK(!
double.IsInfinity(dfLogBase),
"Inf result: log(base) == log(" + dfBase.ToString() +
") = " + dfLogBase.ToString());
67 m_dfBaseScale = 1.0 / dfLogBase;
69 m_log.
CHECK(!
double.IsNaN(m_dfBaseScale),
"NaN result: 1/log(base) == 1/log(" + dfBase.ToString() +
") = " + m_dfBaseScale.ToString());
70 m_log.
CHECK(!
double.IsInfinity(m_dfBaseScale),
"Inf result: 1/log(base) == 1/log(" + dfBase.ToString() +
") = " + m_dfBaseScale.ToString());
74 m_dfBackwardNumScale = m_dfInputScale / dfLogBase;
88 int nCount = colBottom[0].count();
89 long hBottomData = colBottom[0].gpu_data;
90 long hTopData = colTop[0].mutable_gpu_data;
92 if (m_dfInputScale == 1.0 && m_dfInputShift == 0)
94 m_cuda.log(nCount, hBottomData, hTopData);
98 m_cuda.copy(nCount, hBottomData, hTopData);
100 if (m_dfInputScale != 1)
103 if (m_dfInputShift != 0)
104 m_cuda.add_scalar(nCount,
convert(m_dfInputShift), hTopData);
106 m_cuda.log(nCount, hTopData, hTopData);
109 if (m_dfBaseScale != 1)
125 if (!rgbPropagateDown[0])
128 int nCount = colBottom[0].count();
129 long hBottomData = colBottom[0].gpu_data;
130 long hTopDiff = colTop[0].gpu_diff;
131 long hBottomDiff = colBottom[0].mutable_gpu_diff;
133 m_cuda.copy(nCount, hBottomData, hBottomDiff);
135 if (m_dfInputScale != 1.0)
138 if (m_dfInputShift != 0)
139 m_cuda.add_scalar(nCount,
convert(m_dfInputShift), hBottomDiff);
141 m_cuda.powx(nCount, hBottomDiff,
convert(-1.0), hBottomDiff);
143 if (m_dfBackwardNumScale != 1.0)
144 m_cuda.scal(nCount,
convert(m_dfBackwardNumScale), hBottomDiff);
146 m_cuda.mul(nCount, hTopDiff, hBottomDiff, hBottomDiff);
The Log class provides general output in text form.
void CHECK(bool b, string str)
Test a flag for true.
void CHECK_GT(double df1, double df2, string str)
Test whether one number is greater than another.
The BlobCollection contains a list of Blobs.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
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.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
The LogLayer computes the log of the input. This layer is initialized with the MyCaffe....
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 error gradient w.r.t. the LOG value inputs.
LogLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The LogLayer constructor.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
The NeuronLayer is an interface for layers that take one blob as input (x) and produce only equally-s...
Specifies the base parameter for all layers.
LogParameter log_param
Returns the parameter set when initialized with LayerType.LOG
LayerType
Specifies the layer type.
double shift
Specifies the shift to use for the log, where , for base > 0.
double base_val
Specifies the base to use for the log, where , for base > 0.
double scale
Specifies the scale to use for the log, where , for base > 0.
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-...