MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
TileLayer.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
6using MyCaffe.common;
7using MyCaffe.param;
8
9namespace MyCaffe.layers
10{
16 public class TileLayer<T> : Layer<T>
17 {
18 int m_nAxis;
19 int m_nTiles;
20 int m_nOuterDim;
21 int m_nInnerDim;
22
35 : base(cuda, log, p)
36 {
38 }
39
43 public override int ExactNumBottomBlobs
44 {
45 get { return 1; }
46 }
47
51 public override int ExactNumTopBlobs
52 {
53 get { return 1; }
54 }
55
61 public override void LayerSetUp(BlobCollection<T> colBottom, BlobCollection<T> colTop)
62 {
63 }
64
70 public override void Reshape(BlobCollection<T> colBottom, BlobCollection<T> colTop)
71 {
72 m_nAxis = colBottom[0].CanonicalAxisIndex(m_param.tile_param.axis);
73 m_nTiles = m_param.tile_param.tiles;
74 m_log.CHECK_GT(m_param.tile_param.tiles, 0, "Number of tiles must be positive.");
75
76 List<int> rgTopShape = Utility.Clone<int>(colBottom[0].shape());
77 rgTopShape[m_nAxis] = colBottom[0].shape(m_nAxis) * m_nTiles;
78 colTop[0].Reshape(rgTopShape);
79
80 m_nOuterDim = colBottom[0].count(0, m_nAxis);
81 m_nInnerDim = colBottom[0].count(m_nAxis);
82 }
83
93 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
94 {
95 long hBottomData = colBottom[0].gpu_data;
96 long hTopData = colTop[0].mutable_gpu_data;
97 int bottom_tile_axis = colBottom[0].shape(m_nAxis);
98 int nCount = colTop[0].count();
99
100 m_cuda.tile_fwd(nCount, hBottomData, m_nInnerDim, m_nTiles, bottom_tile_axis, hTopData);
101 }
102
111 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
112 {
113 if (!rgbPropagateDown[0])
114 return;
115
116 long hTopDiff = colTop[0].gpu_diff;
117 long hBottomDiff = colBottom[0].mutable_gpu_diff;
118 int bottom_tile_axis = colBottom[0].shape(m_nAxis);
119 int tile_size = m_nInnerDim / bottom_tile_axis;
120 int nCount = colBottom[0].count();
121
122 m_cuda.tile_bwd(nCount, hTopDiff, tile_size, m_nTiles, bottom_tile_axis, hBottomDiff);
123 }
124 }
125}
The Log class provides general output in text form.
Definition: Log.cs:13
void CHECK_GT(double df1, double df2, string str)
Test whether one number is greater than another.
Definition: Log.cs:299
The Utility class provides general utility funtions.
Definition: Utility.cs:35
The BlobCollection contains a list of Blobs.
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.
Definition: CudaDnn.cs:969
An interface for the units of computation which can be composed into a Net.
Definition: Layer.cs:31
Log m_log
Specifies the Log for output.
Definition: Layer.cs:43
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
Definition: Layer.cs:47
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
Definition: Layer.cs:39
LayerParameter.LayerType m_type
Specifies the Layer type.
Definition: Layer.cs:35
The TileLayer copies a Blob along specified dimensions. This layer is initialized with the MyCaffe....
Definition: TileLayer.cs:17
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
Definition: TileLayer.cs:70
TileLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The TileLayer constructor.
Definition: TileLayer.cs:34
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t the inputs.
Definition: TileLayer.cs:111
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: tile.
Definition: TileLayer.cs:52
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Computes the forward calculation.
Definition: TileLayer.cs:93
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: input.
Definition: TileLayer.cs:44
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
Definition: TileLayer.cs:61
Specifies the base parameter for all layers.
TileParameter tile_param
Returns the parameter set when initialized with LayerType.TILE
LayerType
Specifies the layer type.
int tiles
Specifies the number of copies (tiles) of the blob to output.
int axis
Specifies the index of the axis to tile.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
The MyCaffe.layers namespace contains all layers that have a solidified code base,...
Definition: LayerFactory.cs:15
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-...
Definition: Annotation.cs:12