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}")
99
1010add_executable (pytorch_basics tutorials/basics/pytorch_basics/main.cpp)
1111target_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}")
1818
1919set_property (TARGET pytorch-cpp PROPERTY CXX_STANDARD 11)
Original file line number Diff line number Diff line change 1+ // Copyright 2019 Omkar Prabhu
12#include < torch/torch.h>
23#include < iostream>
34
45int main () {
56 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() {
1414 make
1515}
1616
17+ function lint() {
18+ cpplint --linelength=120 main.cpp tutorials/* /* /**
19+ }
20+
1721if [ $1 = " install" ]
1822then
1923 install
20- else
24+ elif [ $1 = " build" ]
25+ then
2126 build
27+ elif [ $1 = " lint" ]
28+ then
29+ lint
2230fi
Original file line number Diff line number Diff line change 1+ // Copyright 2019 Omkar Prabhu
12#include < torch/torch.h>
23#include < iostream>
34
45int main () {
56 std::cout << " FeedForward Neural Network" << std::endl;
6- }
7+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2019 Omkar Prabhu
12#include < torch/torch.h>
23#include < iostream>
34
45int main () {
56 std::cout << " Linear Regression" << std::endl;
6- }
7+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2019 Omkar Prabhu
12#include < torch/torch.h>
23#include < iostream>
34
45int main () {
56 std::cout << " Logistic Regression" << std::endl;
6- }
7+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2019 Omkar Prabhu
12#include < torch/torch.h>
3+ #include < torch/csrc/autograd/variable.h>
4+ #include < torch/csrc/autograd/function.h>
25#include < iostream>
36
47int main () {
58 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