forked from larryniven/nn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnn.h
170 lines (122 loc) · 4.92 KB
/
cnn.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef CNN_H
#define CNN_H
#include "autodiff/autodiff.h"
#include "nn/tensor-tree.h"
namespace cnn {
struct transcriber {
virtual ~transcriber();
virtual bool require_param() const;
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) = 0;
};
struct conv_transcriber
: public transcriber {
int p1;
int p2;
int d1;
int d2;
conv_transcriber();
conv_transcriber(int p1, int p2, int d1, int d2);
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct max_pooling_transcriber
: public transcriber {
int dim1;
int dim2;
int stride1;
int stride2;
max_pooling_transcriber(int dim1, int dim2);
max_pooling_transcriber(int dim1, int dim2, int stride1, int stride2);
virtual bool require_param() const override;
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct fc_transcriber
: public transcriber {
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct framewise_fc_transcriber
: public transcriber {
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct relu_transcriber
: public transcriber {
virtual bool require_param() const override;
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct dropout_transcriber
: public transcriber {
double prob;
std::default_random_engine& gen;
dropout_transcriber(double prob, std::default_random_engine& gen);
virtual bool require_param() const override;
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct multilayer_transcriber
: public transcriber {
std::vector<std::shared_ptr<transcriber>> layers;
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct logsoftmax_transcriber
: public transcriber {
virtual bool require_param() const override;
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
struct densenet_transcriber
: public transcriber {
int transcriber;
densenet_transcriber(int transcriber);
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
std::vector<std::shared_ptr<autodiff::op_t>> ifo_pooling(
std::vector<std::shared_ptr<autodiff::op_t>> input,
std::vector<std::shared_ptr<autodiff::op_t>> input_gate,
std::vector<std::shared_ptr<autodiff::op_t>> forget_gate,
std::vector<std::shared_ptr<autodiff::op_t>> output_gate);
std::vector<std::shared_ptr<autodiff::op_t>> conv_ifo_pooling(
std::shared_ptr<autodiff::op_t> output,
std::shared_ptr<autodiff::op_t> input_gate,
std::shared_ptr<autodiff::op_t> forget_gate,
std::shared_ptr<autodiff::op_t> output_gate,
int size);
std::vector<std::shared_ptr<autodiff::op_t>> conv_fo_pooling(
std::shared_ptr<autodiff::op_t> output,
std::shared_ptr<autodiff::op_t> forget_gate,
std::shared_ptr<autodiff::op_t> output_gate,
int size);
struct conv_fo_pooling_transcriber
: public transcriber {
unsigned int rows;
unsigned int cols;
std::shared_ptr<transcriber> input_conv;
std::shared_ptr<transcriber> forget_gate_conv;
std::shared_ptr<transcriber> output_gate_conv;
conv_fo_pooling_transcriber(
unsigned int rows, unsigned int cols,
std::shared_ptr<transcriber> input,
std::shared_ptr<transcriber> forget_gate,
std::shared_ptr<transcriber> output_gate);
virtual std::shared_ptr<autodiff::op_t>
operator()(std::shared_ptr<tensor_tree::vertex> var_tree,
std::shared_ptr<autodiff::op_t> input) override;
};
}
#endif