Building Torchvision C++ API from source

I have been trying to build torchvision from source (master) on Windows 10. I cannot get past the cmake step. I see there is a dependency on the Torch package and cmake specifically asks for TorchConfig.cmake or torch-config.cmake. I have gotten this to work in the past by explicitly passing in --DCMAKE_PREFIX_PATH=“C:\Path\To\Torch” but most recently this has not worked for me. Can the prebuilt windows binary for Torch satisfy this cmake requirement? Can the Python package for Torch satisfy it? What is the actual path I need to supply to make this work? Is it looking for the torch.dll or torch.lib or something?

If you want to invoke the cmake script here, I think LibTorch is sufficient. Here is what I have done to make it work:

  1. Download https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-1.4.0.zip and extract to D:\libtorch
  2. Clone pybind11 and install to D:\pybind11
git clone https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake -DPYBIND11_TEST=OFF -DCMAKE_INSTALL_PREFIX="D:\pybind11" ..
  1. Clone torchvision and build
git clone https://github.com/pytorch/vision.git
cd vision
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="D:\libtorch;D:\pybind11" ..
1 Like

Thanks Pu Jiachen. I had to modify that a little for my particular case to work. What ended up working for me was

cmake -DCMAKE_PREFIX_PATH=“D:/path/to/libtorch” -Dpybind11_DIR=“D:/path/to/pybind11/share/cmake/pybind11” … -G “Visual Studio 15 2017 Win64”

Hi,

have tried to build Torchvision using cmake in windows10.

Torch 1.11, cuda 11.3, cuDNN v8.3.3

able to go through cmake process but after I click on torchvision.sln and using visual studio 2019 to build, the following error appears

Severity Code Description Project File Line Suppression State
Error C2664 ‘void jpeg_mem_dest(j_compress_ptr,unsigned char **,unsigned long *)’: cannot convert argument 3 from ‘vision::image::JpegSizeType *’ to ‘unsigned long *’ torchvision C:\vision\torchvision\csrc\io\image\cpu\encode_jpeg.cpp 87

I have installed jpeg using
.\vcpkg install --triplet x64-windows libjpeg-turbo

the following files are created
o Jpeg.lib in C:\vcpkg\installed\x64-windows\lib
o Jpeg62.dll in C:\vcpkg\installed\x64-windows\bin

possible to help?