File tree Expand file tree Collapse file tree 7 files changed +47
-12
lines changed
feedforward_neural_network Expand file tree Collapse file tree 7 files changed +47
-12
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,11 @@ target_link_libraries(pytorch-cpp "${TORCH_LIBRARIES}")
9
9
10
10
add_executable (pytorch_basics tutorials/basics/pytorch_basics/main.cpp )
11
11
target_link_libraries (pytorch_basics "${TORCH_LIBRARIES} " )
12
- add_executable (linear_regression tutorials/basics/linear_regression/main.cpp )
13
- target_link_libraries (linear_regression "${TORCH_LIBRARIES} " )
14
- add_executable (logistic_regression tutorials/basics/logistic_regression/main.cpp )
15
- target_link_libraries (logistic_regression "${TORCH_LIBRARIES} " )
16
- add_executable (feedforward_neural_network tutorials/basics/feedforward_neural_network/main.cpp )
17
- target_link_libraries (feedforward_neural_network "${TORCH_LIBRARIES} " )
12
+ # add_executable(linear_regression tutorials/basics/linear_regression/main.cpp)
13
+ # target_link_libraries(linear_regression "${TORCH_LIBRARIES}")
14
+ # add_executable(logistic_regression tutorials/basics/logistic_regression/main.cpp)
15
+ # target_link_libraries(logistic_regression "${TORCH_LIBRARIES}")
16
+ # add_executable(feedforward_neural_network tutorials/basics/feedforward_neural_network/main.cpp)
17
+ # target_link_libraries(feedforward_neural_network "${TORCH_LIBRARIES}")
18
18
19
19
set_property (TARGET pytorch-cpp PROPERTY CXX_STANDARD 11 )
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 Omkar Prabhu
1
2
#include < torch/torch.h>
2
3
#include < iostream>
3
4
4
5
int main () {
5
6
std::cout << " Welcome to PyTorch Tutorial in C++ for Deep Learning Researchers" << std::endl;
6
- }
7
+ }
Original file line number Diff line number Diff line change @@ -14,9 +14,17 @@ function build() {
14
14
make
15
15
}
16
16
17
+ function lint() {
18
+ cpplint --linelength=120 main.cpp tutorials/* /* /**
19
+ }
20
+
17
21
if [ $1 = " install" ]
18
22
then
19
23
install
20
- else
24
+ elif [ $1 = " build" ]
25
+ then
21
26
build
27
+ elif [ $1 = " lint" ]
28
+ then
29
+ lint
22
30
fi
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 Omkar Prabhu
1
2
#include < torch/torch.h>
2
3
#include < iostream>
3
4
4
5
int main () {
5
6
std::cout << " FeedForward Neural Network" << std::endl;
6
- }
7
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 Omkar Prabhu
1
2
#include < torch/torch.h>
2
3
#include < iostream>
3
4
4
5
int main () {
5
6
std::cout << " Linear Regression" << std::endl;
6
- }
7
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 Omkar Prabhu
1
2
#include < torch/torch.h>
2
3
#include < iostream>
3
4
4
5
int main () {
5
6
std::cout << " Logistic Regression" << std::endl;
6
- }
7
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2019 Omkar Prabhu
1
2
#include < torch/torch.h>
3
+ #include < torch/csrc/autograd/variable.h>
4
+ #include < torch/csrc/autograd/function.h>
2
5
#include < iostream>
3
6
4
7
int main () {
5
8
std::cout << " PyTorch Basics" << std::endl;
6
- }
9
+
10
+ // /////////////////////////////////////////////////////////
11
+ // BASIC AUTOGRAD EXAMPLE 1 //
12
+ // /////////////////////////////////////////////////////////
13
+
14
+ // Create Tensors
15
+ torch::Tensor x = torch::tensor (1.0 , torch::requires_grad ());
16
+ torch::Tensor w = torch::tensor (2.0 , torch::requires_grad ());
17
+ torch::Tensor b = torch::tensor (3.0 , torch::requires_grad ());
18
+
19
+ // Build a computational graph
20
+ auto y = w * x + b; // y = 2 * x + 3
21
+
22
+ // Compute the gradients
23
+ y.backward ();
24
+
25
+ // Print out the gradients
26
+ std::cout << x.grad () << std::endl; // x.grad() = 2
27
+ std::cout << w.grad () << std::endl; // w.grad() = 1
28
+ std::cout << b.grad () << std::endl; // b.grad() = 1
29
+ }
You can’t perform that action at this time.
0 commit comments