Skip to content

Commit a0ff412

Browse files
committed
Remove input shape
1 parent 2ea11d1 commit a0ff412

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/cpp/include/tasks/anomaly.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class Anomaly {
1818
std::shared_ptr<InferenceAdapter> adapter;
1919
VisionPipeline<AnomalyResult> pipeline;
2020

21-
Anomaly(std::shared_ptr<InferenceAdapter> adapter, cv::Size input_shape)
22-
: adapter(adapter),
23-
input_shape(input_shape) {
21+
Anomaly(std::shared_ptr<InferenceAdapter> adapter) : adapter(adapter) {
2422
pipeline = VisionPipeline<AnomalyResult>(
2523
adapter,
2624
[&](cv::Mat image) {
@@ -36,9 +34,11 @@ class Anomaly {
3634
normalization_scale = utils::get_from_any_maps("normalization_scale", config, {}, normalization_scale);
3735
task = utils::get_from_any_maps("pixel_threshold", config, {}, task);
3836
labels = utils::get_from_any_maps("labels", config, {}, labels);
37+
input_shape.width = utils::get_from_any_maps("orig_width", config, {}, input_shape.width);
38+
input_shape.height = utils::get_from_any_maps("orig_height", config, {}, input_shape.height);
3939
}
4040

41-
static cv::Size serialize(std::shared_ptr<ov::Model>& ov_model);
41+
static void serialize(std::shared_ptr<ov::Model>& ov_model);
4242
static Anomaly load(const std::string& model_path);
4343

4444
AnomalyResult infer(cv::Mat image);

src/cpp/src/tasks/anomaly.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "utils/preprocessing.h"
55
#include "utils/tensor.h"
66

7-
cv::Size Anomaly::serialize(std::shared_ptr<ov::Model>& ov_model) {
7+
void Anomaly::serialize(std::shared_ptr<ov::Model>& ov_model) {
88
auto input = ov_model->inputs().front();
99

1010
auto layout = ov::layout::get_layout(input);
@@ -42,7 +42,8 @@ cv::Size Anomaly::serialize(std::shared_ptr<ov::Model>& ov_model) {
4242
mean_values,
4343
scale_values);
4444

45-
return cv::Size(input_shape[0], input_shape[1]);
45+
ov_model->set_rt_info(input_shape[0], "model_info", "orig_width");
46+
ov_model->set_rt_info(input_shape[1], "model_info", "orig_height");
4647
}
4748

4849
Anomaly Anomaly::load(const std::string& model_path) {
@@ -56,16 +57,14 @@ Anomaly Anomaly::load(const std::string& model_path) {
5657
throw std::runtime_error("Incorrect or unsupported model_type");
5758
}
5859

59-
cv::Size origin_input_shape;
6060
if (utils::model_has_embedded_processing(model)) {
6161
std::cout << "model already was serialized" << std::endl;
62-
origin_input_shape = utils::get_input_shape_from_model_info(model);
6362
} else {
64-
origin_input_shape = serialize(model);
63+
serialize(model);
6564
}
6665
auto adapter = std::make_shared<OpenVINOInferenceAdapter>();
6766
adapter->loadModel(model, core, "AUTO");
68-
return Anomaly(adapter, origin_input_shape);
67+
return Anomaly(adapter);
6968
}
7069

7170
AnomalyResult Anomaly::infer(cv::Mat image) {

0 commit comments

Comments
 (0)