77int main () {
88 std::cout << " PyTorch Basics" << std::endl;
99
10- // /////////////////////////////////////////////////////////
11- // BASIC AUTOGRAD EXAMPLE 1 //
12- // /////////////////////////////////////////////////////////
10+ // ================================================================ //
11+ // BASIC AUTOGRAD EXAMPLE 1 //
12+ // ================================================================ //
13+
14+ std::cout << std::endl << " BASIC AUTOGRAD EXAMPLE 1: " << std::endl;
1315
1416 // Create Tensors
1517 torch::Tensor x = torch::tensor (1.0 , torch::requires_grad ());
@@ -27,23 +29,25 @@ int main() {
2729 std::cout << w.grad () << std::endl; // w.grad() = 1
2830 std::cout << b.grad () << std::endl; // b.grad() = 1
2931
30- // /////////////////////////////////////////////////////////
31- // BASIC AUTOGRAD EXAMPLE 2 //
32- // /////////////////////////////////////////////////////////
32+ // ================================================================ //
33+ // BASIC AUTOGRAD EXAMPLE 2 //
34+ // ================================================================ //
35+
36+ std::cout << std::endl << " BASIC AUTOGRAD EXAMPLE 2: " << std::endl;
3337
3438 // Create Tensors of shapes
3539 x = torch::randn ({10 , 3 });
3640 y = torch::randn ({10 , 2 });
3741
3842
3943 // Build a fully connected layer
40- auto linear = torch::nn::Linear (3 ,2 );
44+ auto linear = torch::nn::Linear (3 , 2 );
4145 std::cout << " w: " << linear->weight << std::endl;
4246 std::cout << " b: " << linear->bias << std::endl;
4347
4448 // Build loss function and optimizer
4549 auto criterion = torch::nn::MSELoss ();
46- auto optimizer = torch::optim::SGD (linear->parameters , torch::optim::SGDOptions (0.01 ));
50+ auto optimizer = torch::optim::SGD (linear->parameters () , torch::optim::SGDOptions (0.01 ));
4751
4852 // Forward pass
4953 auto pred = linear (x);
@@ -66,4 +70,20 @@ int main() {
6670 pred = linear (x);
6771 loss = criterion (pred, y);
6872 std::cout << " loss after 1 step optimization: " << loss.item ().toFloat () << std::endl;
73+
74+ // =============================================================== //
75+ // INPUT PIPELINE //
76+ // =============================================================== //
77+
78+ // =============================================================== //
79+ // INPUT PIPELINE FOR CUSTOM DATASET //
80+ // =============================================================== //
81+
82+ // =============================================================== //
83+ // PRETRAINED MODEL //
84+ // =============================================================== //
85+
86+ // =============================================================== //
87+ // SAVE AND LOAD THE MODEL //
88+ // =============================================================== //
6989}
0 commit comments