Skip to content

Commit

Permalink
demos: fix warnings (#3847)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wovchena authored Sep 1, 2023
1 parent f08b9b0 commit 78201d4
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cpp_gapi-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ci/dependencies.yml
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include <string>
#include <vector>

#include <ie_allocator.hpp>
#include <ie_common.h>
#include <ie_input_info.hpp>
#include <opencv2/core.hpp>
#include <opencv2/gapi/gkernel.hpp>
#include <opencv2/gapi/gmat.hpp>
Expand Down
14 changes: 5 additions & 9 deletions demos/common/cpp/models/src/detection_model_yolov3_onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,11 @@ void ModelYoloV3ONNX::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
std::shared_ptr<InternalModelData> ModelYoloV3ONNX::preprocess(const InputData& inputData,
ov::InferRequest& request) {
const auto& origImg = inputData.asRef<ImageInputData>().inputImage;

cv::Mat info(cv::Size(1, 2), CV_32SC1);
info.at<int>(0, 0) = origImg.rows;
info.at<int>(0, 1) = origImg.cols;
auto allocator = std::make_shared<SharedTensorAllocator>(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<int32_t>();
data[0] = origImg.rows;
data[1] = origImg.cols;
request.set_tensor(inputsNames[1], info);
return ImageModel::preprocess(inputData, request);
}

Expand Down
3 changes: 1 addition & 2 deletions demos/common/cpp/utils/include/utils/ocv_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SharedTensorAllocator>(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) {
Expand Down
31 changes: 5 additions & 26 deletions demos/common/cpp/utils/include/utils/shared_tensor_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,10 @@
#pragma once

#include <opencv2/core.hpp>
#include <openvino/runtime/allocator.hpp>

// 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<const SharedTensorAllocator*>(&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;}
};
17 changes: 5 additions & 12 deletions demos/gaze_estimation_demo/cpp_gapi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
#include <utility>
#include <vector>

#include <cpp/ie_cnn_network.h>
#include <gflags/gflags.h>
#include <ie_core.hpp>
#include <ie_input_info.hpp>
#include <ie_layouts.h>
#include <opencv2/core.hpp>
#include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/garg.hpp>
Expand Down Expand Up @@ -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<const ov::Node> 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<unsigned long>(layerDims[2] * imageAspectRatio);
face_net.cfgInputReshape(layerName, layerDims);
inShape[3] = static_cast<unsigned long>(inShape[2] * imageAspectRatio);
face_net.cfgInputReshape(input.get_any_name(), inShape);
}
}
auto head_net =
Expand Down
20 changes: 7 additions & 13 deletions demos/gesture_recognition_demo/cpp_gapi/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,17 @@
#include <stdexcept>
#include <utility>

#include <cpp/ie_cnn_network.h>
#include <ie_core.hpp>
#include <ie_input_info.hpp>
#include <ie_layouts.h>
#include <openvino/openvino.hpp>

#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<double>(layerDims[0 + step]),
static_cast<double>(layerDims[1 + step]),
static_cast<double>(layerDims[2 + step]),
static_cast<double>(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<double>(shape[0 + step]),
static_cast<double>(shape[1 + step]),
static_cast<double>(shape[2 + step]),
static_cast<double>(shape[3 + step]));
}

void erase(std::string& str, const char symbol) {
Expand Down
2 changes: 1 addition & 1 deletion demos/pedestrian_tracker_demo/cpp/include/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include <details/ie_exception.hpp>
#include <opencv2/core.hpp>

#define PT_CHECK(cond) CV_Assert(cond);

Expand Down
2 changes: 0 additions & 2 deletions demos/smart_classroom_demo/cpp_gapi/src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <memory>
#include <utility>

#include <ie_common.h>

#include "tracker.hpp"

namespace {
Expand Down
5 changes: 4 additions & 1 deletion demos/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions demos/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tempfile
import timeit
import importlib
import warnings

from pathlib import Path
from io import BytesIO
Expand Down Expand Up @@ -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',
Expand All @@ -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 []),
Expand Down Expand Up @@ -202,6 +203,7 @@ def get_models(case, keys):


def main():
warnings.filterwarnings("error")
args = build_argparser().parse_args()

DEMOS = scopes[args.scope]
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 78201d4

Please sign in to comment.