MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
SqueezeLayer.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
6using MyCaffe.common;
7using MyCaffe.param;
8using MyCaffe.param.beta;
9
10namespace MyCaffe.layers.beta
11{
16 public class SqueezeLayer<T> : Layer<T>
17 {
26 : base(cuda, log, p)
27 {
29 }
30
34 public override int ExactNumBottomBlobs
35 {
36 get { return 1; }
37 }
38
42 public override int ExactNumTopBlobs
43 {
44 get { return 1; }
45 }
46
52 public override void LayerSetUp(BlobCollection<T> colBottom, BlobCollection<T> colTop)
53 {
54 }
55
65 public override void Reshape(BlobCollection<T> colBottom, BlobCollection<T> colTop)
66 {
67 if (!reshapeNeeded(colBottom, colTop))
68 return;
69
70 float[] rgIdxF = null;
71
72 if (colBottom.Count > 1)
73 rgIdxF = convertF(colBottom[1].mutable_cpu_data);
74
75 List<int> rgIdx = new List<int>();
76 if (rgIdxF != null)
77 {
78 if (m_param.squeeze_param.axes.Count > 0)
79 m_log.WriteLine("WARNING: Squeeze indexes specified in as blob input data, squeeze parameters will be ignored.");
80
81 for (int i = 0; i < rgIdxF.Length; i++)
82 {
83 rgIdx.Add((int)rgIdxF[i]);
84 }
85 }
86 else
87 {
88 rgIdx = new List<int>(m_param.squeeze_param.axes);
89 }
90
91 List<int> rgDim = new List<int>();
92 int nIdx = 0;
93
94 for (int i = 0; i < colBottom[0].shape().Count; i++)
95 {
96 int nDim = colBottom[0].shape()[i];
97
98 if (nDim != 1)
99 {
100 rgDim.Add(nDim);
101 }
102 else if (rgIdx != null && rgIdx.Count > 0)
103 {
104 if (nIdx >= rgIdx.Count)
105 {
106 rgDim.Add(nDim);
107 }
108 else
109 {
110 if (rgIdx[nIdx] != i)
111 rgDim.Add(nDim);
112 nIdx++;
113 }
114 }
115 }
116
117 colTop[0].Reshape(rgDim);
118 colTop[0].ShareData(colBottom[0]);
119 colTop[0].ShareDiff(colBottom[0]);
120 }
121
123 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
124 {
125 }
126
128 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
129 {
130 }
131 }
132}
The Log class provides general output in text form.
Definition: Log.cs:13
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
Definition: Log.cs:80
The BlobCollection contains a list of Blobs.
void Add(Blob< T > b)
Add a new Blob to the collection.
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.
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
float convertF(T df)
Converts a generic to a float value.
Definition: Layer.cs:1359
virtual bool reshapeNeeded(BlobCollection< T > colBottom, BlobCollection< T > colTop, bool bReset=true)
Tests the shapes of both the bottom and top blobs and if they are the same as the previous sizing,...
Definition: Layer.cs:622
LayerParameter.LayerType m_type
Specifies the Layer type.
Definition: Layer.cs:35
The SqueezeLayer performs a squeeze operation where all single dimensions are removed.
Definition: SqueezeLayer.cs:17
SqueezeLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The SqueezeLayer constructor.
Definition: SqueezeLayer.cs:25
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
Definition: SqueezeLayer.cs:52
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the top (output) blob.
Definition: SqueezeLayer.cs:65
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Not implemented - squeeze Layers do not perform forward.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Not implemented - squeeze Layers do not perform backward.
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: flatten
Definition: SqueezeLayer.cs:43
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: input.
Definition: SqueezeLayer.cs:35
Specifies the base parameter for all layers.
SqueezeParameter squeeze_param
Returns the parameter set when initialized with LayerType.RESHAPE
LayerType
Specifies the layer type.
List< int > axes
Specifies the axes to remove if dim=1 on squeeze, or add dim=1 on unsqueeze.
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.beta namespace contains all beta stage layers.
Definition: LayerFactory.cs:9
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-...
Definition: Annotation.cs:12