-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
49 lines (37 loc) · 1.24 KB
/
test.cpp
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
#include "layers.h"
#include<stdio.h>
#include <sys/time.h>
#include "utils.h"
int main(int argc, char **argv) {
Image<float> data(3, 3, 1, 2);
Image<float> data_1(3, 3, 1, 2);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
data(i, j, 0, 0) = i + 1;
data(i, j, 0, 1) = (i + 1) * 0.1;
data_1(i, j, 0, 0) = (i + 1) * 1;
data_1(i, j, 0, 1) = (i + 1) * 10;
}
}
Image<float> dx(3, 3, 1, 2);
DataLayer * d_layer = new DataLayer(3, 3, 1, 2, data);
BatchNorm * bat = new BatchNorm(d_layer);
Var x, y, z, w;
Func back;
back(x, y, z, w) = data_1(x, y, z, w);
bat->back_propagate(back);
init_constant(bat->params[1], 0.0);
init_constant(bat->params[0], 1.0);
std::vector<Func> train_outs;
train_outs.push_back(bat->f_param_grads[0]);
train_outs.push_back(bat->f_param_grads[1]);
train_outs.push_back(bat->f_in_grad);
Pipeline train(train_outs);
back.realize(data_1);
//d_layer->forward.realize(data);
//bat->forward.compute_root();
//bat->forward.trace_stores();
//bat->forward.realize(data);
//bat->back_propagate.realize();
train.realize({bat->param_grads[0], bat->param_grads[1], data});
}