SmartEngine  1.6.0
Conv2D.h
1 // Copyright (C) Entropy Software LLC - All Rights Reserved
2 
3 #pragma once
4 
5 #include "ActivationTypes.h"
6 #include "GraphNode.h"
7 #include "Resource.h"
8 
9 namespace SmartEngine
10 {
11 
12 #pragma pack(push, 4)
13 enum class Conv2DType : byte
14 {
18  Conv2D,
19 
23  Conv2DWithBias,
24 
28  Conv2DTranspose,
29 
33  Conv2DTransposeWithBias,
34 
35  Count,
36 };
37 SMARTENGINE_ENUM_STRING(Conv2DType, "Conv2D", "Conv2DWithBias", "Conv2DTranspose", "Conv2DTransposeWithBias");
38 
39 struct Conv2DInfo
40 {
45  int inputWidth = -1;
46 
51  int inputHeight = -1;
52 
57  int inputChannels = -1;
58 
62  int filterWidth = 4;
63 
67  int filterHeight = 4;
68 
73  int strideWidth = 1;
74 
79  int strideHeight = 1;
80 
85  int outputChannels = -1;
86 
87  bool operator==(const Conv2DInfo& rhs)
88  {
89  return inputWidth == rhs.inputWidth && inputHeight == rhs.inputHeight && inputChannels == rhs.inputChannels &&
92  }
93 };
94 
99 {
103  Conv2DType type = Conv2DType::Conv2D;
104 
108  ActivationType activationType = ActivationType::None;
109 
113  IGraphNode* input = nullptr;
114 
119 
124 };
125 #pragma pack(pop)
126 
133 class SMARTENGINE_EXPORT IConv2DLayer : public IGraphNode, public ISerializable
134 {
135 public:
136  SMARTENGINE_DECLARE_CLASS(IConv2DLayer)
137 
138 
139  virtual ObjectPtr<IConv2DLayer> InstanceLayer(const char* name, IGraphNode* input) = 0;
146 
150  virtual void SetRandomWeights() = 0;
151 };
152 
157 
159 extern "C"
160 {
161  SMARTENGINE_EXPORT ObjPtr Conv2DLayer_CreateInstance(const Conv2DLayerCInfo& cinfo);
162  SMARTENGINE_EXPORT ObjPtr Conv2DLayer_InstanceLayer(ObjPtr object, const char* name, ObjPtr input);
163  SMARTENGINE_EXPORT void Conv2DLayer_SetRandomWeights(ObjPtr object);
164 }
166 
167 } // namespace SmartEngine
SmartEngine::IGraphNode
A logical node in the AI graph. Some nodes, like NeuralNetwork, are composed of other nodes (neuron l...
Definition: GraphNode.h:34
SmartEngine::Conv2DInfo::inputWidth
int inputWidth
Input width. If the previous layer is a Conv2D layer, you can set this to -1 to have it auto-calculat...
Definition: Conv2D.h:45
SmartEngine::Conv2DType
Conv2DType
Definition: Conv2D.h:14
SmartEngine::ISerializable
Base class for objects that can be loaded from and saved to an in memory buffer.
Definition: Resource.h:54
SmartEngine::GraphNodeCInfo
Data used to construct an IGraphNode instance
Definition: GraphNode.h:17
SmartEngine::Conv2DLayerCInfo::info
Conv2DInfo info
General convolution info.
Definition: Conv2D.h:118
SmartEngine::Conv2DLayerCInfo::weightStandardDeviation
float weightStandardDeviation
The standard deviation to use when randomizing the filter weights.
Definition: Conv2D.h:123
SmartEngine::Conv2DInfo::outputChannels
int outputChannels
Number of output channels this convolution should produce. This is also the same as the number of fil...
Definition: Conv2D.h:85
SmartEngine::Conv2DLayerCInfo::type
Conv2DType type
The type of convolution to apply.
Definition: Conv2D.h:103
SmartEngine::ObjectPtr
Smart pointer to an IObject. Automatic ref counting.
Definition: ObjectPtr.h:16
SmartEngine
Definition: A2CTrainer.h:10
SmartEngine::Conv2DInfo::filterWidth
int filterWidth
The width of the filters applied.
Definition: Conv2D.h:62
SmartEngine::Conv2DInfo::strideHeight
int strideHeight
The stride height of the convolution. The filter is moved over this many elements every convolution.
Definition: Conv2D.h:79
SmartEngine::Conv2DInfo
Definition: Conv2D.h:40
SmartEngine::Conv2DType::Conv2D
@ Conv2D
2D Convolution layer, no bias
SmartEngine::IConv2DLayer
2D convolution layer. Input is interpreted as a 2D grid laid in row major order. Filters are applied ...
Definition: Conv2D.h:134
SmartEngine::ActivationType
ActivationType
The activation function to apply to the output of the NeuronLayer
Definition: ActivationTypes.h:14
SmartEngine::Conv2DInfo::strideWidth
int strideWidth
The stride width of the convolution. The filter is moved over this many elements every convolution.
Definition: Conv2D.h:73
SmartEngine::Conv2DInfo::inputHeight
int inputHeight
Input height. If the previous layer is a Conv2D layer, you can set this to -1 to have it auto-calcula...
Definition: Conv2D.h:51
SmartEngine::Conv2DLayerCInfo
Conv2D layer constructor info
Definition: Conv2D.h:99
SmartEngine::IConv2DLayer::SetRandomWeights
virtual void SetRandomWeights()=0
Initialize the filters of the layer to random values.
SmartEngine::Conv2DLayerCInfo::input
IGraphNode * input
The input into this convolution.
Definition: Conv2D.h:113
SmartEngine::CreateConv2DLayer
SMARTENGINE_EXPORT ObjectPtr< IConv2DLayer > CreateConv2DLayer(const Conv2DLayerCInfo &cinfo)
Creates an instance of IConv2DLayer
SmartEngine::Conv2DInfo::inputChannels
int inputChannels
Number of input channels. If the previous layer is a Conv2D layer, you can set this to -1 to have it ...
Definition: Conv2D.h:57
SmartEngine::Conv2DInfo::filterHeight
int filterHeight
The height of the filters applies. Set this to 1 if using Conv2D as a Conv1D
Definition: Conv2D.h:67
SmartEngine::Conv2DInfo::operator==
bool operator==(const Conv2DInfo &rhs)
Definition: Conv2D.h:87
SmartEngine::Conv2DLayerCInfo::activationType
ActivationType activationType
The activation to apply on the layer.
Definition: Conv2D.h:108