Skip to content

Commit a6b8956

Browse files
🛠️ Update Pre-Commit (#214)
* remove git based whitespace check Signed-off-by: Ashwin Vaidya <[email protected]> * add cpp pre-commit Signed-off-by: Ashwin Vaidya <[email protected]> * undo cppcheck remove Signed-off-by: Ashwin Vaidya <[email protected]> * update workflow to include clang-format install Signed-off-by: Ashwin Vaidya <[email protected]> * pin versions Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 903070f commit a6b8956

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1439
-1268
lines changed

.clang-format

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
UseTab: Never
4+
ColumnLimit: 120
5+
6+
Language: Cpp
7+
Standard: Cpp11
8+
9+
AccessModifierOffset: -4
10+
AlignConsecutiveMacros: true
11+
AllowAllArgumentsOnNextLine: false
12+
AllowAllConstructorInitializersOnNextLine: false
13+
AllowAllParametersOfDeclarationOnNextLine: false
14+
AllowShortFunctionsOnASingleLine: Empty
15+
AllowShortIfStatementsOnASingleLine: Never
16+
AllowShortLambdasOnASingleLine: Empty
17+
AllowShortLoopsOnASingleLine: false
18+
AlwaysBreakBeforeMultilineStrings: false
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
CommentPragmas: "^#"
22+
DerivePointerAlignment: false
23+
FixNamespaceComments: true
24+
IndentCaseLabels: false
25+
IndentPPDirectives: AfterHash
26+
ForEachMacros:
27+
- foreach
28+
- FOREACH_CHILD

.github/workflows/pre_commit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
uses: actions/setup-python@v5
2424
with:
2525
python-version: "3.10"
26+
- name: Install clang-format
27+
run: sudo apt-get install -y clang-format-10
2628
- name: Install dependencies
2729
run: pip install 'model_api/python/.[full]'
2830
- name: Run pre-commit checks

.github/workflows/test_precommit.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v3
12-
- name: git --no-pager diff --check $(git hash-object -t tree /dev/null)
13-
run: git --no-pager diff --check $(git hash-object -t tree /dev/null)
14-
- name: Prohibit non ASCII chars in file names
15-
run: test $(git diff --name-only --diff-filter=A -z $(git hash-object -t tree /dev/null) | LC_ALL=C tr -d '[ -~]\0' | wc -c) == 0
16-
- run: "! git grep -n '[^ -~]' -- ':(exclude)model_api/python/README.md'"
1712
- uses: actions/setup-python@v4
1813
with:
1914
python-version: 3.9

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ repos:
2222
rev: v0.41.0
2323
hooks:
2424
- id: markdownlint
25+
26+
# C++ code quality
27+
- repo: https://github.com/cpp-linter/cpp-linter-hooks
28+
rev: v0.5.1
29+
hooks:
30+
- id: clang-format
31+
args: [--style=file, --version=10]

examples/cpp/asynchronous_api/main.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,20 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515
*/
16-
16+
#include <adapters/openvino_adapter.h>
17+
#include <models/detection_model.h>
18+
#include <models/results.h>
1719
#include <stddef.h>
1820

1921
#include <cstdint>
2022
#include <exception>
2123
#include <iomanip>
2224
#include <iostream>
23-
#include <stdexcept>
24-
#include <string>
25-
2625
#include <opencv2/core.hpp>
2726
#include <opencv2/imgproc.hpp>
2827
#include <openvino/openvino.hpp>
29-
30-
#include <adapters/openvino_adapter.h>
31-
#include <models/detection_model.h>
32-
#include <models/results.h>
33-
28+
#include <stdexcept>
29+
#include <string>
3430

3531
int main(int argc, char* argv[]) try {
3632
if (argc != 3) {
@@ -43,43 +39,47 @@ int main(int argc, char* argv[]) try {
4339
}
4440

4541
// Instantiate Object Detection model
46-
auto model = DetectionModel::create_model(argv[1], {}, "", false); // works with SSD models. Download it using Python Model API
47-
//Define number of parallel infer requests. Is this number is set to 0, OpenVINO will determine it automatically to obtain optimal performance.
42+
auto model = DetectionModel::create_model(argv[1],
43+
{},
44+
"",
45+
false); // works with SSD models. Download it using Python Model API
46+
// Define number of parallel infer requests. Is this number is set to 0, OpenVINO will determine it automatically to
47+
// obtain optimal performance.
4848
size_t num_requests = 0;
4949
static ov::Core core;
5050
model->load(core, "CPU", num_requests);
5151

5252
std::cout << "Async inference will be carried out by " << model->getNumAsyncExecutors() << " parallel executors\n";
53-
//Prepare batch data
53+
// Prepare batch data
5454
std::vector<ImageInputData> data;
5555
for (size_t i = 0; i < 3; i++) {
5656
data.push_back(ImageInputData(image));
5757
}
5858

59-
//Batch inference is done by processing batch with num_requests parallel infer requests
59+
// Batch inference is done by processing batch with num_requests parallel infer requests
6060
std::cout << "Starting batch inference\n";
6161
auto results = model->inferBatch(data);
6262

6363
std::cout << "Batch mode inference results:\n";
6464
for (const auto& result : results) {
6565
for (auto& obj : result->objects) {
66-
std::cout << " " << std::left << std::setw(9) << obj.confidence << " " << obj.label << "\n";
66+
std::cout << " " << std::left << std::setw(9) << obj.confidence << " " << obj.label << "\n";
6767
}
6868
std::cout << std::string(10, '-') << "\n";
6969
}
7070
std::cout << "Batch mode inference done\n";
7171
std::cout << "Async mode inference results:\n";
7272

73-
//Set callback to grab results once the inference is done
74-
model->setCallback([](std::unique_ptr<ResultBase> result, const ov::AnyMap& callback_args){
73+
// Set callback to grab results once the inference is done
74+
model->setCallback([](std::unique_ptr<ResultBase> result, const ov::AnyMap& callback_args) {
7575
auto det_result = std::unique_ptr<DetectionResult>(static_cast<DetectionResult*>(result.release()));
7676

77-
//callback_args can contain arbitrary data
77+
// callback_args can contain arbitrary data
7878
size_t id = callback_args.find("id")->second.as<size_t>();
7979

8080
std::cout << "Request with id " << id << " is finished\n";
8181
for (auto& obj : det_result->objects) {
82-
std::cout << " " << std::left << std::setw(9) << obj.confidence << " " << obj.label << "\n";
82+
std::cout << " " << std::left << std::setw(9) << obj.confidence << " " << obj.label << "\n";
8383
}
8484
std::cout << std::string(10, '-') << "\n";
8585
});
@@ -88,7 +88,6 @@ int main(int argc, char* argv[]) try {
8888
model->inferAsync(image, {{"id", i}});
8989
}
9090
model->awaitAll();
91-
9291
} catch (const std::exception& error) {
9392
std::cerr << error.what() << '\n';
9493
return 1;

examples/cpp/synchronous_api/main.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@
1414
// limitations under the License.
1515
*/
1616

17+
#include <models/detection_model.h>
18+
#include <models/input_data.h>
19+
#include <models/results.h>
1720
#include <stddef.h>
1821

1922
#include <cstdint>
2023
#include <exception>
2124
#include <iomanip>
2225
#include <iostream>
23-
#include <stdexcept>
24-
#include <string>
25-
2626
#include <opencv2/core.hpp>
2727
#include <opencv2/highgui.hpp>
2828
#include <opencv2/imgproc.hpp>
2929
#include <openvino/openvino.hpp>
30-
31-
#include <models/detection_model.h>
32-
#include <models/input_data.h>
33-
#include <models/results.h>
30+
#include <stdexcept>
31+
#include <string>
3432

3533
int main(int argc, char* argv[]) try {
3634
if (argc != 3) {
@@ -43,16 +41,16 @@ int main(int argc, char* argv[]) try {
4341
}
4442

4543
// Instantiate Object Detection model
46-
auto model = DetectionModel::create_model(argv[1]); // works with SSD models. Download it using Python Model API
44+
auto model = DetectionModel::create_model(argv[1]); // works with SSD models. Download it using Python Model API
4745

4846
// Run the inference
4947
auto result = model->infer(image);
5048

5149
// Process detections
5250
for (auto& obj : result->objects) {
53-
std::cout << " " << std::left << std::setw(9) << obj.label << " | " << std::setw(10) << obj.confidence
54-
<< " | " << std::setw(4) << int(obj.x) << " | " << std::setw(4) << int(obj.y) << " | "
55-
<< std::setw(4) << int(obj.x + obj.width) << " | " << std::setw(4) << int(obj.y + obj.height) << "\n";
51+
std::cout << " " << std::left << std::setw(9) << obj.label << " | " << std::setw(10) << obj.confidence << " | "
52+
<< std::setw(4) << int(obj.x) << " | " << std::setw(4) << int(obj.y) << " | " << std::setw(4)
53+
<< int(obj.x + obj.width) << " | " << std::setw(4) << int(obj.y + obj.height) << "\n";
5654
}
5755
} catch (const std::exception& error) {
5856
std::cerr << error.what() << '\n';

model_api/cpp/adapters/include/adapters/inference_adapter.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
*/
1616

1717
#pragma once
18-
#include <string>
1918
#include <functional>
20-
#include <vector>
2119
#include <map>
2220
#include <memory>
23-
2421
#include <openvino/openvino.hpp>
22+
#include <string>
23+
#include <vector>
2524

2625
struct InputData;
2726
struct InferenceResult;
@@ -31,9 +30,7 @@ using InferenceInput = std::map<std::string, ov::Tensor>;
3130
using CallbackData = std::shared_ptr<ov::AnyMap>;
3231

3332
// The interface doesn't have implementation
34-
class InferenceAdapter
35-
{
36-
33+
class InferenceAdapter {
3734
public:
3835
virtual ~InferenceAdapter() = default;
3936

@@ -44,8 +41,10 @@ class InferenceAdapter
4441
virtual void awaitAll() = 0;
4542
virtual void awaitAny() = 0;
4643
virtual size_t getNumAsyncExecutors() const = 0;
47-
virtual void loadModel(const std::shared_ptr<const ov::Model>& model, ov::Core& core,
48-
const std::string& device = "", const ov::AnyMap& compilationConfig = {},
44+
virtual void loadModel(const std::shared_ptr<const ov::Model>& model,
45+
ov::Core& core,
46+
const std::string& device = "",
47+
const ov::AnyMap& compilationConfig = {},
4948
size_t max_num_requests = 0) = 0;
5049
virtual ov::PartialShape getInputShape(const std::string& inputName) const = 0;
5150
virtual std::vector<std::string> getInputNames() const = 0;

model_api/cpp/adapters/include/adapters/openvino_adapter.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515
*/
1616

1717
#pragma once
18-
#include <string>
1918
#include <functional>
20-
#include <vector>
2119
#include <map>
22-
#include <queue>
2320
#include <memory>
21+
#include <queue>
22+
#include <string>
23+
#include <vector>
2424

2525
#include "adapters/inference_adapter.h"
2626
#include "utils/async_infer_queue.hpp"
2727

28-
class OpenVINOInferenceAdapter :public InferenceAdapter
29-
{
30-
28+
class OpenVINOInferenceAdapter : public InferenceAdapter {
3129
public:
3230
OpenVINOInferenceAdapter() = default;
3331

@@ -37,9 +35,11 @@ class OpenVINOInferenceAdapter :public InferenceAdapter
3735
virtual bool isReady();
3836
virtual void awaitAll();
3937
virtual void awaitAny();
40-
virtual void loadModel(const std::shared_ptr<const ov::Model>& model, ov::Core& core,
41-
const std::string& device = "", const ov::AnyMap& compilationConfig = {},
42-
size_t max_num_requests = 1) override;
38+
virtual void loadModel(const std::shared_ptr<const ov::Model>& model,
39+
ov::Core& core,
40+
const std::string& device = "",
41+
const ov::AnyMap& compilationConfig = {},
42+
size_t max_num_requests = 1) override;
4343
virtual size_t getNumAsyncExecutors() const;
4444
virtual ov::PartialShape getInputShape(const std::string& inputName) const override;
4545
virtual std::vector<std::string> getInputNames() const override;
@@ -50,10 +50,10 @@ class OpenVINOInferenceAdapter :public InferenceAdapter
5050
void initInputsOutputs();
5151

5252
protected:
53-
//Depends on the implementation details but we should share the model state in this class
53+
// Depends on the implementation details but we should share the model state in this class
5454
std::vector<std::string> inputNames;
5555
std::vector<std::string> outputNames;
5656
ov::CompiledModel compiledModel;
5757
std::unique_ptr<AsyncInferQueue> asyncQueue;
58-
ov::AnyMap modelConfig; // the content of model_info section of rt_info
58+
ov::AnyMap modelConfig; // the content of model_info section of rt_info
5959
};

model_api/cpp/adapters/src/openvino_adapter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
*/
1616

1717
#include "adapters/openvino_adapter.h"
18+
1819
#include <openvino/openvino.hpp>
19-
#include <utils/slog.hpp>
2020
#include <stdexcept>
21+
#include <utils/slog.hpp>
2122
#include <vector>
2223

23-
void OpenVINOInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>& model, ov::Core& core,
24-
const std::string& device, const ov::AnyMap& compilationConfig, size_t max_num_requests) {
24+
void OpenVINOInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>& model,
25+
ov::Core& core,
26+
const std::string& device,
27+
const ov::AnyMap& compilationConfig,
28+
size_t max_num_requests) {
2529
slog::info << "Loading model to the plugin" << slog::endl;
2630
ov::AnyMap customCompilationConfig(compilationConfig);
2731
if (max_num_requests != 1) {
@@ -33,8 +37,7 @@ void OpenVINOInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>&
3337
customCompilationConfig["PERFORMANCE_HINT_NUM_REQUESTS"] = ov::hint::num_requests(max_num_requests);
3438
}
3539
}
36-
}
37-
else {
40+
} else {
3841
if (customCompilationConfig.find("PERFORMANCE_HINT") == customCompilationConfig.end()) {
3942
customCompilationConfig["PERFORMANCE_HINT"] = ov::hint::PerformanceMode::LATENCY;
4043
}

0 commit comments

Comments
 (0)