Hi, all, I tried to extend C++ ops for pytorch follow this tutorial https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html. But I got this error, "op.cpp:17:50: error: ‘class at::Tensor’ has no member named ‘ptr’ ".
what I do as follow:
- download pytorch C++ form https://download.pytorch.org/libtorch/cu90/libtorch-shared-with-deps-latest.zip
- add a cmake to find the lib and include directory as this file:
include(FindPackageHandleStandardArgs)
set(TORCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libtorch/include)
find_library(TORCH_LIBRARY
NAMES torch
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/libtorch/lib NO_DEFAULT_PATH)
find_package_handle_standard_args(torch TORCH_INCLUDE_DIR TORCH_LIBRARY)
- in CMakeList, I add like these:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(warp_perspective)
add_compile_options(-std=c++11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
include_directories(
        "${TORCH_INCLUDE_DIR}"
)
# Define our library target
add_library(warp_perspective SHARED op.cpp)
# Enable C++11
target_compile_features(warp_perspective PRIVATE cxx_range_for)
# Link against LibTorch
target_link_libraries(warp_perspective "${TORCH_LIBRARIES}")
# Link against OpenCV
target_link_libraries(warp_perspective opencv_core opencv_imgproc)
- then the compile error show
op.cpp:17:50: error: ‘class at::Tensor’ has no member named ‘ptr’