MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
UnsqueezeLayer.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 UnsqueezeLayer<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 List<int> rgDim = new List<int>(colBottom[0].shape());
72
73 if (colBottom.Count > 1)
74 rgIdxF = convertF(colBottom[1].mutable_cpu_data);
75
76 List<int> rgIdx = new List<int>();
77 if (rgIdxF != null)
78 {
79 if (m_param.squeeze_param.axes.Count > 0)
80 m_log.WriteLine("WARNING: Squeeze indexes specified in as blob input data, squeeze parameters will be ignored.");
81
82 for (int i = 0; i < rgIdxF.Length; i++)
83 {
84 rgIdx.Add((int)rgIdxF[i]);
85 }
86 }
87 else
88 {
89 rgIdx = new List<int>(m_param.squeeze_param.axes);
90 }
91
92 rgIdx = rgIdx.OrderBy(p => p).ToList();
93
94 for (int i = 0; i < rgIdx.Count; i++)
95 {
96 int nAxis = rgIdx[i];
97
98 if (nAxis >= rgDim.Count)
99 rgDim.Add(1);
100 else
101 rgDim.Insert(nAxis, 1);
102 }
103
104 colTop[0].Reshape(rgDim);
105 colTop[0].ShareData(colBottom[0]);
106 colTop[0].ShareDiff(colBottom[0]);
107 }
108
110 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
111 {
112 }
113
115 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
116 {
117 }
118 }
119}
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.
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 UnsqueezeLayer performs an unsqueeze operation where a single dimension is inserted at each index...
override int ExactNumTopBlobs
Returns the exact number of required top (output) Blobs: flatten
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Not implemented - squeeze Layers do not perform forward.
override int ExactNumBottomBlobs
Returns the exact number of required bottom (input) Blobs: input.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
UnsqueezeLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The UnsqueezeLayer constructor.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the top (output) blob.
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Not implemented - squeeze Layers do not perform backward.
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