2using System.Collections.Generic;
24 float m_fLastAverage = 0;
25 Dictionary<float, List<float>> m_rgAccuracies =
new Dictionary<float, List<float>>();
26 Dictionary<float, List<float>> m_rgAcccuracyAverages =
new Dictionary<float, List<float>>();
27 Dictionary<float, int> m_rgWithinTargetCounts;
76 int nN = colBottom[0].num;
77 int nC = colBottom[0].channels;
78 m_log.
CHECK_EQ(colBottom[0].height, 3,
"Currently, the Quantile Accuracy Layer only supports 3 quantile predictions (upper, center, lower).");
80 m_rgWithinTargetCounts =
new Dictionary<float, int>(nC);
84 m_rgAccuracies.Add(fRange,
new List<float>(nN));
86 m_rgWithinTargetCounts.Add(fRange, 0);
97 List<int> rgShape =
new List<int>() { 1 };
99 foreach (
Blob<T> blobTop
in colTop)
118 int nN = colBottom[0].num;
119 int nC = colBottom[0].channels;
120 int nQ = colBottom[0].height;
121 float[] rgX =
convertF(colBottom[0].update_cpu_data());
122 float[] rgTgt =
convertF(colBottom[1].update_cpu_data());
125 throw new Exception(
"There should only be 3 quantile predictions (upper, center, lower).");
127 foreach (KeyValuePair<
float, List<float>> kv
in m_rgAccuracies)
132 for (
int i = 0; i < nN; i++)
136 m_rgWithinTargetCounts[fRange] = 0;
139 for (
int c = 0; c < nC; c++)
141 int nIdx = i * nC * nQ + c * nQ;
142 float fUpper = rgX[nIdx + 2];
143 float fCenter = rgX[nIdx + 1];
144 float fLower = rgX[nIdx];
146 float fUpperRange = Math.Abs(fUpper - fCenter);
147 float fLowerRange = Math.Abs(fCenter - fLower);
153 float fTarget = rgTgt[i * nC + c];
155 if (fTarget <= fUpperTarget && fTarget >= fLowerTarget)
160 foreach (KeyValuePair<float, int> kvp
in m_rgWithinTargetCounts)
162 float fAccuracy = (float)kvp.Value / nC;
163 m_rgAccuracies[kvp.Key].Add(fAccuracy);
168 foreach (KeyValuePair<
float, List<float>> kvp
in m_rgAccuracies)
170 float fAccuracy = kvp.Value.Average();
172 m_rgAcccuracyAverages[kvp.Key].Add(fAccuracy);
174 m_rgAcccuracyAverages[kvp.Key].RemoveAt(0);
177 foreach (KeyValuePair<
float, List<float>> kvp
in m_rgAcccuracyAverages)
180 colTop[nIdx1].SetData(fAveAccuracy);
185 private float average(List<float> rg, uint nN)
189 else if (rg.Count == 1)
190 m_fLastAverage = rg[0];
191 else if (rg.Count < nN)
193 m_fLastAverage = (((float)nN - 1) / (float)nN) * m_fLastAverage;
194 m_fLastAverage += (1.0f / (float)nN) * rg[rg.Count - 1];
198 m_fLastAverage = rg.Average();
201 return m_fLastAverage;
207 if (rgbPropagateDown[0])
208 throw new NotImplementedException();
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.
int Count
Returns the number of items in the collection.
The Blob is the main holder of data that moves through the Layers of the Net.
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
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.
float convertF(T df)
Converts a generic to a float value.
LayerParameter.LayerType m_type
Specifies the Layer type.
The QuantileAccuracyLayer implements the Quantile Accuracy Layer used in TFT models.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the top (output) blobs.
override void setup_internal_blobs(BlobCollection< T > col)
Derivative layers should add all internal blobws to the 'col' provided.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Not implemented – AccuracyLayer cannot be used as a loss.
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: x, target
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: one per accuracy range, each containing an a...
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
QuantileAccuracyLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The constructor.
override void dispose()
Releases all GPU and host resources used by the Layer.
Specifies the base parameter for all layers.
QuantileAccuracyParameter quantile_accuracy_param
Returns the parameter set when initialized with LayerType.QUANTILE_ACCURACY
LayerType
Specifies the layer type.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.layers.tft namespace contains all TFT related layers.
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-...