Skip to content

Commit cea8b00

Browse files
committed
Satisfy pre-commit checks
1 parent b3bef98 commit cea8b00

File tree

26 files changed

+314
-302
lines changed

26 files changed

+314
-302
lines changed

.github/workflows/test_accuracy.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ jobs:
4444
pip install typing_extensions==4.12.2
4545
cmake ../tests/cpp/accuracy/
4646
make -j
47-
- name: Build CPP-PY Bindings
48-
run: |
49-
source venv/bin/activate
50-
pip install src/cpp/py_bindings
5147
- name: Run CPP Test
5248
run: |
5349
build/test_accuracy -d data -p tests/python/accuracy/public_scope.json
54-
- name: Run CPP-PY Bindings Test
55-
run: |
56-
source venv/bin/activate
57-
pip list
58-
pytest --data=./data --config=./tests/python/accuracy/public_scope.json tests/cpp/accuracy/test_bindings.py

examples/cpp/asynchronous_api/main.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
#include <adapters/openvino_adapter.h>
6+
#include <stddef.h>
67
#include <tasks/detection.h>
78
#include <tasks/results.h>
8-
#include <stddef.h>
99

1010
#include <cstdint>
1111
#include <exception>
@@ -31,20 +31,7 @@ int main(int argc, char* argv[]) try {
3131

3232
// Instantiate Object Detection model
3333
auto model = DetectionModel::load(argv[1], {}); // works with SSD models. Download it using Python Model API
34-
//// Define number of parallel infer requests. Is this number is set to 0, OpenVINO will determine it automatically to
35-
//// obtain optimal performance.
36-
//size_t num_requests = 0;
37-
//static ov::Core core;
38-
//model->load(core, "CPU", num_requests);
39-
40-
//std::cout << "Async inference will be carried out by " << model->getNumAsyncExecutors() << " parallel executors\n";
41-
//// Prepare batch data
4234
std::vector<cv::Mat> data = {image};
43-
//for (size_t i = 0; i < 3; i++) {
44-
// data.push_back(ImageInputData(image));
45-
//}
46-
47-
// Batch inference is done by processing batch with num_requests parallel infer requests
4835
std::cout << "Starting batch inference\n";
4936
auto results = model.inferBatch(data);
5037

examples/cpp/synchronous_api/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
#include <stddef.h>
67
#include <tasks/detection.h>
78
#include <tasks/results.h>
8-
#include <stddef.h>
99

1010
#include <cstdint>
1111
#include <exception>

src/cpp/include/tasks/detection.h

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,66 @@
11
#pragma once
22

3-
#include <string>
43
#include <opencv2/opencv.hpp>
54
#include <openvino/openvino.hpp>
5+
#include <string>
6+
67
#include "adapters/inference_adapter.h"
78
#include "tasks/detection/ssd.h"
89
#include "tasks/results.h"
9-
#include "utils/vision_pipeline.h"
1010
#include "utils/tiling.h"
11+
#include "utils/vision_pipeline.h"
1112

1213
class DetectionModel {
1314
public:
1415
std::unique_ptr<Pipeline<DetectionResult>> pipeline;
1516

16-
DetectionModel(std::unique_ptr<SSD> algorithm, const ov::AnyMap& configuration): algorithm(std::move(algorithm)) {
17+
DetectionModel(std::unique_ptr<SSD> algorithm, const ov::AnyMap& configuration) : algorithm(std::move(algorithm)) {
1718
auto config = this->algorithm->adapter->getModelConfig();
1819
if (configuration.count("tiling") && configuration.at("tiling").as<bool>()) {
1920
if (!utils::config_contains_tiling_info(config)) {
2021
throw std::runtime_error("Model config does not contain tiling properties.");
2122
}
22-
pipeline = std::make_unique<TilingPipeline<DetectionResult>>(this->algorithm->adapter,
23+
pipeline = std::make_unique<TilingPipeline<DetectionResult>>(
24+
this->algorithm->adapter,
2325
utils::get_tiling_info_from_config(config),
24-
[&](cv::Mat image) { return preprocess(image);},
25-
[&](InferenceResult result) { return postprocess(result);},
26-
[&](DetectionResult& result, const cv::Rect& coord) { return postprocess_tile(result, coord);},
27-
[&](const std::vector<DetectionResult>& tiles_results, const cv::Size& image_size, const std::vector<cv::Rect>& tile_coords, const utils::TilingInfo& tiling_info) { return merge_tiling_results(tiles_results, image_size, tile_coords, tiling_info);}
28-
);
26+
[&](cv::Mat image) {
27+
return preprocess(image);
28+
},
29+
[&](InferenceResult result) {
30+
return postprocess(result);
31+
},
32+
[&](DetectionResult& result, const cv::Rect& coord) {
33+
return postprocess_tile(result, coord);
34+
},
35+
[&](const std::vector<DetectionResult>& tiles_results,
36+
const cv::Size& image_size,
37+
const std::vector<cv::Rect>& tile_coords,
38+
const utils::TilingInfo& tiling_info) {
39+
return merge_tiling_results(tiles_results, image_size, tile_coords, tiling_info);
40+
});
2941
} else {
30-
pipeline = std::make_unique<VisionPipeline<DetectionResult>>(this->algorithm->adapter,
31-
[&](cv::Mat image) { return preprocess(image);},
32-
[&](InferenceResult result) { return postprocess(result);}
33-
);
42+
pipeline = std::make_unique<VisionPipeline<DetectionResult>>(
43+
this->algorithm->adapter,
44+
[&](cv::Mat image) {
45+
return preprocess(image);
46+
},
47+
[&](InferenceResult result) {
48+
return postprocess(result);
49+
});
3450
}
3551
}
3652

3753
InferenceInput preprocess(cv::Mat);
3854
DetectionResult postprocess(InferenceResult);
3955
DetectionResult postprocess_tile(DetectionResult& result, const cv::Rect& coord);
40-
DetectionResult merge_tiling_results(const std::vector<DetectionResult>& tiles_results, const cv::Size& image_size, const std::vector<cv::Rect>& tile_coords, const utils::TilingInfo& tiling_info);
41-
ov::Tensor merge_saliency_maps(const std::vector<DetectionResult>& tiles_results, const cv::Size& image_size, const std::vector<cv::Rect>& tile_coords, const utils::TilingInfo& tiling_info);
56+
DetectionResult merge_tiling_results(const std::vector<DetectionResult>& tiles_results,
57+
const cv::Size& image_size,
58+
const std::vector<cv::Rect>& tile_coords,
59+
const utils::TilingInfo& tiling_info);
60+
ov::Tensor merge_saliency_maps(const std::vector<DetectionResult>& tiles_results,
61+
const cv::Size& image_size,
62+
const std::vector<cv::Rect>& tile_coords,
63+
const utils::TilingInfo& tiling_info);
4264

4365
static DetectionModel load(const std::string& model_path, const ov::AnyMap& configuration = {});
4466

src/cpp/include/tasks/detection/ssd.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#pragma once
22

33
#include <openvino/openvino.hpp>
4+
45
#include "adapters/inference_adapter.h"
5-
#include "utils/preprocessing.h"
66
#include "tasks/results.h"
7+
#include "utils/preprocessing.h"
78

8-
enum SSDOutputMode {
9-
single,
10-
multi
11-
};
9+
enum SSDOutputMode { single, multi };
1210

1311
class NumAndStep {
1412
public:
@@ -24,7 +22,7 @@ class SSD {
2422
public:
2523
std::shared_ptr<InferenceAdapter> adapter;
2624

27-
SSD(std::shared_ptr<InferenceAdapter> adapter, cv::Size input_shape): adapter(adapter), input_shape(input_shape) {
25+
SSD(std::shared_ptr<InferenceAdapter> adapter, cv::Size input_shape) : adapter(adapter), input_shape(input_shape) {
2826
auto config = adapter->getModelConfig();
2927
{
3028
auto iter = config.find("labels");
@@ -47,6 +45,7 @@ class SSD {
4745
static cv::Size serialize(std::shared_ptr<ov::Model> ov_model);
4846

4947
SSDOutputMode output_mode;
48+
5049
private:
5150
static void prepareSingleOutput(std::shared_ptr<ov::Model> ov_model);
5251
static void prepareMultipleOutputs(std::shared_ptr<ov::Model> ov_model);
@@ -64,4 +63,4 @@ class SSD {
6463
ov::Layout layout;
6564
cv::InterpolationFlags interpolation_mode;
6665
cv::Size input_shape;
67-
};
66+
};

src/cpp/include/tasks/instance_segmentation.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
#pragma once
22

3-
#include <openvino/openvino.hpp>
43
#include <opencv2/opencv.hpp>
5-
#include "tasks/results.h"
4+
#include <openvino/openvino.hpp>
5+
66
#include "adapters/inference_adapter.h"
7+
#include "tasks/results.h"
78
#include "utils/vision_pipeline.h"
89

910
class InstanceSegmentation {
1011
public:
1112
std::shared_ptr<InferenceAdapter> adapter;
1213
VisionPipeline<InstanceSegmentationResult> pipeline;
1314

14-
InstanceSegmentation(std::shared_ptr<InferenceAdapter> adapter, cv::Size input_shape): adapter(adapter), input_shape(input_shape) {
15-
pipeline = VisionPipeline<InstanceSegmentationResult>(adapter,
16-
[&](cv::Mat image) { return preprocess(image);},
17-
[&](InferenceResult result) { return postprocess(result);}
18-
);
15+
InstanceSegmentation(std::shared_ptr<InferenceAdapter> adapter, cv::Size input_shape)
16+
: adapter(adapter),
17+
input_shape(input_shape) {
18+
pipeline = VisionPipeline<InstanceSegmentationResult>(
19+
adapter,
20+
[&](cv::Mat image) {
21+
return preprocess(image);
22+
},
23+
[&](InferenceResult result) {
24+
return postprocess(result);
25+
});
1926

2027
auto config = adapter->getModelConfig();
2128
auto iter = config.find("labels");
@@ -56,4 +63,4 @@ class InstanceSegmentation {
5663

5764
cv::Size input_shape;
5865
float confidence_threshold = 0.5f;
59-
};
66+
};

src/cpp/include/tasks/results.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#pragma once
22

3-
#include <openvino/openvino.hpp>
43
#include <opencv2/opencv.hpp>
4+
#include <openvino/openvino.hpp>
55

66
class InferenceResult {
77
public:
88
std::map<std::string, ov::Tensor> data;
99
cv::Size inputImageSize;
10-
1110
};
1211

1312
struct DetectedObject : public cv::Rect2f {
@@ -62,7 +61,6 @@ struct Contour {
6261
}
6362
};
6463

65-
6664
struct SemanticSegmentationResult {
6765
SemanticSegmentationResult() {}
6866
cv::Mat resultImage;
@@ -108,7 +106,6 @@ struct SemanticSegmentationResult {
108106
os << "[0]";
109107
}
110108
return os;
111-
112109
}
113110
explicit operator std::string() {
114111
std::stringstream ss;
@@ -139,7 +136,6 @@ struct SegmentedObjectWithRects : SegmentedObject {
139136
}
140137
};
141138

142-
143139
struct InstanceSegmentationResult {
144140
std::vector<SegmentedObject> segmentedObjects;
145141
std::vector<cv::Mat_<std::uint8_t>> saliency_map;

src/cpp/include/tasks/semantic_segmentation.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2-
#include <openvino/openvino.hpp>
32
#include <opencv2/opencv.hpp>
3+
#include <openvino/openvino.hpp>
44

55
#include "adapters/inference_adapter.h"
66
#include "tasks/results.h"
@@ -11,11 +11,15 @@ class SemanticSegmentation {
1111
public:
1212
VisionPipeline<SemanticSegmentationResult> pipeline;
1313
std::shared_ptr<InferenceAdapter> adapter;
14-
SemanticSegmentation(std::shared_ptr<InferenceAdapter> adapter): adapter(adapter) {
15-
pipeline = VisionPipeline<SemanticSegmentationResult>(adapter,
16-
[&](cv::Mat image) { return preprocess(image);},
17-
[&](InferenceResult result) { return postprocess(result);}
18-
);
14+
SemanticSegmentation(std::shared_ptr<InferenceAdapter> adapter) : adapter(adapter) {
15+
pipeline = VisionPipeline<SemanticSegmentationResult>(
16+
adapter,
17+
[&](cv::Mat image) {
18+
return preprocess(image);
19+
},
20+
[&](InferenceResult result) {
21+
return postprocess(result);
22+
});
1923

2024
auto config = adapter->getModelConfig();
2125
auto iter = config.find("labels");
@@ -38,7 +42,6 @@ class SemanticSegmentation {
3842
blur_strength = iter->second.as<int>();
3943
}
4044
}
41-
4245
}
4346

4447
static cv::Size serialize(std::shared_ptr<ov::Model>& ov_model);
@@ -52,10 +55,11 @@ class SemanticSegmentation {
5255
void inferAsync(cv::Mat image, ov::AnyMap user_data);
5356
void setCallback(std::function<void(SemanticSegmentationResult, ov::AnyMap)>);
5457
std::vector<SemanticSegmentationResult> inferBatch(std::vector<cv::Mat> image);
58+
5559
private:
5660
cv::Mat create_hard_prediction_from_soft_prediction(cv::Mat, float threshold, int blur_strength);
5761

58-
//from config
62+
// from config
5963
int blur_strength = -1;
6064
float soft_threshold = -std::numeric_limits<float>::infinity();
6165
bool return_soft_prediction = true;
@@ -65,4 +69,4 @@ class SemanticSegmentation {
6569
std::string getLabelName(size_t labelID) {
6670
return labelID < labels.size() ? labels[labelID] : std::string("Label #") + std::to_string(labelID);
6771
}
68-
};
72+
};

src/cpp/include/utils/config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <openvino/openvino.hpp>
43
#include <opencv2/opencv.hpp>
4+
#include <openvino/openvino.hpp>
55
namespace utils {
66
template <typename Type>
77
Type get_from_any_maps(const std::string& key,
@@ -76,7 +76,6 @@ IntervalCondition makeCond(Args&&... args) {
7676
}
7777
using LayoutCondition = std::tuple<size_t /*dim index*/, IntervalCondition, std::string>;
7878

79-
8079
static inline std::tuple<bool, ov::Layout> makeGuesLayoutFrom4DShape(const ov::PartialShape& shape) {
8180
// at the moment we make assumption about NCHW & NHCW only
8281
// if hypothetical C value is less than hypothetical H and W - then
@@ -129,4 +128,4 @@ static inline ov::Layout getLayoutFromShape(const ov::PartialShape& shape) {
129128
throw std::runtime_error("Usupported " + std::to_string(shape.size()) + "D shape");
130129
}
131130

132-
}
131+
} // namespace utils

src/cpp/include/utils/math.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <cmath>
43
#include <algorithm>
4+
#include <cmath>
55

66
inline float clamp_and_round(float val, float min, float max) {
77
return std::round(std::max(min, std::min(max, val)));
@@ -15,4 +15,4 @@ constexpr std::size_t arraySize(const T (&)[N]) noexcept {
1515
template <typename T>
1616
T clamp(T value, T low, T high) {
1717
return value < low ? low : (value > high ? high : value);
18-
}
18+
}

0 commit comments

Comments
 (0)