7
7
int main () {
8
8
std::cout << " PyTorch Basics" << std::endl;
9
9
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;
13
15
14
16
// Create Tensors
15
17
torch::Tensor x = torch::tensor (1.0 , torch::requires_grad ());
@@ -27,23 +29,25 @@ int main() {
27
29
std::cout << w.grad () << std::endl; // w.grad() = 1
28
30
std::cout << b.grad () << std::endl; // b.grad() = 1
29
31
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;
33
37
34
38
// Create Tensors of shapes
35
39
x = torch::randn ({10 , 3 });
36
40
y = torch::randn ({10 , 2 });
37
41
38
42
39
43
// Build a fully connected layer
40
- auto linear = torch::nn::Linear (3 ,2 );
44
+ auto linear = torch::nn::Linear (3 , 2 );
41
45
std::cout << " w: " << linear->weight << std::endl;
42
46
std::cout << " b: " << linear->bias << std::endl;
43
47
44
48
// Build loss function and optimizer
45
49
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 ));
47
51
48
52
// Forward pass
49
53
auto pred = linear (x);
@@ -66,4 +70,20 @@ int main() {
66
70
pred = linear (x);
67
71
loss = criterion (pred, y);
68
72
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
+ // =============================================================== //
69
89
}
0 commit comments