File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed
Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 99### [ Using libcurl to download an image and stb to read it] ( libcurl/download_image )
1010
1111### [ Using libcurl to download an image and stb to read it (color version with fmt)] ( libcurl/ascii_art_color )
12+
13+ ### [ Using libtorch] ( libtorch/regression )
Original file line number Diff line number Diff line change 1+ ## Libtorch example with Conan
2+
3+ This example shows how to use Libtorch with Conan package manager to build a simple regression model.
4+
5+ The regression source code is not hosted in this repository,
6+ we use [ the official PyTorch examples repository] ( https://github.com/pytorch/examples/tree/main/cpp/regression ) ,
7+ so make sure to clone it first and then navigate to the ` cpp/regression ` folder:
8+
9+ ``` bash
10+ $ git clone https://github.com/pytorch/examples/tree/main/cpp/regression
11+ $ cd cpp/regression
12+ ```
13+
14+ Then, copy the ` conanfile.txt ` from this directory to the ` cpp/regression ` folder,
15+ and finally run Conan and CMake as usual:
16+
17+ ``` bash
18+ $ conan install --build=missing
19+ $ cmake --preset conan-release # conan-default for Windows
20+ $ cmake --build --preset conan-release
21+ $ ./build/Release/regression
22+ ```
Original file line number Diff line number Diff line change 1+ import platform
2+ import shutil
3+
4+ from test .examples_tools import run , chdir
5+
6+ print ("Libtorch regression example with Conan" )
7+
8+ run ("git clone --depth 1 https://github.com/pytorch/examples.git" )
9+ shutil .copy ("conanfile.txt" , "examples/cpp/regression/conanfile.txt" )
10+
11+ with chdir ("examples/cpp/regression" ):
12+ cppstd = "17" if platform .system () == "Windows" else "gnu17"
13+ run (f"conan install -b=missing -s compiler.cppstd={ cppstd } --update" )
14+
15+ if platform .system () == "Windows" :
16+ run ("cmake --preset conan-default" )
17+ # Don't build on Windows. CI's msvc can't build this
18+ else :
19+ run ("cmake --preset conan-release" )
20+ run ("cmake --build --preset conan-release" )
21+
22+ # Only execute this in macos in the CI, there are some issues with the generated binary and the
23+ # GitHub images
24+ if platform .system () == "Darwin" :
25+ run ("./build/Release/regression" )
26+
Original file line number Diff line number Diff line change 1+ [requires]
2+ libtorch/[*]
3+
4+ [generators]
5+ CMakeToolchain
6+ CMakeDeps
7+
8+ [layout]
9+ cmake_layout
You can’t perform that action at this time.
0 commit comments