From 78201d4bec2d8ab3ec2a04d8a5b13f507a998d9c Mon Sep 17 00:00:00 2001 From: Zlobin Vladimir Date: Fri, 1 Sep 2023 11:07:23 +0400 Subject: [PATCH] demos: fix warnings (#3847) --- .github/workflows/cpp_gapi-demos.yml | 2 +- ci/dependencies.yml | 8 ++--- .../cpp_gapi/include/custom_kernels.hpp | 3 -- .../src/detection_model_yolov3_onnx.cpp | 14 +++------ .../cpp/utils/include/utils/ocv_common.hpp | 3 +- .../include/utils/shared_tensor_allocator.hpp | 31 +++---------------- demos/gaze_estimation_demo/cpp_gapi/main.cpp | 17 +++------- .../cpp_gapi/src/utils.cpp | 20 +++++------- .../cpp/include/logging.hpp | 2 +- .../cpp_gapi/src/logger.cpp | 2 -- demos/tests/cases.py | 5 ++- demos/tests/run_tests.py | 10 +++--- 12 files changed, 39 insertions(+), 78 deletions(-) diff --git a/.github/workflows/cpp_gapi-demos.yml b/.github/workflows/cpp_gapi-demos.yml index a4780c1cf15..30d5b7878ce 100644 --- a/.github/workflows/cpp_gapi-demos.yml +++ b/.github/workflows/cpp_gapi-demos.yml @@ -43,7 +43,7 @@ jobs: - name: build_demos.sh run: | source ov/setupvars.sh - OpenCV_DIR=$GITHUB_WORKSPACE/cache/opencv/build CMAKE_CXX_COMPILER_LAUNCHER=ccache CMAKE_CXX_LINKER_LAUNCHER=ccache ./demos/build_demos.sh --build_dir=build + OpenCV_DIR=$GITHUB_WORKSPACE/cache/opencv/build CMAKE_CXX_COMPILER_LAUNCHER=ccache CMAKE_CXX_LINKER_LAUNCHER=ccache ./demos/build_demos.sh --build_dir=build # TODO: add CMAKE_CXX_FLAGS=-Werror after background_subtraction_demo/cpp_gapi is updated to ov2.0 - uses: actions/setup-python@v4 with: python-version: 3.11 diff --git a/ci/dependencies.yml b/ci/dependencies.yml index 66fd64204fe..5353ad1d62f 100644 --- a/ci/dependencies.yml +++ b/ci/dependencies.yml @@ -1,4 +1,4 @@ -openvino_linux: 'l_openvino_toolkit_ubuntu20_2023.1.0.dev20230623_x86_64' -openvino_windows: 'w_openvino_toolkit_windows_2023.1.0.dev20230623_x86_64' -wheel_linux: '2023.0.0-10926' -wheel_windows: '2023.1.0.dev20230623' +openvino_linux: 'https://storage.openvinotoolkit.org/repositories/openvino/packages/master/2023.1.0.dev20230811/l_openvino_toolkit_ubuntu20_2023.1.0.dev20230811_x86_64.tgz' +openvino_windows: 'https://storage.openvinotoolkit.org/repositories/openvino/packages/master/2023.1.0.dev20230811/w_openvino_toolkit_windows_2023.1.0.dev20230811_x86_64.zip' +wheel_linux: '2023.1.0.dev20230811' +wheel_windows: '2023.1.0.dev20230811' diff --git a/demos/classification_benchmark_demo/cpp_gapi/include/custom_kernels.hpp b/demos/classification_benchmark_demo/cpp_gapi/include/custom_kernels.hpp index 83b7d8948ea..3df9000a374 100644 --- a/demos/classification_benchmark_demo/cpp_gapi/include/custom_kernels.hpp +++ b/demos/classification_benchmark_demo/cpp_gapi/include/custom_kernels.hpp @@ -9,9 +9,6 @@ #include #include -#include -#include -#include #include #include #include diff --git a/demos/common/cpp/models/src/detection_model_yolov3_onnx.cpp b/demos/common/cpp/models/src/detection_model_yolov3_onnx.cpp index 81ab6cb033a..ab8330a49ee 100644 --- a/demos/common/cpp/models/src/detection_model_yolov3_onnx.cpp +++ b/demos/common/cpp/models/src/detection_model_yolov3_onnx.cpp @@ -107,15 +107,11 @@ void ModelYoloV3ONNX::prepareInputsOutputs(std::shared_ptr& model) { std::shared_ptr ModelYoloV3ONNX::preprocess(const InputData& inputData, ov::InferRequest& request) { const auto& origImg = inputData.asRef().inputImage; - - cv::Mat info(cv::Size(1, 2), CV_32SC1); - info.at(0, 0) = origImg.rows; - info.at(0, 1) = origImg.cols; - auto allocator = std::make_shared(info); - ov::Tensor infoInput = ov::Tensor(ov::element::i32, ov::Shape({1, 2}), ov::Allocator(allocator)); - - request.set_tensor(inputsNames[1], infoInput); - + ov::Tensor info{ov::element::i32, ov::Shape({1, 2})}; + int32_t* data = info.data(); + data[0] = origImg.rows; + data[1] = origImg.cols; + request.set_tensor(inputsNames[1], info); return ImageModel::preprocess(inputData, request); } diff --git a/demos/common/cpp/utils/include/utils/ocv_common.hpp b/demos/common/cpp/utils/include/utils/ocv_common.hpp index c0ce1ceff31..93e116de9cd 100644 --- a/demos/common/cpp/utils/include/utils/ocv_common.hpp +++ b/demos/common/cpp/utils/include/utils/ocv_common.hpp @@ -96,8 +96,7 @@ static UNUSED ov::Tensor wrapMat2Tensor(const cv::Mat& mat) { throw std::runtime_error("Doesn't support conversion from not dense cv::Mat"); } auto precision = isMatFloat ? ov::element::f32 : ov::element::u8; - auto allocator = std::make_shared(mat); - return ov::Tensor(precision, ov::Shape{ 1, height, width, channels }, ov::Allocator(allocator)); + return ov::Tensor(precision, ov::Shape{ 1, height, width, channels }, SharedMatAllocator{mat}); } static inline void resize2tensor(const cv::Mat& mat, const ov::Tensor& tensor) { diff --git a/demos/common/cpp/utils/include/utils/shared_tensor_allocator.hpp b/demos/common/cpp/utils/include/utils/shared_tensor_allocator.hpp index 10f9c5fef1e..a12112f448f 100644 --- a/demos/common/cpp/utils/include/utils/shared_tensor_allocator.hpp +++ b/demos/common/cpp/utils/include/utils/shared_tensor_allocator.hpp @@ -17,31 +17,10 @@ #pragma once #include -#include -// To prevent false-positive clang compiler warning -// (https://github.com/openvinotoolkit/openvino/pull/11092#issuecomment-1073846256): -// warning: destructor called on non-final 'SharedTensorAllocator' that has virtual functions -// but non-virtual destructor [-Wdelete-non-abstract-non-virtual-dtor] -// SharedTensorAllocator class declared as final - -class SharedTensorAllocator final : public ov::AllocatorImpl { -public: - SharedTensorAllocator(const cv::Mat& img) : img(img) {} - - ~SharedTensorAllocator() = default; - - void* allocate(const size_t bytes, const size_t) override { - return bytes <= img.rows * img.step[0] ? img.data : nullptr; - } - - void deallocate(void* handle, const size_t bytes, const size_t) override {} - - bool is_equal(const AllocatorImpl& other) const override { - auto other_tensor_allocator = dynamic_cast(&other); - return other_tensor_allocator != nullptr && other_tensor_allocator == this; - } - -private: - const cv::Mat img; +struct SharedMatAllocator { + const cv::Mat mat; + void* allocate(size_t bytes, size_t) {return bytes <= mat.rows * mat.step[0] ? mat.data : nullptr;} + void deallocate(void*, size_t, size_t) {} + bool is_equal(const SharedMatAllocator& other) const noexcept {return this == &other;} }; diff --git a/demos/gaze_estimation_demo/cpp_gapi/main.cpp b/demos/gaze_estimation_demo/cpp_gapi/main.cpp index a81ddcc6ba5..f40cf6b669a 100644 --- a/demos/gaze_estimation_demo/cpp_gapi/main.cpp +++ b/demos/gaze_estimation_demo/cpp_gapi/main.cpp @@ -18,11 +18,7 @@ #include #include -#include #include -#include -#include -#include #include #include #include @@ -205,19 +201,16 @@ int main(int argc, char* argv[]) { stringToSize(FLAGS_res)); if (FLAGS_fd_reshape) { - InferenceEngine::Core core; - const auto network = core.ReadNetwork(FLAGS_m_fd); - const auto layerName = network.getInputsInfo().begin()->first; - const auto layerData = network.getInputsInfo().begin()->second; - auto layerDims = layerData->getTensorDesc().getDims(); + ov::Output input = ov::Core{}.read_model(FLAGS_m_fd)->input(); + ov::Shape inShape = input.get_shape(); const double imageAspectRatio = std::round(100. * frame_size.width / frame_size.height) / 100.; - const double networkAspectRatio = std::round(100. * layerDims[3] / layerDims[2]) / 100.; + const double networkAspectRatio = std::round(100. * inShape[3] / inShape[2]) / 100.; const double aspectRatioThreshold = 0.01; if (std::fabs(imageAspectRatio - networkAspectRatio) > aspectRatioThreshold) { - layerDims[3] = static_cast(layerDims[2] * imageAspectRatio); - face_net.cfgInputReshape(layerName, layerDims); + inShape[3] = static_cast(inShape[2] * imageAspectRatio); + face_net.cfgInputReshape(input.get_any_name(), inShape); } } auto head_net = diff --git a/demos/gesture_recognition_demo/cpp_gapi/src/utils.cpp b/demos/gesture_recognition_demo/cpp_gapi/src/utils.cpp index 40f22dbdd7b..9cf905a5b5e 100644 --- a/demos/gesture_recognition_demo/cpp_gapi/src/utils.cpp +++ b/demos/gesture_recognition_demo/cpp_gapi/src/utils.cpp @@ -11,23 +11,17 @@ #include #include -#include -#include -#include -#include +#include #define _USE_MATH_DEFINES cv::Scalar getNetShape(const std::string& path) { - const auto network = InferenceEngine::Core{}.ReadNetwork(path); - const auto layerData = network.getInputsInfo().begin()->second; - const auto layerDims = layerData->getTensorDesc().getDims(); - - const int step = layerDims.size() == 5 ? 1 : 0; - return cv::Scalar(static_cast(layerDims[0 + step]), - static_cast(layerDims[1 + step]), - static_cast(layerDims[2 + step]), - static_cast(layerDims[3 + step])); + ov::Shape shape = ov::Core{}.read_model(path)->input().get_shape(); + const int step = shape.size() == 5 ? 1 : 0; + return cv::Scalar(static_cast(shape[0 + step]), + static_cast(shape[1 + step]), + static_cast(shape[2 + step]), + static_cast(shape[3 + step])); } void erase(std::string& str, const char symbol) { diff --git a/demos/pedestrian_tracker_demo/cpp/include/logging.hpp b/demos/pedestrian_tracker_demo/cpp/include/logging.hpp index a2e54d8a390..5f9a3d6a592 100644 --- a/demos/pedestrian_tracker_demo/cpp/include/logging.hpp +++ b/demos/pedestrian_tracker_demo/cpp/include/logging.hpp @@ -4,7 +4,7 @@ #pragma once -#include
+#include #define PT_CHECK(cond) CV_Assert(cond); diff --git a/demos/smart_classroom_demo/cpp_gapi/src/logger.cpp b/demos/smart_classroom_demo/cpp_gapi/src/logger.cpp index 0fc67b474e8..9c5ac28a2fa 100644 --- a/demos/smart_classroom_demo/cpp_gapi/src/logger.cpp +++ b/demos/smart_classroom_demo/cpp_gapi/src/logger.cpp @@ -9,8 +9,6 @@ #include #include -#include - #include "tracker.hpp" namespace { diff --git a/demos/tests/cases.py b/demos/tests/cases.py index fc87cdfcb0d..558c2763574 100644 --- a/demos/tests/cases.py +++ b/demos/tests/cases.py @@ -145,7 +145,10 @@ def __init__(self, name, model_keys=('-m',), device_keys=('-d',), test_cases=Non self._exec_name = self._exec_name.replace('_python', '') def fixed_args(self, source_dir, build_dir): - return [sys.executable, str(source_dir / self.subdirectory / (self._exec_name + '.py'))] + if self._exec_name in ('image_retrieval_demo', 'time_series_forecasting_demo', 'object_detection_demo'): + # sklearn has DeprecationWarning, RuntimeWarning: overflow encountered in exp for yolo-v4-tf + return [sys.executable, str(source_dir / self.subdirectory / (self._exec_name + '.py'))] + return [sys.executable, '-W', 'error', str(source_dir / self.subdirectory / (self._exec_name + '.py'))] def join_cases(*args): diff --git a/demos/tests/run_tests.py b/demos/tests/run_tests.py index 57982189aaa..73c00d1c4ce 100755 --- a/demos/tests/run_tests.py +++ b/demos/tests/run_tests.py @@ -40,6 +40,7 @@ import tempfile import timeit import importlib +import warnings from pathlib import Path from io import BytesIO @@ -135,7 +136,7 @@ def prepare_models(auto_tools_dir, downloader_cache_dir, mo_path, global_temp_di try: subprocess.check_output( [ - sys.executable, '--', str(auto_tools_dir / 'downloader.py'), + sys.executable, '-W', 'error', '--', str(auto_tools_dir / 'downloader.py'), '--output_dir', str(dl_dir), '--cache_dir', str(downloader_cache_dir), '--list', str(complete_models_lst_path), '--precisions', ','.join(model_precisions), '--jobs', '9', @@ -152,7 +153,7 @@ def prepare_models(auto_tools_dir, downloader_cache_dir, mo_path, global_temp_di try: subprocess.check_output( [ - sys.executable, '--', str(auto_tools_dir / 'converter.py'), + sys.executable, '-W', 'error', '--', str(auto_tools_dir / 'converter.py'), '--download_dir', str(dl_dir), '--list', str(complete_models_lst_path), '--precisions', ','.join(model_precisions), '--jobs', 'auto', *(['--mo', str(mo_path)] if mo_path else []), @@ -202,6 +203,7 @@ def get_models(case, keys): def main(): + warnings.filterwarnings("error") args = build_argparser().parse_args() DEMOS = scopes[args.scope] @@ -212,7 +214,7 @@ def main(): auto_tools_dir = omz_dir / 'tools/model_tools' model_info_list = json.loads(subprocess.check_output( - [sys.executable, '--', str(auto_tools_dir / 'info_dumper.py'), '--all'], + [sys.executable, '-W', 'error', '--', str(auto_tools_dir / 'info_dumper.py'), '--all'], universal_newlines=True)) model_info = {} @@ -276,7 +278,7 @@ def main(): declared_model_names = set() for model_data in json.loads(subprocess.check_output( - [sys.executable, '--', str(auto_tools_dir / 'info_dumper.py'), + [sys.executable, '-W', 'error', '--', str(auto_tools_dir / 'info_dumper.py'), '--list', str(demo.models_lst_path(demos_dir))], universal_newlines=True)): models_list = model_data['model_stages'] if model_data['model_stages'] else [model_data]