mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* minor changes * support windows * fix GCC build * fix lint * reformat * fix Windows build * fix GCC build * search backend ops for onnxruntime * fix lint * fix lint * code clean-up * code clean-up * fix clang build * fix trt support * fix cmake for ncnn * fix cmake for openvino * fix SDK Python API * handle ops for other backends (ncnn, trt) * handle SDK Python API library location * robustify linkage * fix cuda * minor fix for openvino & ncnn * use CMAKE_CUDA_ARCHITECTURES if set * fix cuda preprocessor * fix misc * fix pplnn & pplcv, drop support for pplcv<0.6.0 * robustify cmake * update build.md (#2) * build dynamic modules as module library & fix demo (partially) * fix candidate path for mmdeploy_python * move "enable CUDA" to cmake config for demo * refine demo cmake * add comment * fix ubuntu build * revert docs/en/build.md * fix C API * fix lint * Windows build doc (#3) * check in docs related to mmdeploy build on windows * update build guide on windows platform * update build guide on windows platform * make path of thirdparty libraries consistent * make path consistency * correct build command for custom ops * correct build command for sdk * update sdk build instructions * update doc * correct build command * fix lint * correct build command and fix lint Co-authored-by: lvhan <lvhan@pjlab.org> * trailing whitespace (#4) * minor fix * fix sr sdk model * fix type deduction * fix cudaFree after driver shutting down * update ppl.cv installation warning (#5) * fix device allocator threshold & fix lint * update doc (#6) * update ppl.cv installation warning * missing 'git clone' Co-authored-by: chenxin <chenxin2@sensetime.com> Co-authored-by: zhangli <zhangli@sensetime.com> Co-authored-by: lvhan028 <lvhan_028@163.com> Co-authored-by: lvhan <lvhan@pjlab.org>
69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#include <fstream>
|
|
|
|
#include "archive/json_archive.h"
|
|
#include "core/model.h"
|
|
#include "core/model_impl.h"
|
|
#include "core/utils/filesystem.h"
|
|
|
|
using nlohmann::json;
|
|
|
|
namespace mmdeploy {
|
|
|
|
class DirectoryModelImpl : public ModelImpl {
|
|
public:
|
|
DirectoryModelImpl() = default;
|
|
|
|
Result<void> Init(const std::string& sdk_model_path) override {
|
|
auto path = fs::path{sdk_model_path};
|
|
if (!is_directory(path)) {
|
|
return Status(eInvalidArgument);
|
|
}
|
|
root_ = fs::path{sdk_model_path};
|
|
return success();
|
|
}
|
|
|
|
Result<std::string> ReadFile(const std::string& file_path) const override {
|
|
auto _path = root_ / fs::path(file_path);
|
|
std::ifstream ifs(_path, std::ios::binary | std::ios::in);
|
|
if (!ifs.is_open()) {
|
|
return Status(eFail);
|
|
}
|
|
ifs.seekg(0, std::ios::end);
|
|
auto size = ifs.tellg();
|
|
ifs.seekg(0, std::ios::beg);
|
|
std::string str(size, '\0');
|
|
ifs.read(str.data(), size);
|
|
return str;
|
|
}
|
|
|
|
Result<deploy_meta_info_t> ReadMeta() const override {
|
|
OUTCOME_TRY(auto deploy_json, ReadFile("deploy.json"));
|
|
try {
|
|
deploy_meta_info_t meta;
|
|
from_json(json::parse(deploy_json), meta);
|
|
return meta;
|
|
} catch (std::exception& e) {
|
|
MMDEPLOY_ERROR("exception happened: {}", e.what());
|
|
return Status(eFail);
|
|
}
|
|
}
|
|
|
|
private:
|
|
fs::path root_;
|
|
};
|
|
|
|
class DirectoryModelRegister {
|
|
public:
|
|
DirectoryModelRegister() {
|
|
(void)ModelRegistry::Get().Register("DirectoryModel", []() -> std::unique_ptr<ModelImpl> {
|
|
return std::make_unique<DirectoryModelImpl>();
|
|
});
|
|
}
|
|
};
|
|
|
|
static DirectoryModelRegister directory_model_register;
|
|
|
|
} // namespace mmdeploy
|