52 auto to_lower = [](std::string s) {
53 std::transform(s.begin(), s.end(), s.begin(),
54 [](
unsigned char c) { return std::tolower(c); });
59 auto name = to_lower(model_path.stem().string());
60 if (name.find(
"sam3") != std::string::npos ||
61 name.find(
"sam2") != std::string::npos) {
62 reusex::info(
"Detected SAM3 model from path name: {}", model_path);
67 if (std::filesystem::is_directory(model_path)) {
68 for (
const auto &entry :
69 std::filesystem::directory_iterator(model_path)) {
70 auto stem = to_lower(entry.path().stem().string());
71 if (stem.find(
"vision-encoder") != std::string::npos) {
73 "Detected SAM3 model from sub-model file: {}", entry.path());
79 reusex::info(
"Defaulting to YOLO model type for path: {}",
89 using namespace std::filesystem;
91 if (is_regular_file(model_path))
92 return detect_backend_from_file(model_path);
94 if (is_directory(model_path))
95 for (
const auto &entry : directory_iterator(model_path))
96 if (entry.is_regular_file())
97 if (
auto backend = detect_backend_from_file(entry.path());
114 throw std::runtime_error(
"OpenCV backend not implemented");
117#ifdef REUSEX_USE_TENSORRT
118 return std::make_unique<reusex::vision::tensor_rt::TensorRTBackend>();
120 reusex::error(
"TensorRT backend not compiled in this build. "
121 "Rebuild with -DML_BACKENDS=TensorRT or AUTO.");
122 throw std::runtime_error(
"TensorRT backend not available");
126#ifdef REUSEX_USE_LIBTORCH
127 return std::make_unique<reusex::vision::libtorch::LibTorchBackend>();
129 reusex::error(
"LibTorch backend not compiled in this build. "
130 "Rebuild with -DML_BACKENDS=LibTorch or AUTO.");
131 throw std::runtime_error(
"LibTorch backend not available");
136 throw std::runtime_error(
"DNN backend not implemented");
139#ifdef REUSEX_USE_ONNX
140 return std::make_unique<reusex::vision::onnx::ONNXBackend>();
142 reusex::error(
"ONNX Runtime backend is not implemented yet.");
143 throw std::runtime_error(
"ONNX Runtime backend not implemented");
147#ifdef REUSEX_USE_OPENVINO
148 return std::make_unique<reusex::vision::openvino::OpenVINOBackend>();
151 throw std::runtime_error(
"OpenVINO backend not implemented");
156 static_cast<int>(type));
157 throw std::runtime_error(
"Unsupported backend");