MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ConstantLayer.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Text;
6using MyCaffe.basecode;
7using MyCaffe.common;
8using MyCaffe.param;
9
10namespace MyCaffe.layers
11{
17 public class ConstantLayer<T> : Layer<T>
18 {
19 BlobShape m_shape;
20 List<float> m_rgF;
21
29 : base(cuda, log, p)
30 {
32 }
33
39 public override void LayerSetUp(BlobCollection<T> colBottom, BlobCollection<T> colTop)
40 {
43
44 if (!string.IsNullOrEmpty(m_param.constant_param.binary_data_file))
45 {
46 m_log.CHECK(File.Exists(m_param.constant_param.binary_data_file), "The 'binary_data_file' specified ('" + m_param.constant_param.binary_data_file + "') could not be found!");
47
48 using (FileStream fs = new FileStream(m_param.constant_param.binary_data_file, FileMode.Open, FileAccess.Read))
49 using (BinaryReader br = new BinaryReader(fs))
50 {
51 BlobProto proto = BlobProto.Load(br);
52 m_rgF = proto.data;
53 }
54 }
55 }
56
62 public override void Reshape(BlobCollection<T> colBottom, BlobCollection<T> colTop)
63 {
65 T[] rgData = Utility.ConvertVec<T>(m_rgF.ToArray());
66 colTop[0].SetData(rgData);
67 }
68
77 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
78 {
79 }
80
82 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
83 {
84 }
85 }
86}
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
The Utility class provides general utility funtions.
Definition: Utility.cs:35
static double[] ConvertVec(float[] rgf)
Convert an array of float to an array of generics.
Definition: Utility.cs:550
The BlobCollection contains a list of Blobs.
void SetData(double df)
Set all blob data to the value specified.
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
The ConstantLayer provides a layer that just outputs a constant value. This layer is initialized with...
ConstantLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The ConstantLayer constructor.
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Not implemented - constant Layers do not perform backward.
override void Reshape(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Reshape the layer.
override void LayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the layer.
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 m_type
Specifies the Layer type.
Definition: Layer.cs:35
The BlobProto contains the descripion of a blob.
Definition: BlobProto.cs:15
List< float > data
Get/set the data as a List of float.
Definition: BlobProto.cs:180
object Load(BinaryReader br, bool bNewInstance)
Loads a BlobProto from a binary reader.
Definition: BlobProto.cs:84
Specifies the shape of a Blob.
Definition: BlobShape.cs:15
BlobShape output_shape
Specifies the output shape.
string binary_data_file
Specifies a binary data file containing the values to load.
List< float > values_f
Specifies a set of float values used to fill the output. When only one item is specified,...
Specifies the base parameter for all layers.
ConstantParameter constant_param
Returns the parameter set when initialized with LayerType.CONSTANT
LayerType
Specifies the layer type.
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