diff --git a/.github/workflows/cpp_gapi-demos.yml b/.github/workflows/cpp_gapi-demos.yml index 3a8f564cad6..4faa2bf2b43 100644 --- a/.github/workflows/cpp_gapi-demos.yml +++ b/.github/workflows/cpp_gapi-demos.yml @@ -28,23 +28,25 @@ jobs: path: ${{ github.workspace }}/cache key: unused restore-keys: ubuntu20_2023.2.0.13089.cfd42bd2cb0- - - if: ${{ !steps.cache.outputs.cache-hit }} - uses: actions/checkout@v3 - with: - repository: opencv/opencv - path: cache/opencv - - if: ${{ !steps.cache.outputs.cache-hit }} - name: Compile OpenCV + - name: Clone and checkout OpenCV + run: | + cd cache + mkdir opencv-with-fix + cd opencv-with-fix + git clone https://github.com/DariaMityagina/opencv.git + cd opencv + git checkout icv/dm/govbackend-partial-shape-support + - name: Compile OpenCV run: | - rm -rf cache/opencv/.git/ # Minimize cache - mkdir cache/opencv/build - cd cache/opencv/build + cd cache + mkdir opencv-with-fix/opencv/build + cd opencv-with-fix/opencv/build cmake -DCMAKE_BUILD_TYPE=Release -DWITH_INF_ENGINE=y -DOpenVINO_DIR=$GITHUB_WORKSPACE/ov/runtime/cmake/ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_LINKER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_C_LINKER_LAUNCHER=ccache -DBUILD_TESTS=y -DVIDEOIO_ENABLE_PLUGINS=y -DBUILD_PERF_TESTS=n -DBUILD_EXAMPLES=n -DBUILD_opencv_apps=y -DWITH_OPENCL=n -DWITH_OPENCLAMDBLAS=n -DWITH_GSTREAMER=n -DWITH_V4L=ON -DWITH_LIBV4L=ON -DWITH_OPENCLAMDFFT=n -DWITH_VA=n -DWITH_VA_INTEL=n -DWITH_PROTOBUF=n -DBUILD_PROTOBUF=n -DBUILD_JAVA=n -DBUILD_opencv_java_bindings_generator=n -DBUILD_opencv_python2=n -DBUILD_opencv_python3=n -DWITH_IMGCODEC_HDR=y -DWITH_IMGCODEC_SUNRASTER=y -DWITH_IMGCODEC_PXM=y -DWITH_IMGCODEC_PFM=y -DWITH_PNG=y -DWITH_TIFF=n -DWITH_WEBP=n -DWITH_OPENJPEG=n -DWITH_JASPER=n -DWITH_OPENEXR=n -DBUILD_opencv_dnn=n -DBUILD_opencv_features2d=n -DBUILD_opencv_flann=n -DWITH_TBB=n -DBUILD_INFO_SKIP_EXTRA_MODULES=n -DBUILD_JASPER=n -DBUILD_PNG=n -DBUILD_OPENEXR=n -DBUILD_WEBP=n -DBUILD_ZLIB=n -DWITH_CUDA=n -DWITH_EIGEN=n -DWITH_GPHOTO2=n -DOPENCV_GAPI_GSTREAMER=n -DWITH_LAPACK=n -DWITH_MATLAB=n -DWITH_MFX=n -DWITH_QUIRC=n -DWITH_VTK=n -DINSTALL_PDB=n -DINSTALL_TESTS=n -DINSTALL_C_EXAMPLES=n -DINSTALL_PYTHON_EXAMPLES=n -DOPENCV_GENERATE_SETUPVARS=n -DWITH_1394=n -DWITH_FFMPEG=y -DWITH_GTK_2_X=y -DBUILD_JPEG=y -DWITH_IPP=y -DENABLE_CONFIG_VERIFICATION=y -DBUILD_LIST=core,gapi,highgui,imgcodecs,imgproc,videoio,video .. cmake --build . -j $((`nproc`*2+2)) - 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 # TODO: add CMAKE_CXX_FLAGS=-Werror after background_subtraction_demo/cpp_gapi is updated to ov2.0 + OpenCV_DIR=$GITHUB_WORKSPACE/cache/opencv-with-fix/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/demos/background_subtraction_demo/cpp_gapi/CMakeLists.txt b/demos/background_subtraction_demo/cpp_gapi/CMakeLists.txt index 5f12122c89d..dbba68ba05d 100644 --- a/demos/background_subtraction_demo/cpp_gapi/CMakeLists.txt +++ b/demos/background_subtraction_demo/cpp_gapi/CMakeLists.txt @@ -7,11 +7,6 @@ if (NOT TARGET utils_gapi) return() endif() -if(OpenVINO_VERSION_MAJOR VERSION_GREATER_EQUAL 2024) - message(WARNING "background_subtraction_demo_gapi skipped. G-API is not compatible with OpenVINO 2024.0.") - return() -endif() - file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) diff --git a/demos/background_subtraction_demo/cpp_gapi/include/custom_kernels.hpp b/demos/background_subtraction_demo/cpp_gapi/include/custom_kernels.hpp index 098f291b678..be3eac857b6 100644 --- a/demos/background_subtraction_demo/cpp_gapi/include/custom_kernels.hpp +++ b/demos/background_subtraction_demo/cpp_gapi/include/custom_kernels.hpp @@ -7,16 +7,12 @@ #include #include -#include -#include -#include -#include +#include + #include #include #include -namespace IE = InferenceEngine; - namespace custom { // clang-format off G_API_OP(GTensorToImg, , "custom.tensorToImg") { @@ -49,10 +45,10 @@ class NNBGReplacer { } protected: - IE::CNNNetwork m_cnn_network; + std::shared_ptr model; std::string m_tag; - IE::InputsDataMap m_inputs; - IE::OutputsDataMap m_outputs; + std::vector> m_inputs; + std::vector> m_outputs; }; class MaskRCNNBGReplacer : public NNBGReplacer { diff --git a/demos/background_subtraction_demo/cpp_gapi/main.cpp b/demos/background_subtraction_demo/cpp_gapi/main.cpp index d57a1d0f829..10a74676679 100644 --- a/demos/background_subtraction_demo/cpp_gapi/main.cpp +++ b/demos/background_subtraction_demo/cpp_gapi/main.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -147,13 +147,13 @@ int main(int argc, char* argv[]) { auto config = ConfigFactory::getUserConfig(FLAGS_d, FLAGS_nireq, FLAGS_nstreams, FLAGS_nthreads); // clang-format off const auto net = - cv::gapi::ie::Params{ + cv::gapi::ov::Params{ model->getName(), FLAGS_m, // path to topology IR fileNameNoExt(FLAGS_m) + ".bin", // path to weights FLAGS_d // device specifier }.cfgNumRequests(config.maxAsyncRequests) - .pluginConfig(config.getLegacyConfig()); + .cfgPluginConfig(config.getLegacyConfig()); // clang-format on slog::info << "The background matting model " << FLAGS_m << " is loaded to " << FLAGS_d << " device." @@ -241,6 +241,8 @@ int main(int argc, char* argv[]) { } else { presenter.handleKey(key); } + } else { + cv::imwrite("./background-substr-out.jpg", output); } } slog::info << "Metrics report:" << slog::endl; diff --git a/demos/background_subtraction_demo/cpp_gapi/src/custom_kernels.cpp b/demos/background_subtraction_demo/cpp_gapi/src/custom_kernels.cpp index 952c50828f2..25d8d6a8797 100644 --- a/demos/background_subtraction_demo/cpp_gapi/src/custom_kernels.cpp +++ b/demos/background_subtraction_demo/cpp_gapi/src/custom_kernels.cpp @@ -10,9 +10,6 @@ #include #include -#include -#include -#include #include #include #include @@ -137,16 +134,16 @@ GAPI_OCV_KERNEL(OCVCalculateMaskRCNNBGMask, custom::GCalculateMaskRCNNBGMask) { // clang-format on custom::NNBGReplacer::NNBGReplacer(const std::string& model_path) { - IE::Core core; - m_cnn_network = core.ReadNetwork(model_path); - m_tag = m_cnn_network.getName(); - m_inputs = m_cnn_network.getInputsInfo(); - m_outputs = m_cnn_network.getOutputsInfo(); + ov::Core core; + model = core.read_model(model_path); + m_tag = model->get_name(); + m_inputs = model->inputs(); + m_outputs = model->outputs(); } custom::MaskRCNNBGReplacer::MaskRCNNBGReplacer(const std::string& model_path) : custom::NNBGReplacer(model_path) { for (const auto& p : m_outputs) { - const auto& layer_name = p.first; + const auto& layer_name = p.get_any_name(); if (layer_name.rfind("TopK") != std::string::npos) { continue; } @@ -154,9 +151,9 @@ custom::MaskRCNNBGReplacer::MaskRCNNBGReplacer(const std::string& model_path) : if (m_inputs.size() != 1) { throw std::logic_error("Supported only single input MaskRCNN models!"); } - m_input_name = m_inputs.begin()->first; + m_input_name = m_inputs[0].get_any_name(); - const auto dims_size = p.second->getTensorDesc().getDims().size(); + const auto dims_size = p.get_partial_shape().size(); if (dims_size == 1) { m_labels_name = layer_name; } else if (dims_size == 2) { @@ -177,7 +174,7 @@ cv::GMat custom::MaskRCNNBGReplacer::replace(cv::GFrame in, cv::GMat bgr, const auto boxes = outputs.at(m_boxes_name); auto masks = outputs.at(m_masks_name); - const auto& dims = m_inputs.at(m_input_name)->getTensorDesc().getDims(); + const auto& dims = model->input(m_input_name).get_partial_shape().get_max_shape(); GAPI_Assert(dims.size() == 4u); auto mask = custom::GCalculateMaskRCNNBGMask::on(in_size, cv::Size(dims[3], dims[2]), labels, boxes, masks); auto mask3ch = cv::gapi::medianBlur(cv::gapi::merge3(mask, mask, mask), 11); @@ -188,12 +185,12 @@ custom::BGMattingReplacer::BGMattingReplacer(const std::string& model_path) : NN if (m_inputs.size() != 1) { throw std::logic_error("Supported only single input background matting models!"); } - m_input_name = m_inputs.begin()->first; + m_input_name = m_inputs[0].get_any_name(); if (m_outputs.size() != 1) { throw std::logic_error("Supported only single output background matting models!"); } - m_output_name = m_outputs.begin()->first; + m_output_name = m_outputs[0].get_any_name(); } cv::GMat custom::BGMattingReplacer::replace(cv::GFrame in, cv::GMat bgr, const cv::Size& in_size, cv::GMat background) { diff --git a/demos/tests/cases.py b/demos/tests/cases.py index 16b4ae6090a..fe1e7e62273 100644 --- a/demos/tests/cases.py +++ b/demos/tests/cases.py @@ -170,15 +170,18 @@ def single_option_cases(key, *args): DEMOS = [ - # CppDemo(name='background_subtraction_demo', device_keys=['-d'], implementation='cpp_gapi', test_cases=combine_cases( - # TestCase(options={'--no_show': None, '-at': 'maskrcnn', - # **MONITORS, - # '-i': DataPatternArg('coco128-subset-480x640x3'), - # }), - # single_option_cases('-m', - # ModelArg('instance-segmentation-person-0007'), - # ModelArg('instance-segmentation-security-0091')), - # )), + CppDemo(name='background_subtraction_demo', device_keys=['-d'], implementation='cpp_gapi', test_cases=combine_cases( + TestCase(options={'--no_show': None, '-at': 'maskrcnn', + **MONITORS, + }), + single_option_cases('-m', + ModelArg('instance-segmentation-person-0007'), + ModelArg('instance-segmentation-security-0091')), + single_option_cases( + '-i', + DataPatternArg('coco128-every-480x640x3'), + str('video.mp4')), + )), CppDemo('classification_benchmark_demo', 'cpp_gapi', test_cases=combine_cases( single_option_cases( @@ -251,8 +254,8 @@ def single_option_cases(key, *args): ModelArg('face-detection-retail-0004')), single_option_cases( '-i', - str('video.mp4'), - DataPatternArg('coco128-every-480x640x3')), + DataPatternArg('coco128-every-480x640x3'), + str('video.mp4')), )), # TODO: https://github.com/DariaMityagina is to fix the demo