-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayer.h
137 lines (115 loc) · 2.81 KB
/
Layer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// Layer.h
// ConvNet
//
// Created by Márton Szemenyei on 2017. 09. 28..
// Copyright © 2017. Márton Szemenyei. All rights reserved.
//
#ifndef Layer_h
#define Layer_h
#define NN_SILENT
#include <cstdint>
#include <vector>
#include <string>
#include "Activations.h"
// Layer Types
typedef enum {
CONV=0,
TRCONV,
FC,
BATCHNORM,
MAXPOOL,
AVGPOOL,
REORG,
ROUTE,
CONCAT,
SHORTCUT,
SOFTMAX,
NETWORK,
OTHER
} LAYERTYPE;
inline std::string type2Str(LAYERTYPE type)
{
switch (type) {
case CONV:
return "Conv";
break;
case TRCONV:
return "Tr Conv";
break;
case FC:
return "Linear";
break;
case BATCHNORM:
return "BatchNorm";
break;
case MAXPOOL:
return "Max Pool";
break;
case AVGPOOL:
return "Avg Pool";
break;
case REORG:
return "Reorg";
break;
case ROUTE:
return "Route";
break;
case CONCAT:
return "Concat";
break;
case SHORTCUT:
return "Shortcut";
break;
case SOFTMAX:
return "Softmax";
break;
case NETWORK:
return "Net";
break;
case OTHER:
return "Other";
break;
}
}
class Layer
{
protected:
const float *inputs;
float *outputs;
// Needed by convolutional layers
float *workspace;
// Needed to reduce input size
int32_t cropRows;
int32_t inW;
int32_t inH;
int32_t outW;
int32_t outH;
int32_t inCh;
int32_t outCh;
ACTIVATION activation;
LAYERTYPE type;
public:
// Forward input
virtual void forward() = 0;
virtual bool loadWeights( std::ifstream &file ) = 0;
virtual void print() = 0;
virtual ~Layer() {}
virtual int32_t getWorkSpaceSize() = 0;
inline void setCropRows( int32_t val) { cropRows = val; }
inline int32_t getNextCropRows() { return cropRows * outH / inH; }
virtual bool HasBias() {return true;}
inline void setInput( const float* input ) {inputs = input;}
inline const float *getInput() {return inputs;}
inline float *getOutput() {return outputs;}
inline void setWorkSpace( float *_workspace ) {workspace = _workspace;}
inline LAYERTYPE getType() {return type;}
// Get total number of output elements
inline int32_t getN() {return outW*outH*outCh; }
// Get number of output channels
inline int32_t getCh() {return outCh; }
// Get output width and height
inline int32_t getW() {return outW; }
inline int32_t getH() {return outH; }
};
#endif /* Layer_h */