This use the libtorch
to create a simple circle predictor just as an example.This is not a perfect network, but feel free to imptove it..
In this example, the network is fed an X value/point from the cartesian coordinate system. The results is the Y point and its opposite point in the circle.
- Clone the repo:
git clone https://github.com/mjshakir/circle_predictor.git
- Pull the submodules:
git pull --recurse-submodules
- A shortcut is to clone with submodules
git clone https://github.com/mjshakir/circle_predictor.git --recurse-submodules
- Go to PyTorch to get
libtorch
- Unziping
sudo apt-get install -y unzip
unzip path/to/libtorch.zip
- Copy
libtorch
to the project folder
cp -r ~/path/to/libtorch ~/path/to/external_library/circle_predictor
- Folder system should look like
circle_predictor/
├── CMakeLists.txt
├── external_library
└── libtorch
├── include
├── main
└── src
- Create a build folder
~/path/to/circle_predictor/; mkdir build; cd build
- Get Ninja:
sudo apt-get install -y ninja-build
- Build Ninja:
cmake -DCMAKE_BUILD_TYPE=release .. -G Ninja
- Build Ninja using
CLang
:
cmake -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_BUILD_TYPE=release .. -G Ninja
- Build the project:
ninja
- Build Ninja:
cmake -DUSE_TTB=OFF -DCMAKE_BUILD_TYPE=release .. -G Ninja
- Build Ninja using
CLang
:
cmake -DUSE_TTB=OFF -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_BUILD_TYPE=release .. -G Ninja
- Build the project:
ninja
- Run: (Reminder: be in
~/path/to/circle_predictor/build/
)
./bin/circle_predictor
-h
or--help
:- Display options and description:
-s
or--filename
: defaulttest_results
- Save the results of the test data in
csv
file.
- Save the results of the test data in
-t
or---training_size
: default100
- How many different points to train
- Accepts an integer
x > 0
-g
or--generated_size
: default10000
- How many points generated
- Accepts an integer
x >= 100
-b
or--batch_size
: default20
- Batch the generated data to train
- Limitations:
- Accept an unsigned integer
x > 0
- Must be less then the
generated_size
- Must be less the
1000
this alibtorch
limitation
- Accept an unsigned integer
-u
or--use_epoch
: defaultfalse
- Train with an epoch iterations or validation precision
-p
or--precision
: default2.5E-1L
- Determine when to stop the training. This uses a validation set.
-e
or--epoch
: default20
- How many iteration to train.
- With precision and validation:
./bin/circle_predictor precision_results 10 1200 false 1E-2
- With Epoch iteration:
./bin/circle_predictor epoch_results 10 1200 true 10