Skip to content

Commit

Permalink
Port G-API demos to API2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaMityagina committed Jan 5, 2024
1 parent f1f7361 commit cd6ba9a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cpp_gapi-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ jobs:
- if: ${{ !steps.cache.outputs.cache-hit }}
name: Compile OpenCV
run: |
sudo apt install pkg-config
sudo apt install ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev
rm -rf cache/opencv/.git/ # Minimize cache
mkdir cache/opencv/build
cd cache/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=n -DBUILD_PERF_TESTS=n -DBUILD_EXAMPLES=n -DBUILD_opencv_apps=n -DWITH_OPENCL=n -DWITH_OPENCLAMDBLAS=n -DWITH_OPENCLAMDFFT=n -DWITH_VA=n -DWITH_VA_INTEL=n -DWITH_V4L=n -DWITH_GSTREAMER=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=n -DWITH_IMGCODEC_SUNRASTER=n -DWITH_IMGCODEC_PXM=n -DWITH_IMGCODEC_PFM=n -DWITH_PNG=n -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=n -DWITH_GTK_2_X=y -DBUILD_JPEG=y -DWITH_IPP=y -DENABLE_CONFIG_VERIFICATION=y -DBUILD_LIST=core,gapi,highgui,imgcodecs,imgproc,videoio ..
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: |
Expand Down
5 changes: 3 additions & 2 deletions demos/background_subtraction_demo/cpp_gapi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <opencv2/gapi/imgproc.hpp>
#include <opencv2/gapi/infer.hpp>
#include <opencv2/gapi/infer/ie.hpp>
#include <opencv2/gapi/infer/ov.hpp>
#include <opencv2/gapi/own/assert.hpp>
#include <opencv2/gapi/streaming/source.hpp>
#include <opencv2/gapi/util/optional.hpp>
Expand Down Expand Up @@ -147,13 +148,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::Generic>{
cv::gapi::ov::Params<cv::gapi::Generic>{
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."
Expand Down
13 changes: 7 additions & 6 deletions demos/gaze_estimation_demo/cpp_gapi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <opencv2/gapi/gstreaming.hpp>
#include <opencv2/gapi/infer.hpp>
#include <opencv2/gapi/infer/ie.hpp>
#include <opencv2/gapi/infer/ov.hpp>
#include <opencv2/gapi/streaming/format.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
Expand Down Expand Up @@ -175,7 +176,7 @@ int main(int argc, char* argv[]) {
processed_gaze_vectors));
/** ---------------- End of graph ---------------- **/
/** Configure networks **/
auto face_net = cv::gapi::ie::Params<nets::Faces>{
auto face_net = cv::gapi::ov::Params<nets::Faces>{
FLAGS_m_fd, // path to topology IR
fileNameNoExt(FLAGS_m_fd) + ".bin", // path to weights
FLAGS_d_fd, // device specifier
Expand Down Expand Up @@ -210,11 +211,11 @@ int main(int argc, char* argv[]) {

if (std::fabs(imageAspectRatio - networkAspectRatio) > aspectRatioThreshold) {
inShape[3] = static_cast<unsigned long>(inShape[2] * imageAspectRatio);
face_net.cfgInputReshape(input.get_any_name(), inShape);
face_net.cfgReshape(inShape);
}
}
auto head_net =
cv::gapi::ie::Params<nets::HeadPose>{
cv::gapi::ov::Params<nets::HeadPose>{
FLAGS_m_hp, // path to topology IR
fileNameNoExt(FLAGS_m_hp) + ".bin", // path to weights
FLAGS_d_hp, // device specifier
Expand All @@ -223,7 +224,7 @@ int main(int argc, char* argv[]) {
slog::info << "The Head Pose Estimation model " << FLAGS_m_hp << " is loaded to " << FLAGS_d_hp << " device."
<< slog::endl;

auto landmarks_net = cv::gapi::ie::Params<nets::Landmarks>{
auto landmarks_net = cv::gapi::ov::Params<nets::Landmarks>{
FLAGS_m_lm, // path to topology IR
fileNameNoExt(FLAGS_m_lm) + ".bin", // path to weights
FLAGS_d_lm, // device specifier
Expand All @@ -233,7 +234,7 @@ int main(int argc, char* argv[]) {

// clang-format off
auto gaze_net =
cv::gapi::ie::Params<nets::Gaze>{
cv::gapi::ov::Params<nets::Gaze>{
FLAGS_m, // path to topology IR
fileNameNoExt(FLAGS_m) + ".bin", // path to weights
FLAGS_d, // device specifier
Expand All @@ -242,7 +243,7 @@ int main(int argc, char* argv[]) {
slog::info << "The Gaze Estimation model " << FLAGS_m << " is loaded to " << FLAGS_d << " device."
<< slog::endl;

auto eyes_net = cv::gapi::ie::Params<nets::Eyes>{
auto eyes_net = cv::gapi::ov::Params<nets::Eyes>{
FLAGS_m_es, // path to topology IR
fileNameNoExt(FLAGS_m_es) + ".bin", // path to weights
FLAGS_d_es, // device specifier
Expand Down
5 changes: 3 additions & 2 deletions demos/gesture_recognition_demo/cpp_gapi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <opencv2/gapi/gstreaming.hpp>
#include <opencv2/gapi/infer.hpp>
#include <opencv2/gapi/infer/ie.hpp>
#include <opencv2/gapi/infer/ov.hpp>
#include <opencv2/gapi/streaming/source.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
Expand Down Expand Up @@ -135,7 +136,7 @@ int main(int argc, char* argv[]) {
/** Configure networks **/
// clang-format off
auto person_detection =
cv::gapi::ie::Params<nets::PersonDetection>{
cv::gapi::ov::Params<nets::PersonDetection>{
FLAGS_m_d, // path to model
fileNameNoExt(FLAGS_m_d) + ".bin", // path to weights
FLAGS_d_d // device to use
Expand All @@ -148,7 +149,7 @@ int main(int argc, char* argv[]) {

// clang-format off
auto action_recognition =
cv::gapi::ie::Params<nets::ActionRecognition>{
cv::gapi::ov::Params<nets::ActionRecognition>{
FLAGS_m_a, // path to model
fileNameNoExt(FLAGS_m_a) + ".bin", // path to weights
FLAGS_d_a // device to use
Expand Down
55 changes: 29 additions & 26 deletions demos/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ 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,
'-i': DataPatternArg('coco128-subset-480x640x3'),
}),
single_option_cases('-m',
ModelArg('instance-segmentation-person-0007'),
ModelArg('instance-segmentation-security-0091')),
)),

CppDemo('classification_benchmark_demo', 'cpp_gapi', test_cases=combine_cases(
single_option_cases(
Expand Down Expand Up @@ -254,8 +254,7 @@ def single_option_cases(key, *args):
device_keys=['-d', '-d_fd', '-d_hp', '-d_lm', '-d_es'],
test_cases=combine_cases(
TestCase(options={'-no_show': None,
**MONITORS,
'-i': TestDataArg('coco128/images/train2017/')}),
**MONITORS}),
TestCase(options={
'-m': ModelArg('gaze-estimation-adas-0002'),
'-m_hp': ModelArg('head-pose-estimation-adas-0001'),
Expand All @@ -266,23 +265,27 @@ def single_option_cases(key, *args):
'-m_fd',
ModelArg('face-detection-adas-0001'),
ModelArg('face-detection-retail-0004')),
single_option_cases(
'-i',
str('/tmp/video.mp4'),
DataPatternArg('coco128-every-480x640x3')),
)),

CppDemo(name='gesture_recognition_demo', implementation='cpp_gapi',
model_keys=['-m_a', '-m_d'],
device_keys=['-d_a', '-d_d'],
test_cases=combine_cases(
TestCase(options={'--no_show': None,
'-i': DataPatternArg('coco128-every-480x640x3'),
'-m_d': ModelArg('person-detection-asl-0001')}),
[
TestCase(options={'-m_a': ModelArg('asl-recognition-0004'), '-c': str(OMZ_DIR / 'data/dataset_classes/msasl100.json')}),
TestCase(options={'-m_a': ModelArg('common-sign-language-0001'),
'-c': str(OMZ_DIR / 'data/dataset_classes/jester27.json')}),
TestCase(options={'-m_a': ModelArg('common-sign-language-0002'),
'-c': str(OMZ_DIR / 'data/dataset_classes/common_sign_language12.json')}),
],
)),
# CppDemo(name='gesture_recognition_demo', implementation='cpp_gapi',
# model_keys=['-m_a', '-m_d'],
# device_keys=['-d_a', '-d_d'],
# test_cases=combine_cases(
# TestCase(options={'--no_show': None,
# '-i': DataPatternArg('coco128-every-480x640x3'),
# '-m_d': ModelArg('person-detection-asl-0001')}),
# [
# TestCase(options={'-m_a': ModelArg('asl-recognition-0004'), '-c': str(OMZ_DIR / 'data/dataset_classes/msasl100.json')}),
# TestCase(options={'-m_a': ModelArg('common-sign-language-0001'),
# '-c': str(OMZ_DIR / 'data/dataset_classes/jester27.json')}),
# TestCase(options={'-m_a': ModelArg('common-sign-language-0002'),
# '-c': str(OMZ_DIR / 'data/dataset_classes/common_sign_language12.json')}),
# ],
# )),

CppDemo(
'interactive_face_detection_demo', 'cpp_gapi',
Expand Down
14 changes: 14 additions & 0 deletions demos/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@
from cases import Demo
from data_sequences import DATA_SEQUENCES

import shutil
import requests

scopes = {
'base': importlib.import_module('cases').DEMOS,
'performance': importlib.import_module('performance_cases').DEMOS,
}
COCO128_URL = "https://ultralytics.com/assets/coco128.zip"
VIDEO_URL = "https://storage.openvinotoolkit.org/data/test_data/videos/head-pose-face-detection-male.mp4"


def parser_paths_list(supported_devices):
Expand Down Expand Up @@ -247,6 +251,16 @@ def main():
with ZipFile(BytesIO(zipresp.read())) as zfile:
zfile.extractall(args.test_data_dir)

try:
r = requests.get(VIDEO_URL)
with open("video.mp4", 'wb') as f:
f.write(r.content)
print('Video for demos downloaded successfully')
shutil.copy("video.mp4", "/tmp/")
except requests.exceptions.HTTPError as err:
print(err)


with temp_dir_as_path() as global_temp_dir:
if args.models_dir:
dl_dir = args.models_dir
Expand Down

0 comments on commit cd6ba9a

Please sign in to comment.