MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ReshapeLayer.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{
20 public class ReshapeLayer<T> : Layer<T>
21 {
25 List<int> m_rgCopyAxes = new List<int>();
29 int m_nInferredAxis;
33 int m_nConstantCount;
34
43 : base(cuda, log, p)
44 {
46 }
47
51 public override int ExactNumBottomBlobs
52 {
53 get { return 1; }
54 }
55
59 public override int ExactNumTopBlobs
60 {
61 get { return 1; }
62 }
63
69 public override void LayerSetUp(BlobCollection<T> colBottom, BlobCollection<T> colTop)
70 {
71 m_log.CHECK(colTop[0] != colBottom[0], type.ToString() + " Layer does not allow in-place computation.");
72 m_nInferredAxis = -1;
73 m_nConstantCount = 1;
74 m_rgCopyAxes = ReshapeParameter.CalculateCopyAxes(m_param, out m_nInferredAxis, out m_nConstantCount);
75 }
76
82 public override void Reshape(BlobCollection<T> colBottom, BlobCollection<T> colTop)
83 {
84 List<int> rgTopShape = ReshapeParameter.Reshape(m_param, colBottom[0].shape(), m_rgCopyAxes, m_nInferredAxis, m_nConstantCount, m_log);
85
86 colTop[0].Reshape(rgTopShape);
87 m_log.CHECK_EQ(colTop[0].count(), colBottom[0].count(), "output count must match input count");
88
89 colTop[0].ShareData(colBottom[0]);
90 colTop[0].ShareDiff(colBottom[0]);
91 }
92
94 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
95 {
96 }
97
99 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
100 {
101 }
102 }
103}
The Log class provides general output in text form.
Definition: Log.cs:13
void CHECK(bool b, string str)
Test a flag for true.
Definition: Log.cs:227
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
Definition: Log.cs:239
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
LayerParameter.LayerType type
Returns the LayerType of this Layer.
Definition: Layer.cs:927
LayerParameter.LayerType m_type
Specifies the Layer type.
Definition: Layer.cs:35
The ReshapeLayer reshapes the input Blob into an arbitrary-sized output Blob. This layer is initializ...
Definition: ReshapeLayer.cs:21
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Not implemented - reshape Layers do not perform forward, reshaping is performed in Reshape().
Definition: ReshapeLayer.cs:94
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the bottom (input) and top (output) blobs.
Definition: ReshapeLayer.cs:82
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: reshape
Definition: ReshapeLayer.cs:60
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
Definition: ReshapeLayer.cs:69
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: input
Definition: ReshapeLayer.cs:52
ReshapeLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
Constructor.
Definition: ReshapeLayer.cs:42
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Not implemented - reshape Layers do not perform backward.
Definition: ReshapeLayer.cs:99
Specifies the base parameter for all layers.
LayerType
Specifies the layer type.
override string ToString()
Returns a string representation of the LayerParameter.
Specifies the parameters for the ReshapeLayer.
static List< int > CalculateCopyAxes(LayerParameter p, out int nInferredAxis, out int nConstantCount, Log log=null)
Calculate the Copy Axes, inferred axis and constant count.
static List< int > Reshape(LayerParameter p, List< int > rgShape, List< int > rgCopyAxes, int nInferredAxis, int nConstantCount, Log log=null)
Calculates the new shape.
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