2using System.Collections.Generic;
39 int m_nUnPooledHeight;
41 bool m_bGlobalPooling;
127 m_log.
CHECK(((p.
pad.Count > 0) && p.
pad_h.HasValue && p.
pad_w.HasValue) || (!p.
pad_h.HasValue && !p.
pad_w.HasValue),
"Pad is pad or pad_h and pad_w are required.");
134 if (m_bGlobalPooling)
136 m_nKernelH = colBottom[0].height;
137 m_nKernelW = colBottom[0].width;
153 m_log.
CHECK_GT(m_nKernelH, 0,
"Filter dimensions cannot be zero.");
154 m_log.
CHECK_GT(m_nKernelW, 0,
"Filter dimensions cannot be zero.");
161 m_nPadH = (int)p.
pad[0];
162 m_nPadW = (
int)p.
pad[0];
166 m_nPadH = (p.
pad_h.HasValue) ? (
int)p.
pad_h.Value : 0;
167 m_nPadW = (p.
pad_w.HasValue) ? (
int)p.
pad_w.Value : 0;
175 m_nStrideH = (int)p.
stride[0];
176 m_nStrideW = (
int)p.
stride[0];
184 if (m_bGlobalPooling)
185 m_log.
CHECK(m_nPadH == 0 && m_nPadW == 0 && m_nStrideH == 1 && m_nStrideW == 1,
"With global pooling = true, only pad = 0 and stride = 1 allowed.");
187 if (m_nPadH != 0 || m_nPadW != 0)
191 m_log.
CHECK_LT(m_nPadH, m_nKernelH,
"The pad_h must be <= kernel_h.");
192 m_log.
CHECK_LT(m_nPadW, m_nKernelW,
"The pad_w must be <= kernel_w.");
203 m_log.
CHECK_EQ(4, colBottom[0].num_axes,
"Input must have 4 axes, corresponding to (num, channels, height, width)");
205 m_nChannels = colBottom[0].channels;
206 m_nHeight = colBottom[0].height;
207 m_nWidth = colBottom[0].width;
209 if (m_bGlobalPooling)
211 m_nKernelH = colBottom[0].height;
212 m_nKernelW = colBottom[0].width;
222 m_nUnPooledHeight = Math.Max((m_nHeight - 1) * m_nStrideH + m_nKernelH - 2 * m_nPadH,
223 m_nHeight * m_nStrideH - m_nPadH + 1);
224 m_nUnPooledWidth = Math.Max((m_nWidth - 1) * m_nStrideW + m_nKernelW - 2 * m_nPadW,
225 m_nWidth * m_nStrideW - m_nPadW + 1);
227 if (m_nUnPooledHeight <= 0)
229 m_nUnPooledHeight = 1;
230 m_log.
WriteLine(
"WARNING: unpooling height was 0, setting to 1.");
233 if (m_nUnPooledWidth <= 0)
235 m_nUnPooledWidth = 1;
239 colTop[0].
Reshape(colBottom[0].num, m_nChannels, m_nUnPooledHeight, m_nUnPooledWidth);
253 T[] bottom_data = colBottom[0].update_cpu_data();
256 if (colBottom.
Count > 1)
257 mask = colBottom[1].update_cpu_data();
259 T[] top_data = colTop[0].mutable_cpu_data;
260 int nBottomDataOffset = 0;
261 int nTopDataOffset = 0;
268 for (
int n = 0; n < colBottom[0].num; n++)
270 for (
int c = 0; c < m_nChannels; c++)
272 for (
int ph = 0; ph < m_nHeight; ph++)
274 for (
int pw = 0; pw < m_nWidth; pw++)
276 int nIdx = ph * m_nWidth + pw;
279#warning TODO: Bug - nMaskOffset + nIdx exceed length on last row of mask.
280 if (mask !=
null && nMaskOffset + nIdx < mask.Length)
281 nTopIdx = (int)Convert.ChangeType(mask[nMaskOffset + nIdx], typeof(
int));
283#warning TODO: Bug - nTopDataOffset + nTopIdx exceed length on last row of data.
284 if (nTopDataOffset + nTopIdx < top_data.Length)
285 top_data[nTopDataOffset + nTopIdx] = bottom_data[nBottomDataOffset + nIdx];
290 nTopDataOffset += colTop[0].offset(0, 1);
291 nBottomDataOffset += colBottom[0].offset(0, 1);
292 nMaskOffset += colBottom[0].offset(0, 1);
295 colTop[0].mutable_cpu_data = top_data;
299 throw new NotImplementedException(
"Unpooling is only supported on the MAX type of pooling.");
302 throw new NotImplementedException(
"Unpooling is only supported on the MAX type of pooling.");
309 throw new NotImplementedException(
"UnPooling does not support the backward operation.");
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_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
void CHECK_GT(double df1, double df2, string str)
Test whether one number is greater than another.
void CHECK_LT(double df1, double df2, string str)
Test whether one number is less than another.
The BlobCollection contains a list of Blobs.
void SetData(double df)
Set all blob data to the value specified.
int Count
Returns the number of items in the collection.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
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.
LayerParameter.LayerType m_type
Specifies the Layer type.
override int ExactNumTopBlobs
Returns the required number of top (output) Blobs: input
override int MinBottomBlobs
Returns the minimum number of required bottom (input) Blobs: input
override void dispose()
Releases all GPU and host resources used by the Layer.
UnPoolingLayer1(CudaDnn< T > cuda, Log log, LayerParameter p)
The UnPoolingLayer1 constructor.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer for use with both Engine.CAFFE and Engine.CUDNN modes.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Run the Forward computation using the Engine.CAFFE mode only.
override int? MaxBottomBlobs
Returns the maximum number of required bottom (input) Blobs: input, mask (only when using MAX)
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)
Currently, not implemented.
uint? stride_h
The stride height (2D only)
List< uint > kernel_size
Kernel size is given as a single value for equal dimensions in all spatial dimensions,...
uint? stride_w
The stride width (2D only)
uint? pad_h
The padding height (2D only)
uint? kernel_h
The kernel height (2D only)
List< uint > stride
Stride is given as a single value for equal dimensions in all spatial dimensions, or once per spatial...
uint? kernel_w
The kernel width (2D only)
uint? pad_w
The padding width (2D only)
List< uint > pad
Pad is given as a single value for equal dimensions in all spatial dimensions, or once per spatial di...
Specifies the base parameter for all layers.
UnPoolingParameter unpooling_param
Returns the parameter set when initialized with LayerType.UNPOOLING
LayerType
Specifies the layer type.
Specifies the parameters for the PoolingLayer.
PoolingMethod
Defines the pooling method.
PoolingMethod pool
Specifies the pooling method.
bool global_pooling
Specifies whether or not to enable global pooling.
Specifies the parameters for the UnPoolingLayer.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.layers.beta namespace contains all beta stage layers.
The MyCaffe.param.beta parameters are used by the MyCaffe.layer.beta 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-...