# Detectron2 in C++

**URL:** <https://discuss.pytorch.org/t/detectron2-in-c/153369>\
**Category:** Uncategorized\
**Created:** [June 5, 2022, 2:49pm UTC](https://discuss.pytorch.org/t/detectron2-in-c/153369 "2022-06-05T14:49:02Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![KRG](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/krg/32/42202_2.png) [@KRG](https://discuss.pytorch.org/u/KRG)\
**Post date:** [November 16, 2022, 2:11am UTC](https://discuss.pytorch.org/t/detectron2-in-c/153369/3 "2022-11-16T02:11:22Z")

</div>

You will have to build the touch vision c++. Please refer - [Building Torchvision C++ API from source](https://discuss.pytorch.org/t/building-torchvision-c-api-from-source/68281)

Below is a sample of commands I used in Windows using anaconda.

- Clone pybind11 and install to C:\pybind11

```auto
    git clone https://github.com/pybind/pybind11.git
    cd pybind11
    mkdir build
    cd build
    cmake -DPYBIND11_TEST=OFF -DCMAKE_INSTALL_PREFIX="C:\Users\pybind11" ..

```

- Clone torchvision

```auto
   git clone https://github.com/pytorch/vision.git

```

- Cmake the project.

```auto
    cd vision
    mkdir build
    cd build    
    ## Enable CUDA. 
    cmake -DWITH_CUDA=on -DUSE_PYTHON=on -DCMAKE_PREFIX_PATH="C:\libtorch-win-shared-with-deps-1.10.2+cu113\libtorch;C:\Users\pybind11" -DCMAKE_BUILD_TYPE=Release ..

```

- Create torchvison dll file : cd C:\Users\user\vision\build and open torchvision.sln using Visual Studio. Build the ‘tourchvision’ project to create DLL file. DLL file ‘torchvision.dll’ is created in '.\Release' folder.

- Install C++ files : cd C:\Users\user\vision\build and install torchvision c++ using ‘cmake -P cmake\_install.cmake’. C++ files will be created in C:\Program Files (x86)\torchvision.

---

_[View the full topic](https://discuss.pytorch.org/t/detectron2-in-c/153369)._
