2using System.Collections.Generic;
35 double m_dfLowerBound;
36 double m_dfUpperBound;
40 Stopwatch m_swOutput =
new Stopwatch();
70 base.LayerSetUp(colBottom, colTop);
76 m_log.
CHECK(args !=
null,
"WARNING: The OnGetIteration event is not connected!");
84 m_log.
CHECK_LE(m_dfLowerBound, m_dfUpperBound,
"The lower bound must be <= the upper bound.");
85 m_log.
CHECK_GE(m_dfAlpha, 0,
"The alpha value must be >= 0.0");
88 int nIteration = (args ==
null) ? 1 : args.
Iteration;
89 double dfProgress = Math.Min(1.0, (
double)nIteration / m_dfMaxIter);
90 double dfHeight = m_dfUpperBound - m_dfLowerBound;
92 m_dfCoeff = 2.0 * dfHeight / (1.0 + Math.Exp(-m_dfAlpha * dfProgress)) - dfHeight + m_dfLowerBound;
93 m_log.
WriteLine(
"iter = " + nIteration.ToString() +
" progress = " + dfProgress.ToString() +
" coeff = " + m_dfCoeff.ToString());
106 colTop[0].ShareData(colBottom[0]);
120 if (!rgbPropagateDown[0])
127 int nCount = colTop[0].count();
128 long hTopDiff = colTop[0].gpu_diff;
129 long hBottomDiff = colBottom[0].mutable_gpu_diff;
131 int nIteration = (args ==
null) ? 1 : args.
Iteration;
132 double dfProgress = Math.Min(1.0, (
double)nIteration / m_dfMaxIter);
133 double dfHeight = m_dfUpperBound - m_dfLowerBound;
135 m_dfCoeff = 2.0 * dfHeight / (1.0 + Math.Exp(-m_dfAlpha * dfProgress)) - dfHeight + m_dfLowerBound;
137 if (m_swOutput.Elapsed.TotalMilliseconds > 1000)
139 m_log.
WriteLine(
"iter = " + nIteration.ToString() +
" progress = " + dfProgress.ToString() +
" coeff = " + m_dfCoeff.ToString());
140 m_swOutput.Restart();
143 m_cuda.scale(nCount, -m_dfCoeff, hTopDiff, hBottomDiff);
The Log class provides general output in text form.
void CHECK(bool b, string str)
Test a flag for true.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void CHECK_LE(double df1, double df2, string str)
Test whether one number is less than or 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.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
The GetIterationArgs is sent bubbled up to the solver when a layer needs to know the curret training ...
int Iteration
Returns the iteration.
Phase CurrentPhase
Returns the phase.
The GradientScaleLayer which scales the deltas during the backpropagation. This layer is initialized ...
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
GradientScaleLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The GradientScaleLayer constructor.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Scales the error gradient w.r.t. the GRADIENTSCALER value inputs.
Log m_log
Specifies the Log for output.
GetIterationArgs getCurrentIteration()
Fires the OnGetIteration event to query the current iteration.
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
LayerParameter.LayerType m_type
Specifies the Layer type.
The NeuronLayer is an interface for layers that take one blob as input (x) and produce only equally-s...
double lower_bound
Specifies the lower bound of the height used for scaling.
double alpha
Specifies the alpha value applied to the current iter/max_iter, used when scaling.
double max_iter
Specifies the maximum iteration used when scaling.
double upper_bound
Specifies the upper bound of the height used for scaling.
Specifies the base parameter for all layers.
GradientScaleParameter gradient_scale_param
Returns the parameter set when initialized with LayerType.GSL
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.
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-...