-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLayer.hpp
More file actions
76 lines (65 loc) · 1.68 KB
/
Copy pathLayer.hpp
File metadata and controls
76 lines (65 loc) · 1.68 KB
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
#pragma once
#include <initializer_list>
#include <numeric>
#include <stdexcept>
#include <string>
#include <vector>
#include "layers/Shape.hpp"
#include "layers/Tensor.hpp"
#include "oneapi/tbb.h"
namespace it_lab_ai {
enum LayerType : uint8_t {
kInput,
kPooling,
kNormalization,
kDropout,
kElementWise,
kConvolution,
kFullyConnected,
kFlatten,
kOutput,
};
enum ImplType : uint8_t { kDefault, kTBB, kSTL };
class Layer;
struct PostOperations {
std::vector<Layer*> layers;
unsigned int count = 0;
};
class Layer {
public:
Layer() = default;
virtual ~Layer() = default;
PostOperations postops;
int getID() const { return id_; }
void setID(int id) { id_ = id; }
LayerType getName() const { return type_; }
void setName(LayerType type) { type_ = type; }
virtual void run(const Tensor& input, Tensor& output) = 0;
#ifdef ENABLE_STATISTIC_WEIGHTS
virtual Tensor get_weights() = 0;
#endif
protected:
int id_ = 0;
LayerType type_;
};
template <typename ValueType>
class LayerImpl {
public:
LayerImpl() = default;
LayerImpl(const Shape& inputShape, const Shape& outputShape)
: inputShape_(inputShape), outputShape_(outputShape) {}
LayerImpl(const LayerImpl& c) = default;
LayerImpl& operator=(const LayerImpl& c) = default;
virtual std::vector<ValueType> run(
const std::vector<ValueType>& input) const = 0;
Shape get_input_shape() const { return inputShape_; }
Shape get_output_shape() const { return outputShape_; }
// weights width x height
std::pair<Shape, Shape> get_dims() const {
return std::pair<Shape, Shape>(outputShape_, inputShape_);
}
protected:
Shape inputShape_;
Shape outputShape_;
};
} // namespace it_lab_ai