Skip to content

Commit 8f76b40

Browse files
committed
Cleanup
1 parent f9ac4f4 commit 8f76b40

File tree

8 files changed

+21
-58
lines changed

8 files changed

+21
-58
lines changed

src/cpp/include/adapters/inference_adapter.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@ class InferenceAdapter {
3131
virtual void awaitAll() = 0;
3232
virtual void awaitAny() = 0;
3333
virtual size_t getNumAsyncExecutors() const = 0;
34-
virtual void loadModel(const std::shared_ptr<const ov::Model>& model,
35-
ov::Core& core,
34+
virtual void loadModel(const std::string& modelPath,
3635
const std::string& device = "",
37-
const ov::AnyMap& compilationConfig = {},
38-
size_t max_num_requests = 0) = 0;
39-
virtual void loadModelFile(const std::string& modelPath,
40-
const std::string& device = "",
41-
const ov::AnyMap& adapterConfig = {},
42-
bool preCompile = true) = 0;
36+
const ov::AnyMap& adapterConfig = {},
37+
bool preCompile = true) = 0;
4338
virtual void compileModel(const std::string& device = "", const ov::AnyMap& adapterConfig = {}) = 0;
4439
virtual ov::PartialShape getInputShape(const std::string& inputName) const = 0;
4540
virtual ov::PartialShape getOutputShape(const std::string& inputName) const = 0;

src/cpp/include/adapters/openvino_adapter.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ class OpenVINOInferenceAdapter : public InferenceAdapter {
2525
virtual bool isReady();
2626
virtual void awaitAll();
2727
virtual void awaitAny();
28-
virtual void loadModel(const std::shared_ptr<const ov::Model>& model,
29-
ov::Core& core,
28+
virtual void loadModel(const std::string& modelPath,
3029
const std::string& device = "",
31-
const ov::AnyMap& compilationConfig = {},
32-
size_t max_num_requests = 1) override;
33-
virtual void loadModelFile(const std::string& modelPath,
34-
const std::string& device = "",
35-
const ov::AnyMap& adapterConfig = {},
36-
bool preCompile = true) override;
30+
const ov::AnyMap& adapterConfig = {},
31+
bool preCompile = true) override;
3732
virtual void compileModel(const std::string& device = "", const ov::AnyMap& adapterConfig = {}) override;
3833
virtual size_t getNumAsyncExecutors() const;
3934
virtual ov::PartialShape getInputShape(const std::string& inputName) const override;
@@ -44,7 +39,7 @@ class OpenVINOInferenceAdapter : public InferenceAdapter {
4439
virtual std::vector<std::string> getOutputNames() const override;
4540
virtual const ov::AnyMap& getModelConfig() const override;
4641

47-
void applyModelTransform(std::function<void(std::shared_ptr<ov::Model>&)> func);
42+
void applyModelTransform(std::function<void(std::shared_ptr<ov::Model>&)> t);
4843

4944
protected:
5045
void initInputsOutputs();

src/cpp/src/adapters/openvino_adapter.cpp

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,6 @@
1111

1212
#include "utils/config.h"
1313

14-
void OpenVINOInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>& model,
15-
ov::Core& core,
16-
const std::string& device,
17-
const ov::AnyMap& compilationConfig,
18-
size_t max_num_requests) {
19-
ov::AnyMap customCompilationConfig(compilationConfig);
20-
if (max_num_requests != 1) {
21-
if (customCompilationConfig.find("PERFORMANCE_HINT") == customCompilationConfig.end()) {
22-
customCompilationConfig["PERFORMANCE_HINT"] = ov::hint::PerformanceMode::THROUGHPUT;
23-
}
24-
if (max_num_requests > 0) {
25-
if (customCompilationConfig.find("PERFORMANCE_HINT_NUM_REQUESTS") == customCompilationConfig.end()) {
26-
customCompilationConfig["PERFORMANCE_HINT_NUM_REQUESTS"] = ov::hint::num_requests(max_num_requests);
27-
}
28-
}
29-
} else {
30-
if (customCompilationConfig.find("PERFORMANCE_HINT") == customCompilationConfig.end()) {
31-
customCompilationConfig["PERFORMANCE_HINT"] = ov::hint::PerformanceMode::LATENCY;
32-
}
33-
}
34-
35-
compiledModel = core.compile_model(model, device, customCompilationConfig);
36-
asyncQueue = std::make_unique<AsyncInferQueue>(compiledModel, max_num_requests);
37-
initInputsOutputs();
38-
39-
if (model->has_rt_info({"model_info"})) {
40-
modelConfig = model->get_rt_info<ov::AnyMap>("model_info");
41-
}
42-
}
43-
4414
void OpenVINOInferenceAdapter::compileModel(const std::string& device, const ov::AnyMap& adapterConfig) {
4515
if (!model) {
4616
throw std::runtime_error("Model is not loaded");
@@ -70,10 +40,10 @@ void OpenVINOInferenceAdapter::compileModel(const std::string& device, const ov:
7040
initInputsOutputs();
7141
}
7242

73-
void OpenVINOInferenceAdapter::loadModelFile(const std::string& modelPath,
74-
const std::string& device,
75-
const ov::AnyMap& adapterConfig,
76-
bool preCompile) {
43+
void OpenVINOInferenceAdapter::loadModel(const std::string& modelPath,
44+
const std::string& device,
45+
const ov::AnyMap& adapterConfig,
46+
bool preCompile) {
7747
ov::Core core;
7848
model = core.read_model(modelPath);
7949
if (model->has_rt_info({"model_info"})) {
@@ -84,11 +54,14 @@ void OpenVINOInferenceAdapter::loadModelFile(const std::string& modelPath,
8454
}
8555
}
8656

87-
void OpenVINOInferenceAdapter::applyModelTransform(std::function<void(std::shared_ptr<ov::Model>&)> func) {
57+
void OpenVINOInferenceAdapter::applyModelTransform(std::function<void(std::shared_ptr<ov::Model>&)> t) {
8858
if (!model) {
8959
throw std::runtime_error("Model is not loaded");
9060
}
91-
func(model);
61+
t(model);
62+
if (model->has_rt_info({"model_info"})) {
63+
modelConfig = model->get_rt_info<ov::AnyMap>("model_info");
64+
}
9265
}
9366

9467
void OpenVINOInferenceAdapter::infer(const InferenceInput& input, InferenceOutput& output) {

src/cpp/src/tasks/anomaly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void Anomaly::serialize(std::shared_ptr<ov::Model>& ov_model) {
5353

5454
Anomaly Anomaly::load(const std::string& model_path) {
5555
auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
56-
adapter->loadModelFile(model_path, "", {}, false);
56+
adapter->loadModel(model_path, "", {}, false);
5757

5858
std::string model_type;
5959
model_type = utils::get_from_any_maps("model_type", adapter->getModelConfig(), {}, model_type);

src/cpp/src/tasks/classification.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void Classification::serialize(std::shared_ptr<ov::Model>& ov_model) {
182182

183183
Classification Classification::load(const std::string& model_path) {
184184
auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
185-
adapter->loadModelFile(model_path, "", {}, false);
185+
adapter->loadModel(model_path, "", {}, false);
186186

187187
std::string model_type;
188188
model_type = utils::get_from_any_maps("model_type", adapter->getModelConfig(), {}, model_type);

src/cpp/src/tasks/detection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
DetectionModel DetectionModel::load(const std::string& model_path, const ov::AnyMap& configuration) {
1515
auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
16-
adapter->loadModelFile(model_path, "", {}, false);
16+
adapter->loadModel(model_path, "", {}, false);
1717

1818
std::string model_type;
1919
model_type = utils::get_from_any_maps("model_type", adapter->getModelConfig(), {}, model_type);

src/cpp/src/tasks/instance_segmentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void InstanceSegmentation::serialize(std::shared_ptr<ov::Model>& ov_model) {
192192

193193
InstanceSegmentation InstanceSegmentation::load(const std::string& model_path) {
194194
auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
195-
adapter->loadModelFile(model_path, "", {}, false);
195+
adapter->loadModel(model_path, "", {}, false);
196196

197197
std::string model_type;
198198
model_type = utils::get_from_any_maps("model_type", adapter->getModelConfig(), {}, model_type);

src/cpp/src/tasks/semantic_segmentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cv::Mat get_activation_map(const cv::Mat& features) {
2222

2323
SemanticSegmentation SemanticSegmentation::load(const std::string& model_path) {
2424
auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
25-
adapter->loadModelFile(model_path, "", {}, false);
25+
adapter->loadModel(model_path, "", {}, false);
2626

2727
std::string model_type;
2828
model_type = utils::get_from_any_maps("model_type", adapter->getModelConfig(), {}, model_type);

0 commit comments

Comments
 (0)