gpt4 book ai didi

c++ - 尝试构建 torch 脚本扩展导致 INVALID TYPE : Only int64_t and bool are supported as an integral argument type error

转载 作者:行者123 更新时间:2023-12-03 07:01:01 24 4
gpt4 key购买 nike

我正在关注 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
这里有什么问题?

最佳答案

这个错误有点误导!所需要的只是转换来自 int 的所有返回类型至 int64_t就是这样。现在所有编译都很好!

关于c++ - 尝试构建 torch 脚本扩展导致 INVALID TYPE : Only int64_t and bool are supported as an integral argument type error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63763112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com