File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ #include " autodiff.hpp"
2+ #include " net.hpp"
3+ #include " layers.hpp"
4+ #include " optim.hpp"
5+ #include " loss.hpp"
6+
7+ #include < iostream>
8+
9+ class Model : public nn ::Net{
10+ public:
11+ Model () : nn::Net(), fc1(10 , 1 , this ){ }
12+
13+ nn::FullyConnected fc1;
14+ autodiff::Var forward (autodiff::Var& x) {
15+ auto y = fc1 (x);
16+ return y;
17+ }
18+ };
19+
20+ int main (){
21+ nn::Tensor a (1 ,10 );
22+ nn::Tensor z (1 );
23+ a.rand (0 ,1 );
24+ z.rand (0 ,1 );
25+ std::cout << a.row (0 );
26+ std::cout << a.col (0 );
27+ autodiff::Var var_a (a);
28+ autodiff::Var var_z (z);
29+
30+ Model model;
31+ auto opt = opt::GD (model.params ());
32+ auto y = model.forward (var_a);
33+ auto l = loss::cross_entropy_loss (y, var_z);
34+ model.backward (y);
35+ opt.step ();
36+ std::cout << l;
37+ }
You can’t perform that action at this time.
0 commit comments