2

我正在关注torch_script_custom_classes以便在 Python 中公开我的 C++ dll。我目前拥有的大部分代码如下:

#include <torch/script.h>
#include <string>
#include <vector>
struct PyManager : torch::CustomClassHolder {
       PyManager(std::string model_path, 
                 std::string img_bank_folder_root, 
                 std::string cache_folder,
                 std::string pnet, 
                 std::string rnet, 
                 std::string onet, 
                 bool rebuildCache) {

                std::cout << "ok!";
       }

    int AddUser(std::string user_id, std::string img_fldr_path) { 
       std::cout << user_id << img_fldr_path;
       return 0;
    }
    int RemoveUser(std::string user_id) { 
       std::cout << user_id; 
       return 0;
    }
    int UpdateUser(std::string user_id, std::string new_images_folder_path) { 
        std::cout << user_id << new_images_folder_path; 
        return 0;
    }
    int RenameId(std::string old_id, std::string new_id) { 
        std::cout << old_id << new_id; 
        return 0;
    }
    int UpdateUsersInBulk(std::vector<std::string> userIDs, 
                          std::string ID_folders_path, 
                          bool is_delete_granted = true, bool show_dbg_info = true) {
           std::cout << userIDs.size() << ID_folders_path; 
           return 0;
      }


};

TORCH_LIBRARY(my_classes, m) {
              m.class_<PyManager>("PyManager")
        .def(torch::init<std::string, std::string, std::string, std::string, std::string, std::string, bool>())
        .def("add", &PyManager::AddUser)
        .def("remove", &PyManager::RemoveUser)
        .def("update", &PyManager::UpdateUser)
        .def("update_in_bulk", &PyManager::UpdateUsersInBulk);
}

这是我使用的 cmake 文件:

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(custom_class)

find_package(Torch REQUIRED)

# Define our library target
add_library(custom_class SHARED class1.cpp)

#define our c++ standard
set(CMAKE_CXX_STANDARD 17)
# Link against LibTorch
target_link_libraries(custom_class "${TORCH_LIBRARIES}")

我这样称呼cmake:

cmake -DCMAKE_PREFIX_PATH="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" ..

但我收到以下错误:

Severity    Code    Description Project File    Line    Suppression State
Error   C2338   INVALID TYPE: Only int64_t and bool are supported as an integral argument type  custom_class    ...\libtorch-debug-latest\libtorch\include\ATen\core\op_registration\infer_schema.h 39  

这里有什么问题?

4

1 回答 1

2

这个错误有点误导!所需要的只是将所有返回类型从intto转换int64_t,仅此而已。现在所有编译都很好!

于 2020-09-19T09:30:05.273 回答